Basically, before drawing X-Rays, we now bind a second depth buffer. After drawing XRays, we do an extra resolve pass where we overwrite the non-XRay depth buffer in pixels where the depth is not maximum (which means background pixel, since depth is cleared before drawing X-Ray objects). This ensures both scene and X-Rays keep their depth values and are ready for compositing. Well, the odd effect due to depth discontinuities can be expected, and X-Rays are a bit more expensive (extra buffer + resolve pass) but at least X-Rays won't invalidate depth values anymore. Whee!
15 lines
227 B
GLSL
15 lines
227 B
GLSL
uniform sampler2D depthbuffer;
|
|
varying vec4 uvcoordsvar;
|
|
|
|
void main(void)
|
|
{
|
|
float depth = texture2D(depthbuffer, uvcoordsvar.xy).r;
|
|
|
|
/* XRay background, discard */
|
|
if (depth >= 1.0) {
|
|
discard;
|
|
}
|
|
|
|
gl_FragDepth = depth;
|
|
}
|