material.glsl 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. // GLSL 3.30 does not allow indexing texture sampler with non constant values.
  26. // This function is used to mix the texture with the specified index with the material color.
  27. // It should be called for each texture index. It uses two externally defined variables:
  28. // vec4 texColor
  29. // vec4 texMixed
  30. vec4 MIX_TEXTURE(vec4 texMixed, vec2 FragTexcoord, int i) {
  31. if (MatTexVisible(i)) {
  32. vec4 texColor = texture(MatTexture[i], FragTexcoord * MatTexRepeat(i) + MatTexOffset(i));
  33. if (i == 0) {
  34. texMixed = texColor;
  35. } else {
  36. texMixed = mix(texMixed, texColor, texColor.a);
  37. }
  38. }
  39. return texMixed;
  40. }
  41. #endif
  42. // TODO for alpha blending dont use mix use implementation below (similar to one in panel shader)
  43. //vec4 prevTexPre = texMixed;
  44. //prevTexPre.rgb *= prevTexPre.a;
  45. //vec4 currTexPre = texColor;
  46. //currTexPre.rgb *= currTexPre.a;
  47. //texMixed = currTexPre + prevTexPre * (1 - currTexPre.a);
  48. //texMixed.rgb /= texMixed.a;