Sign in to follow this  
GavinC

Rendering background geometry.

Recommended Posts

GavinC    122
Hi, this is very likely a simple problem. Essentially, what I want to be able to do is render off my scene as per normal (performing lighting etc) and then afterwards render some background scenery. The reason the scenery has to be rendered last is that there are certain fullscreen post-processing passes that we don't want applied to the background, and so it can't be present at that stage. Is there a way to (in the vertex shader), poke the z or w components of the transformed vertex positions to ensure they are rendered behind everything, but maintain perspective? I recall that there was something very similar you could do to have geometry rendered infront of everything (without modifying the view or projection matrices being used), but I don't know if there's a directly applicable method for forcing everything to be more or less at infinity (well, maximum visible depth). Thanks for any help put forward.

Share this post


Link to post
Share on other sites
dave    2187
Why don't you render your background stuff to the back buffer, render your scene to another render target, perform all post effects and then layer the render target on to the back buffer?

Share this post


Link to post
Share on other sites
GavinC    122
Because it means that we burn fillrate on the scene rendering to every pixel of the separate backbuffer with no early-out from depth-test where the background geometry would normally be occluded.

Additionally it uses a separate render target, and in fact would use two separate render targets, as you'd need to use the two originals as inputs to a shader to composite them, and they would have to both be high-dynamic range so that they could be composited prior to the bright-pass and tone-mapping stage.

Those are the two main reasons... there are a few others, but those are pretty major in themselves.

Share this post


Link to post
Share on other sites
berkbig    122
I think if i were doing this i would split the viewport z so that the main scene had a viewport of 0 to 0.9 in z and the background had a viewport of 0.9 to 1.0. I've done this in the past with shadow buffers that needed some off screen geometry putting in at the beginning of the Z buffer and it worked neatly and requires very little messing around...

Share this post


Link to post
Share on other sites
GavinC    122
How would you go about doing that? It's not something I've ever done before, but may be a more viable solution than what I'm thinking of :)

Share this post


Link to post
Share on other sites
GavinC    122
Ah okay, well it was actually very simple as I'd originally thought (at least in the case of non-overlapping geometry, which is fine for what I need to do).

It took two A4 pages of matrix math expansion with test coordinates to come to a very simple solution and a couple of very simple conclusions.

1. You cannot poke w. As it's needed for the post-perspective divide into homogenous normalised coordinates, so if you touch w, you break x and y clip-space coordinates = badness.

2. That means, you can only poke z... and as you always want z to be 1 (to be behind everything), the answer is simply to do this.

Out.Pos.z = Out.Pos.w; // = goodness.

It'd ridiculously simple when you think about it. This way both x and y maintain their positions (including after divide by w), and as pos.z is now pos.w you're essentially doing w/w = 1 every time.

Nice and simple and maintains perspective while being rendered behind everything else.

Of course, that wouldn't work for geometry that overlaps (say if you have a small town off in the distance or something), but for a sky dome or sky box or other 'flat' geometry it does the trick nicely.

Guess I should've sat down and written all of that out before huh? ^_^
Thanks for the help anyway everyone (and I'm still intrigued about splitting the view frustum for separate geometry sets, so if you want to say about that, then feel free, otherwise this post has served it's purpose already).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this