material.glsl 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. // Alpha compositing (see here: https://ciechanow.ski/alpha-compositing/)
  26. vec4 Blend(vec4 texMixed, vec4 texColor) {
  27. texMixed.rgb *= texMixed.a;
  28. texColor.rgb *= texColor.a;
  29. texMixed = texColor + texMixed * (1 - texColor.a);
  30. if (texMixed.a > 0.0) {
  31. texMixed.rgb /= texMixed.a;
  32. }
  33. return texMixed;
  34. }
  35. #endif
  36. // TODO for alpha blending dont use mix use implementation below (similar to one in panel shader)
  37. //vec4 prevTexPre = texMixed;
  38. //prevTexPre.rgb *= prevTexPre.a;
  39. //vec4 currTexPre = texColor;
  40. //currTexPre.rgb *= currTexPre.a;
  41. //texMixed = currTexPre + prevTexPre * (1 - currTexPre.a);
  42. //texMixed.rgb /= texMixed.a;