point_fragment.glsl 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <material>
  2. // GLSL 3.30 does not allow indexing texture sampler with non constant values.
  3. // This macro is used to mix the texture with the specified index with the material color.
  4. // It should be called for each texture index.
  5. #define MIX_POINT_TEXTURE(i) \
  6. if (MatTexVisible(i)) { \
  7. vec2 pt = gl_PointCoord - vec2(0.5); \
  8. vec4 texColor = texture(MatTexture[i], (Rotation * pt + vec2(0.5)) * MatTexRepeat(i) + MatTexOffset(i)); \
  9. if (i == 0) { \
  10. texMixed = texColor; \
  11. } else { \
  12. texMixed = mix(texMixed, texColor, texColor.a); \
  13. } \
  14. }
  15. // Inputs from vertex shader
  16. in vec3 Color;
  17. flat in mat2 Rotation;
  18. // Output
  19. out vec4 FragColor;
  20. void main() {
  21. // Mix material color with textures colors
  22. vec4 texMixed = vec4(1);
  23. #if MAT_TEXTURES==1
  24. MIX_POINT_TEXTURE(0)
  25. #elif MAT_TEXTURES==2
  26. MIX_POINT_TEXTURE(0)
  27. MIX_POINT_TEXTURE(1)
  28. #elif MAT_TEXTURES==3
  29. MIX_POINT_TEXTURE(0)
  30. MIX_POINT_TEXTURE(1)
  31. MIX_POINT_TEXTURE(2)
  32. #endif
  33. // Generates final color
  34. FragColor = min(vec4(Color, MatOpacity) * texMixed, vec4(1));
  35. }