2
0

pass1_trans_fragment.glsl 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. uniform sampler2D ColorMapSampler;
  2. varying vec4 tPos;
  3. #ifdef COLORED_SHADOWS
  4. varying vec3 varColor;
  5. // c_precision of 128 fits within 7 base-10 digits
  6. const float c_precision = 128.0;
  7. const float c_precisionp1 = c_precision + 1.0;
  8. float packColor(vec3 color)
  9. {
  10. return floor(color.b * c_precision + 0.5)
  11. + floor(color.g * c_precision + 0.5) * c_precisionp1
  12. + floor(color.r * c_precision + 0.5) * c_precisionp1 * c_precisionp1;
  13. }
  14. const vec3 black = vec3(0.0);
  15. #endif
  16. void main()
  17. {
  18. vec4 col = texture2D(ColorMapSampler, gl_TexCoord[0].st);
  19. #ifndef COLORED_SHADOWS
  20. if (col.a < 0.5)
  21. discard;
  22. #endif
  23. float depth = 0.5 + tPos.z * 0.5;
  24. // ToDo: Liso: Apply movement on waving plants
  25. // depth in [0, 1] for texture
  26. //col.rgb = col.a == 1.0 ? vec3(1.0) : col.rgb;
  27. #ifdef COLORED_SHADOWS
  28. col.rgb *= varColor.rgb;
  29. // premultiply color alpha (see-through side)
  30. float packedColor = packColor(col.rgb * (1.0 - col.a));
  31. gl_FragColor = vec4(depth, packedColor, 0.0,1.0);
  32. #else
  33. gl_FragColor = vec4(depth, 0.0, 0.0, 1.0);
  34. #endif
  35. }