material.glsl 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //
  2. // Material properties uniform
  3. //
  4. // Material parameters uniform array
  5. uniform vec3 Material[6];
  6. // Macros to access elements inside the Material array
  7. #define MatAmbientColor Material[0]
  8. #define MatDiffuseColor Material[1]
  9. #define MatSpecularColor Material[2]
  10. #define MatEmissiveColor Material[3]
  11. #define MatShininess Material[4].x
  12. #define MatOpacity Material[4].y
  13. #define MatPointSize Material[4].z
  14. #define MatPointRotationZ Material[5].x
  15. #if MAT_TEXTURES > 0
  16. // Texture unit sampler array
  17. uniform sampler2D MatTexture[MAT_TEXTURES];
  18. // Texture parameters (3*vec2 per texture)
  19. uniform vec2 MatTexinfo[3*MAT_TEXTURES];
  20. // Macros to access elements inside the MatTexinfo array
  21. #define MatTexOffset(a) MatTexinfo[(3*a)]
  22. #define MatTexRepeat(a) MatTexinfo[(3*a)+1]
  23. #define MatTexFlipY(a) bool(MatTexinfo[(3*a)+2].x)
  24. #define MatTexVisible(a) bool(MatTexinfo[(3*a)+2].y)
  25. #endif
  26. // GLSL 3.30 does not allow indexing texture sampler with non constant values.
  27. // This macro is used to mix the texture with the specified index with the material color.
  28. // It should be called for each texture index. It uses two externally defined variables:
  29. // vec4 texColor
  30. // vec4 texMixed
  31. #define MIX_TEXTURE(i) \
  32. if (MatTexVisible(i)) { \
  33. texColor = texture(MatTexture[i], FragTexcoord * MatTexRepeat(i) + MatTexOffset(i)); \
  34. if (i == 0) { \
  35. texMixed = texColor; \
  36. } else { \
  37. texMixed = mix(texMixed, texColor, texColor.a); \
  38. } \
  39. }