Simulating reflections

A forum to store posts deemed exceptionally wise and useful
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Simulating reflections

Post by afecelis »

A la PS2 Hardware style :wink:
In irredit:
Image
Running in the engine:
Image

should you be interested in achieving this effect, this is where I found out about it:
http://frecle.net/forum/viewtopic.php?t ... reflection

Only drawback is that the more complex the scene, the slower fps performance in realtime you'll get :( But works great in simple scenes like the one I posted!
Last edited by afecelis on Sun Jan 14, 2007 4:06 pm, edited 1 time in total.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Nice job. I think I know already what you are doing without looking at the link. For this kind of thing IrrEdit should include "Mirror against *this* axis" feature, so you do not have to do it manually. Or is it possible to just duplicate all and set negative Y axis scale? :D

Either way you have done a very nice job :D

EDIT: WOW I am very surprised, I just read the link and the steps he said are EXACTLY like I thought :shock:
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

An alternative would be to use my Reflective Water hardware shader and render the reflections into a rendertarget. Irrlicht could do with user-clip planes for this kinda stuff, though.

Duplicating geometry is fine, but what if there's a room below "this" room? You'll have a load of inverted geometry sticking into the lower room!

Hmmm. In fact, if you'd like to send me the scene *without reflections* I'd make a little demo of reflecting floors. 8) Send me a PM if you're interested.
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

thnx for the comments guys! :wink:
EDIT: WOW I am very surprised, I just read the link and the steps he said are EXACTLY like I thought
@Blindside: hehehehe, that can only mean you really know what you're doing!!! :wink:
Hmmm. In fact, if you'd like to send me the scene *without reflections* I'd make a little demo of reflecting floors.
@sio2: 1st idea I had was shaders, but I got no experience with them. So yup! of course I'd love to see your shader version.....and the source of course! :wink: hehhehehehe

you can grab the project here:
http://afecelis.gdlib.net/Irrlicht/files/giroom.zip
it's just a b3d loade rtemplate. If you succeed please let me see your results and code,as this feature heavily interests me :D
Last edited by afecelis on Sun Jan 14, 2007 2:58 pm, edited 1 time in total.
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

afecelis wrote: you can grab the project here:
http://afecelis.gdlib.net/Irrlicht/files/giroom.zip
it's just a b3d loade rtemplate. If you succeed please let me see your results and code,as this feature heavily interests me :D
I'll take a look. Should just a case of adapting my existing reflection shader. Once I have it working I'll bundle up a demo and the source. :)
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

@Sio2: I was thinking and it would be very cool if your shaders could be coded into Irredit. That way it would just be a matter of selecting the floor material, and selecting (from a newly created shaders tab) a material property or shader type that would turn it into "reflective". Then, you'd just save the .irr file and load it!

would such thing be possible? I mean, are you sharing your stuff with plans to get it merged into the source? :wink:
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

I'm not sure I even need shaders for this. If Irrlicht has a built-in reflection material then all I need to do is set the material's reflection texture to a pre-rendered rendertarget. I'll look at this when I code it up.

I'm not sure I'm doing anything that can be put into the core, just using what Irrlicht is already giving me. :wink:
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

First things first, great art afecelis.

Well both methods have advantages, the afecelis method has theses
postives:
-low requirements
-easy and unobtrusive to simple rendering sequences like irrlicht's
-no rendertargets (but new internal targets such as p buferrs and fbo's are quickly approaching "normal" performance
-vertex transform costs are out of question if instancing is used(i think its directx only) this means the gpu only needs to draw both the reflected and normal scenes and very little transforms (less than transforming both scenes)
negatives:
-you are practically rendering twice the surfaces with twice the textures being rasterd= twice the fillrate etc....
-you rendered the scene twice but with no effects on the floor!, only non shader effects can be used to make the floor have other properties than reflection
- this isnt really a negative but just make sure even dynamic objects are copied so you can get dynamic reflections

the render target method:
postives:
-you can have the render target at a lower resoltion, so yes you are rendering the scene twice like the above method but you are rendering maybe 1.5x pixels rather than 2x pixels.
-applying shader effects is easy and a good oppurtinity to show some eye candy.

negatives:
-rendertargets are slow
-hard to implement
-requires shaders
-rendering sequences are getting complex
-im not sure you can do instancing in across two rendertargets (framebuffer and texture target).

I think its obvious which method to use now :wink: but if you want fancy floors with fancy reflection distrorting shaders then us method 2.
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

@ sio why not do 6 render targets in irredit of the room map them on a 6 parted sphere capture that sphere with another render target then save it, voila a spehere map of the scene.

another cheaper method is to set the camera fov really high (fisheye style) for a cost of only 1 vs 6 rendertargets.

I was experimenting with realtime reflections using shaders and these kinds of "online" spheres (i dont want to implement cubemaps).
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Hey guys, cant we just use RenderToTexture for this thing? :?
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

BlindSide wrote:Hey guys, cant we just use RenderToTexture for this thing? :?
Doh! Not only have I already mentioned this twice in this thread, but I've already previously implemented rendertarget reflections! :wink: This is what my ReflectiveWater snippet does: real-time dynamic reflections to an Irrlicht-handled rendertarget. [There are two snippets, BTW]

Anyway, I now have reflections working with afecelis's nice room mesh; I use an Irrlicht rendertarget for dynamic reflections. Just gotta tweak and then I can release. 8)
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

ahhhhh! great news Sio2! can't wait to see it! :D
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

afecelis wrote:ahhhhh! great news Sio2! can't wait to see it! :D
I have this working now. I'm just going to add a few things to the demo and then I'll post it. I want to add a few dynamic objects to make use of the dynamic reflections. There are a few "rough edges" but this proof-of-concept, not production code. :wink:

I've had issues with Irrlicht that have slowed me down. I'm ditching the OPENGL driver for the time begin in favour of the DIRECT3D9 driver. The GL driver currently won't allow rendertarget textures to be used as GUI textures. This makes it tricky to debug them. Also, HLSL has explicit bindings of textures to sampler stages - I'm fed up with textures in my GLSL shaders showing up in the wrong sampler slots!
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

I couldn't resist posting a screenshot for you all to drool over until I can polish off the demo. :twisted:

Yes, those reflections are dynamic and the reflections are blended into the floor texture. 8)

Image
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

oh man! :shock: :shock: :shock:
amazing! please keep us updated!

ps. Too bad about the OpenGL issue.
EDIT:Just saw you already reported it as a bug.
But the result with D3D9 is simply amazing. I hope the gl issue on the Irrlicht part gets fixed.

thanks for looking into it! :D

regards,
Alvaro
Post Reply