Z buffer tricks

Hi,

I'm implementing a multilayered clouds system and I am having integration problems because of clipping issues.

My idea is to render an infinite cloud plane for each cloud layer. The layers should be rendered fully behind of the main scene.

In order to achieve this, I would like to raster all pixels of the clouds plane using Zscreen = 1. I make the following steps:

1 Clear color buffer
2 Render main scene using near and far 0.1 and 4000
3 Render sky dome with Zscreen = 1.0 (using vertex shader trick Z = W), zwrite off
4 For each cloud layer
4.1 Render a plane (1 quad of 10.000x10.000 centered arround the eye point) using skydome trick

I've been searching methods to cheat Z buffer values and I've found the following methods:

1. change scene depth range (0.1 - 10000): it works but zbuffer artifacts in the main scene are noticeable
2. vertex shader trick (Z = W): it works with skydome but it doesn't work with cloud plane
3. change viewport depth range [1,1]: same problem as 2
4. write z in pixel shader: it works but it is very expensive and it works only with SM3 cards

I could also try to tesselate the plane in order to minimize artifacts, but I would prefer to use a smarter method.

Any idea?

Cheers,

s.
 
From your description I can't really figure out what you're trying to achieve or what artifacts you are encountering.
 
Xmas: My idea is to render a textured infinite plane with a tiled clouds image behind the main scene (as Crysis's distance clouds). Depending on the view direction, some pixels of the plane are wrongly discarded and this causes a flickering effect.

However, I've had an idea. I'm going to render a fullscreen quad with z = 1 using the main scene zbuffer. In this way, the pixel shader will run only the pixels that has not been written previously.

Besides, I will interpolate a ray from vertex shader to pixel shader (as deferred shading) and I'll use the ray to find the intersection with my plane (defined in world space) in the pixel shader. I need the position of the plane in order to compute procedurally texture coordinates.

I hope it works.

s.
 
Problem solved. I've used the method that is described in my previous post (draw fullscreen quad and intersect ray with cloud plane in the pixel shader).

If anyone knows more methods to raster triangles (with perspective cameras) with fixed z screen values, please let me know.

Cheers,

s.
 
Set Z=0 in the vertex shader and the viewport depth range to [c, c]. That way you shouldn't have any precision issues.
 
Back
Top