depth.fs 615 B

1234567891011121314151617181920212223242526272829
  1. #version 120
  2. uniform sampler2D diffuse_map;
  3. uniform float alpha_test;
  4. uniform float clip_near;
  5. uniform float clip_far;
  6. varying vec2 fTexcoord;
  7. varying float fDepth;
  8. float linear_depth(float depth, float near, float far){
  9. return (2.0 * near) / (far + near - depth * (far - near));
  10. }
  11. void main() {
  12. vec2 uvs = vec2(fTexcoord.x, 1-fTexcoord.y);
  13. float alpha = texture2D(diffuse_map, uvs).a;
  14. if (alpha < alpha_test) {
  15. discard;
  16. }
  17. float depth = linear_depth(fDepth, clip_near, clip_far);
  18. //gl_FragDepth = 0;
  19. gl_FragColor = vec4(depth, depth, depth, depth);
  20. }