From cde2c1aa6db6577fa415d60280aa53a86b3cc97a Mon Sep 17 00:00:00 2001 From: raysan5 Date: Fri, 8 Apr 2016 00:21:21 +0200 Subject: [PATCH] Added depth drawing shader NOTE: It requires a depth texture as input, it should be configured on rlgl, by default RenderTexture (fbo) uses Depth Renderbuffer instead of Depth Texture. Check rlglLoadRenderTexture() --- examples/resources/shaders/glsl330/depth.fs | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 examples/resources/shaders/glsl330/depth.fs diff --git a/examples/resources/shaders/glsl330/depth.fs b/examples/resources/shaders/glsl330/depth.fs new file mode 100644 index 000000000..06d399f9f --- /dev/null +++ b/examples/resources/shaders/glsl330/depth.fs @@ -0,0 +1,27 @@ +#version 330 + +// Input vertex attributes (from vertex shader) +in vec2 fragTexCoord; +in vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; // Depth texture +uniform vec4 fragTintColor; + +// Output fragment color +out vec4 finalColor; + +// NOTE: Add here your custom variables + +void main() +{ + float zNear = 0.01; // camera z near + float zFar = 10.0; // camera z far + float z = texture(texture0, fragTexCoord).x; + + // Linearize depth value + float depth = (2.0*zNear)/(zFar + zNear - z*(zFar - zNear)); + + // Calculate final fragment color + finalColor = vec4(depth, depth, depth, 1.0f); +} \ No newline at end of file