Skip to main content
gamedev.net
🔒 Locked

Rendering reflections?

Started by matches81 Apr 8, 2005 at 5:02 PM 4 replies 1k views
Original Post
matches81
matches81
Hi there! I´m writing a terrain rendering engine for a small 2-player strategy game I try to do. Currently I can render a terrain 513 x 513 vertices, which sums up to about 500.000 triangles, using 4 textures at an acceptable frame rate. Because it´s my first try doing anything 3d, I´m quite proud of this ;) But I actually don´t have a clue about reflections, which I would really like to implement for the water. I´ve read the article about this VCP stuff here at Gamedev. If I got it right, I´m supposed to mirror the camera position and view angle relative to the water plane (which would be a horizontal plane in my case) and render the whole scene a second time using the mirrored camera EVERY frame. This would mean I´d have to render 1.000.000 triangles every frame, which seems quite much to me. Assuming I´d do that: When I have rendered the whole scene to a texture, how do I "map" this texture correctly to the plane in order to get a correct reflection? What resolution should I use for the texture? Can I use that texture in combination with bumpmapping for the waves? Is there a faster way to do reflections? Cubemaps seem to be used often for things like that, could they be what I´m looking for? Any help appreciated. Would love links to some (or one) tutorial explaining this. BumpMapping tutorials would be great, too. Ah yes, I guess I should tell you, that I would like to the whole water stuff (reflection and bumpmapping) in a HLSL shader, except the texture rendering of course.
sirob
sirob
First off, I too wrote a nice terrain engine, and just recently finished working on water simulation for it. I too am quite proud :).

Anywho, back to the issue at hand, you said that rendering the scene twice per frame seems much, and calculated your number of polygons times 2. I'm assuming this means you have not yet implemented frustum culling. If not, I'd consider looking into that first. Using culling would allow you to only draw what you need, both for the rendering of the terrain itself, and for the reflection rendering. When implementing frustum culling in my engine, I saw an increase of over 20% (not imediately, had to improve the coding several times).

Also, regarding using cubemaps, as far as I know, cubemaps are mostly used to reflect a skybox over your water, and they arn't really efficient for reflection your actual terrain through the water.

You mentioned you would like to try HLSL, so I'd also recommend you try a simple HLSL shader before jumping in, since water shaders are quite complicated. Maybe you should try rendering terrain using HLSL first :).

Finally, if you feel ready to start with water simulation, I really have to recommend the SWEET water shader included in NVidia's FX Composer (nice program for HLSL coding). It's called "Ocean" and it's what I based my water simulation on (actually, theres a commented section in that sample, that has a simpler technique, which is what I used).

heres a link to some screens and a demo of my currect engine: http://www.devimg.net/?View=484

Anywho, hope this helps, and best of luck.
Sirob Yes.» - status: Work-O-Rama.
matches81
matches81
thx for the reply.
nice looking screens. ;) is that engine tile-based? (I ask because of the textures mapped to the terrain)
I´ve already added frustum culling to my 'engine'. Worked out fine, gave enormous performance increases for me, something about 30 to 50 percent. But still got some bug in it, it cuts away some tree-nodes of my quadtree that should be visible (at the edges of the screen), should fix this some time ;)
My calculation was for worst-case, if you see the whole terrain.
The texturing of my terrain is mainly done in a HLSL shader... quite a simple one, but after all it´s a shader :)
I just used the R, G, B and A value of the vertex´ color as blending percentages for the four textures, works fine and runs in shader model 1.1 after some tuning of the code.

I´ll have a look at the water shader from nVidia, thx for the tip.
Did I understand your post right that cubemaps should only be used for reflecting a skybox?
HL² for example uses cubemaps for reflections on the water, yet I noticed some 'severe' inaccuracies while building a map. But since I´m not going to use reflections for such general purposes as they do, I thought I might use the idea and tune it to fit my need. If I´m right I could calculate the cubemap once at terrain generation and use it for the reflection later on. Still my water wouldn´t reflect dynamic objects that move.
Hmm...
so I guess I will have to stick with VCP after all.

Still the questions remain:
- Is it enough to mirror the camera position and view vector and render the whole scene to a texture?
There surely is a faster way than mirroring the camera and then generate a new view and projection matrix. Could I directly change those two matrices to get the result I need? How?
- How should I map the rendered texture to the plane? (I assume this question will be answered when looking at the shader sample from nVidia, but it´s 4 AM here in Germany and I´m off to bed, so I´ll leave the question open)

Thx for reading
sirob
sirob
First off, my terrain engine uses a 1024x1024 texture, split into 16 smaller ones (4x4). I use 2 of the color values of the vertex to select on of the 64 possible options (each texture can be unmodified, mirrored horizontally, vertically, or both). I also do this in a shader, and I use another of the vertices' color value for the lighting (precalculated for speed reasons).

back to the water, I wasn't clear enough :). The "Ocean" sample is for the water type I added to my engine, which only reflects a cubemap (which is also my skybox -- so the water actually fits the screen).

I do know there are ways to reflect your terrain using cubemaps, but everything I've read about this indicates it's slow as hell :).

Regarding reflecting the actual terrain, I havn't gotten into it, but it shouldn't be that big of a deal. Theres some code you use to mirror the view matrix across a plane, then you set the rendertarget to a texture, and render your terrain again (frustum culling should cut out most of the terrain so only very little is drawn). Then you use some shader (with or without bumpmapping) and render a water quad with the texture you created. This doesn't seems very expensive to me, really.
Sirob Yes.» - status: Work-O-Rama.
matches81
matches81
:( seems that the 'ocean' is not included in FX Composer anymore, I remember seeing it some time ago, but it isn´t there in my release of the composer. I would be happy if someone could tell me where to get it?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.