material.glsl 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. }
  40. // TODO for alpha blending dont use mix use implementation below (similar to one in panel shader)
  41. //vec4 prevTexPre = texMixed; \
  42. //prevTexPre.rgb *= prevTexPre.a; \
  43. //vec4 currTexPre = texColor; \
  44. //currTexPre.rgb *= currTexPre.a; \
  45. //texMixed = currTexPre + prevTexPre * (1 - currTexPre.a); \
  46. //texMixed.rgb /= texMixed.a; \