point_fragment.glsl 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #if MAT_TEXTURES > 0
  7. vec4 MIX_POINT_TEXTURE(vec4 texMixed, mat2 rotation, int i) { \
  8. if (MatTexVisible(i)) { \
  9. vec2 pt = gl_PointCoord - vec2(0.5); \
  10. vec4 texColor = texture(MatTexture[i], (rotation * pt + vec2(0.5)) * MatTexRepeat(i) + MatTexOffset(i)); \
  11. if (i == 0) { \
  12. texMixed = texColor; \
  13. } else { \
  14. texMixed = mix(texMixed, texColor, texColor.a); \
  15. } \
  16. }
  17. return texMixed;
  18. }
  19. #endif
  20. // Inputs from vertex shader
  21. in vec3 Color;
  22. flat in mat2 Rotation;
  23. // Output
  24. out vec4 FragColor;
  25. void main() {
  26. // Mix material color with textures colors
  27. vec4 texMixed = vec4(1);
  28. #if MAT_TEXTURES==1
  29. texMixed = MIX_POINT_TEXTURE(texMixed, Rotation, 0);
  30. #elif MAT_TEXTURES==2
  31. texMixed = MIX_POINT_TEXTURE(texMixed, Rotation, 0);
  32. texMixed = MIX_POINT_TEXTURE(texMixed, Rotation, 1);
  33. #elif MAT_TEXTURES==3
  34. texMixed = MIX_POINT_TEXTURE(texMixed, Rotation, 0);
  35. texMixed = MIX_POINT_TEXTURE(texMixed, Rotation, 1);
  36. texMixed = MIX_POINT_TEXTURE(texMixed, Rotation, 2);
  37. #endif
  38. // Generates final color
  39. FragColor = min(vec4(Color, MatOpacity) * texMixed, vec4(1));
  40. }