point_fragment.glsl 1.8 KB

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