Write z data to the depth buffer.

This commit is contained in:
Paul Chote
2016-04-08 10:54:30 -04:00
parent ecebb2a844
commit 2634643d91
6 changed files with 51 additions and 20 deletions

View File

@@ -17,25 +17,20 @@ void main()
if (c.a == 0.0)
discard;
if (EnableDepthPreview && length(vDepthMask) > 0.0)
{
if (abs(DepthTextureScale) > 0.0)
{
// Preview vertex aware depth
float depth = gl_FragCoord.z + DepthTextureScale * dot(x, vDepthMask);
float depth = gl_FragCoord.z;
if (length(vDepthMask) > 0.0)
{
// Preview vertex aware depth
depth = depth + DepthTextureScale * dot(x, vDepthMask);
}
// Convert to window coords
depth = 0.5 * depth + 0.5;
// Convert to window coords
gl_FragDepth = 0.5 * depth + 0.5;
// Front of the depth buffer is at 0, but we want to render it as bright
gl_FragColor = vec4(vec3(1.0 - depth), 1.0);
}
else
{
// Preview boring sprite-only depth
float depth = dot(x, vDepthMask);
gl_FragColor = vec4(depth, depth, depth, 1.0);
}
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;