Sign in to follow this  
sdacc

Terrain + Mirror, Problem

Recommended Posts

sdacc    122
Hey I'm making a mirror, so I have this terrain... I run it through the pixelshader and compute and blend some textures every frame. Now I want to render the same terrain with the same textures in the mirror, the water actually, without having to recompute every pixel in the pixelshader. Is there a way to do this? Maybe save pixeldata in an array during the pixelshader and use that array when rendering the mirrored terrain? Or instead of recomputing the textureblending every frame maybe I could do it once, and create a huge texture in memory and then use that texture in future rendering, both on the mirror and the real terrain? Anyone have any suggestion of what to do? EDIT: Also, does anyone know of a way to render reflections instead of using a stencil mirror? Maybe send the water vertices through a shader that computes the reflected pixels? Can't find much info on google!

Share this post


Link to post
Share on other sites
turnpast    1011
Quote:
Original post by sdacc
Now I want to render the same terrain with the same textures in the mirror, the water actually, without having to recompute every pixel in the pixelshader. Is there a way to do this?


Stencil reflections?

Quote:

Maybe save pixeldata in an array during the pixelshader and use that array when rendering the mirrored terrain? Or instead of recomputing the textureblending every frame maybe I could do it once, and create a huge texture in memory and then use that texture in future rendering, both on the mirror and the real terrain? Anyone have any suggestion of what to do?


A recomendation: Don't try to optimize before you have a firm grasp of what you are trying to do and know what it is that is slowing you down. Is texture blending the thing that is really bogging your engine down? If so, you should look into how to optimize that before worring about how to use the not-yet-existing optimization help speed up another effect.

The easiest way I can think of to make a reflection is to render the scene from the reflection eyepoint onto a texture and then to render the scene again using the teaxture you just created as a texture on some surface in the scene. If you get this to work and it is too slow start tying to optimize.

Hope this helps.

Share this post


Link to post
Share on other sites
sdacc    122
Quote:
Original post by turnpast
Stencil reflections?


If i render the same geometry again I will have to send each vertex trough the vertexshader and the pixels through the pixelshader again. ELSE, the both terrains will not look the same. See what I mean? It will obvioulsy divide the framerate by 2. ;P

Quote:

A recomendation: Don't try to optimize before you have a firm grasp of what you are trying to do and know what it is that is slowing you down. Is texture blending the thing that is really bogging your engine down? If so, you should look into how to optimize that before worring about how to use the not-yet-existing optimization help speed up another effect.

The easiest way I can think of to make a reflection is to render the scene from the reflection eyepoint onto a texture and then to render the scene again using the teaxture you just created as a texture on some surface in the scene. If you get this to work and it is too slow start tying to optimize.

Hope this helps.


It's running fast... I'm not trying to optimize, I'm trying to draw my scene in a way that runs fast. I think you have misunderstood me.

What I want to do is rendering the same terrain in my mirror without having to send it through my shader again just to make it look the same. That will just slow my application down.

I want a way to render the exact-looking terrain in the mirror as the one rendered above the mirror...

Share this post


Link to post
Share on other sites
turnpast    1011
If you just want to use your render twice there are a number of ways to do it.

1. Use multiple passes rendering first to a texture and then using that texture in following passes, rendering to a screen aligned quad to push it onto the screen.

2. Use multiple render targsts by calling SetRenderTarget with a texture and a greater than 0 index. Has lots of limitations, but will allow you to keep a copy of the render for later use.

Share this post


Link to post
Share on other sites
sdacc    122
Three textures are blended together, first a blendmap that tells where a specific texture should appear. This happens for every pixel in the pixel shader. I want to use the result of every pixel in both the reflected terrain and the default terrain to make them both appear with equivalent colorvalues and shade. As the shade depends on the vertexnormals I will have to use the vertexshader too. And this is where the problem comes in, I don't know how to get the color of each pixel to appear the same on the both terrains WITHOUT having to sending them both terrains through the shader after each other. I'm looking for a solution. :/

Share this post


Link to post
Share on other sites
turnpast    1011
OK, maybe my understanding of what you mean by a mirror is wrong. When I think mirror I imagine a plane or other shape that appears to reflect a portion the scene. The image on the mirror surface should appear to be the scene from a different direction.

To get the correct effect you really have to apply a different view matrix (and perhaps projection too) to the geometry. Different parts of the scene will appear in different places the mirror than they do on the scren. Different objects may become visible or ocluded from the perspective of the mirror. So to do this right you will have to run both the vertex pipeline (different transforms - producing different positions and depth valuies) and the pixel pipeline (different z buffer and different color locations) a second time to generate the mirror.

Do not assume that rendering twice will devide the framerate by two -- you cannot know how things will perform until you test them, it may be a much greater or lesser impact than that depending on where you engine is bound.

Now stencil reflections are a way of simulationg a mirror effect in a single pass with some significent limitations (planar restriction, some of the scene may not appear and you may want to use the stencil for something else like shadows). I do not know of any other way to get this effect in a single pass.

It may be possible to get a planar reflection by rendering to a texture and mapping it across a screen aligned quad so that it appears to reflect. Only across a plane though and still requiring multiple passes.

Perhaps I am misunderstanding your problem or someone else here knows of another tecnuque.

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