Render voxels with an approximately-correct z-offset.

This commit is contained in:
Paul Chote
2016-08-09 10:15:44 +01:00
parent c312cf9171
commit f0306e7cc2
4 changed files with 50 additions and 12 deletions

View File

@@ -1,7 +1,25 @@
uniform sampler2D DiffuseTexture;
uniform bool EnableDepthPreview;
varying vec4 vTexCoord;
void main()
{
gl_FragColor = texture2D(DiffuseTexture, vTexCoord.st);
vec4 c = texture2D(DiffuseTexture, vTexCoord.st);
// Discard any transparent fragments (both color and depth)
if (c.a == 0.0)
discard;
float depth = gl_FragCoord.z;
// Convert to window coords
gl_FragDepth = 0.5 * depth + 0.5;
if (EnableDepthPreview)
{
// Front of the depth buffer is at 0, but we want to render it as bright
gl_FragColor = vec4(vec3(1.0 - gl_FragDepth), 1.0);
}
else
gl_FragColor = c;
}