reflections

Started by
83 comments, last by Crispy 21 years, 5 months ago
Which method is faster for creating reflections: through the stencil buffer of by rendering to texture? Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
Advertisement
Depends on the hardware. I would suggest the stencil buffer (at least on T&L class cards) but I am not sure.
It also depends on your scene.
If you're meant to look at a mirror very close (that is, the reflective surface almost covers the whole screen), I'd suggest stencil. It's more detailed and faster. In that case if you used a texture, you would :
- create a very big texture, which uses alot of memory and is very long to fill and long to render,
- or create a pretty small texture that would be fast enough but rendering quality would not be good.
Either way, texture would not be good.

But if you're rendering a mirror which is "small enough", then texture is good and probably faster.

Also note : since stencil is really a direct reflection, it's useful for really flat and really shiny mirrors, but no more. With texture, you can get easily a "dirty mirror" effect or an embossed mirror and cool things like that.

[edited by - vincoof on November 22, 2002 12:45:35 PM]
Ok, understood - thanks for the clarification. However, I''ll thincken the plot now:

suppose (well, no use in supposing - that''s what I want to do ) I want to create a semi-reflective water surface with ripples in it - the ripples would need to reflect light as well, but not as effectively as still water. I haven''t quite made a decision as to how to create the ripples (pixel-based normal calculation is most likely out since the project the thing is for involves outdoor scenery with larger-than-average bodies of water). What would be the most effective (fastest) way of, firstly - going about the creation of ripples, and secondly - applying a reflection to them, be?

PS - if I''m thinking too big here in terms of performance, just say so...

Crispy

"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
what you ask is actually easier than you might think...

I made a demo a good 2 years ago that did that, I never released it though, because it''s code was a shocker...

anyway, just so you see what I mean, heres a pic:


the way this was done was by reflecting the view matrix realitive to the mirror (really roughly, since the mirror - the water - is flat along the z axis)...

then it was a matter of using the texture matrix to project the texture onto the water (again, really roughly done)..

the thing is, here, the water is a mesh, and each vertex has the R texture coordinate moving in a sin pattern, where the S and T coords are generated using tex gen and the texture matrix, so although you can''t see it, the reflection is actually undulating with the water. (this effect, though, is extremly inefficient compared to, say, a vertex shader, since R coords with 2d textures kill performance)...

plus there were a bunch of other effects, like a cube map (hence the line running through the image, since i initially made this on a geforce)...

Note though, for a reflection, you will NEED to clip it off at the mirror... Ati cards support up to 6 (I think) HARDWARE clip planes, ie, they are as fast as fustrum clipping, but Nvidia cards support NONE (older drivers fake them though). so you''d need to have two methods, correct clip plane clipping, and something else, such as texture clipping (alpha test, for example).

| - Project-X - my mega project.. big things comming soon - | - adDeath - an ad blocker I made - | - email me - |
Are you trying to do something like this?:

members.rogers.com/ramrajb/Downloads/IslandDemo.zip
members.rogers.com/ramrajb/Downloads/IslandDemoCode.zip

For the ripples, you can use the ripple or water effect. An article on it can be found in the special effects articles on gamedev. Its written to be implemented in a 2d environment but its easy to convert to 3d. I suggust you use trent''s terrain tutorial to start with. I got lazy and used sphere mapping to do the texture for the water. If you get reflection working e-mail me (thereisnocowlevel@hotmail.com) - i would like to see what you come up with

"Free advice is seldom cheap."
-- Rule of Acquisition #59
aha - I must say your demo looks pretty good, RipTorn - I''d like to actually see the ripples, though (I''m afraid simple undulation is not what I''m looking for). But the reflection part looks gravy. Another question for you, though - how many faces did you use for the trees? They look very 3D and the trees I''m thinking about implementing should look good close up and from afar, while using up only an optimal number of faces (need many of them).

IIvllatrix - the demo''s pretty much what I''m looking for, but not quite yet - I haven''t had time to look at the source, but I most certainly will. As for the mailing part - if this project gets off the ground, it''ll be released freeware (not sure about open source yet) - I''ll be sure to post a link on this forum when the time is ripe.

However, it contains a whole lot of features I have very little or no experience with, so I''d like to thank anyone who contributes their brain power (is that two words?) during the making of it - planning on creating an additional thank-you-list for the Net release...

Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
quote:Original post by Crispy
Another question for you, though - how many faces did you use for the trees? They look very 3D and the trees I''m thinking about implementing should look good close up and from afar, while using up only an optimal number of faces (need many of them).


It looks as if his trees are made up of 2 quads (4 triangles), in an + shape on the terrain, with alpha masking enabled to create the invisible areas on the polygons.

-----------------------
"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else''s drivers, I assume it is their fault" - John Carmack
-----------------------"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else's drivers, I assume it is their fault" - John Carmack
quote:Original post by Maximus
It looks as if his trees are made up of 2 quads (4 triangles), in an + shape on the terrain, with alpha masking enabled to create the invisible areas on the polygons.


Ah yes - I didn''t quite look at the closer ones. The ones further away (and on the left) seem to have (more) volume

Crispy
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
quote:
Note though, for a reflection, you will NEED to clip it off at the mirror... Ati cards support up to 6 (I think) HARDWARE clip planes, ie, they are as fast as fustrum clipping, but Nvidia cards support NONE

Partially incorrect. NVidia hardware (GF3+) supports clipping planes through pixelshaders (the texkill instruction). They aren''t automatic (you have to code them manually), but they are efficient. However, you''ll have to sacrifice a texture unit, which is pretty bad design IMO. You get 4 clipping for each texture unit.

This topic is closed to new replies.

Advertisement