Reflection

What it says on the tin: a place to discuss proposed new features.
Post Reply
zander76
Halfling
Posts: 89
Joined: Sun Oct 06, 2002 11:19 pm

Reflection

Post by zander76 »

Hello Everybody,

I was thinking the other day about mirrored surfaces. To make a mirrored surface you have to setup and reflection matrix and renderer the world a again to a texture that is applied to a surface.

So what I was thinking is that it would be really nice to have a Reflection parameter in the material file.

texture floor.png
reflection 0.2

The number would be how reflective the surface is. 1 being fully reflective so the texture about would not be seen at all. That would give the artist control over how reflective they think the surface should be.

Does this sound like a good idea. Has it already been done. I read the part about reflections in the docs but it was cubmapping and enviromental mapping. I nice feature but not a true reflection.

Thanks, Ben
Dating a women is like driving in a foreign country. You don't know what side of the road your on, you can't understand the signs and you certainly don't want to ask for directions but it usually worth the ride. :)
User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4011
Joined: Fri Sep 19, 2003 6:28 pm
Location: Burgos, Spain
x 2
Contact:

Post by Kencho »

There are some features supported for this purpose in Ogre (take a look at the Camera class, and its methods for "reflected camera" and so on...)
The problem is that you can't use a material as a "reflector/mirror", as the geometry can be extremely complex, and you have to render the scene for each reflection plane. For a plane, this is render twice. But for a cube, this means render 4 times (for a perfect cube, and not rendering the occluded faces....). This is why it's usually selected a plane as the mirror for the whole scene, and use stencilling to reflect just some parts...
Image
User avatar
japito
Halfling
Posts: 77
Joined: Mon Apr 26, 2004 11:01 pm
Location: In your MBR ... (sometimes in spain)

Post by japito »

Kencho wrote:There are some features supported for this purpose in Ogre (take a look at the Camera class, and its methods for "reflected camera" and so on...)
The problem is that you can't use a material as a "reflector/mirror", as the geometry can be extremely complex, and you have to render the scene for each reflection plane. For a plane, this is render twice. But for a cube, this means render 4 times (for a perfect cube, and not rendering the occluded faces....). This is why it's usually selected a plane as the mirror for the whole scene, and use stencilling to reflect just some parts...
You can explain it a little more?
ummmm emmmm estoooo.....
User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4011
Joined: Fri Sep 19, 2003 6:28 pm
Location: Burgos, Spain
x 2
Contact:

Post by Kencho »

Yep. Reflections (in the context he is talking) are quite "expensive" as you must perform them manually. For instance, think you have a marble floor and want to reflect the geometry on it. You have to make two render passes: One for the above and one for the reflection, plus the floor "transparency" and some scaling and stencil operations. There are many papers about this around internet. What he was talking about was adding this feature in the material scripts, so you just say the amount of "scene reflection" and OGRE would do everything else.
This can be done, so that OGRE would detect the plane that would perform the reflection, and it will automatically modify the render algorithm so that it reflects it. The problem is that if the mesh that will reflect is not a perfect plane, then it must add a render pass per face (guess the performance rendering a 100K polygon scene per frame?). If you have a plane, you render the scene twice. If you have a cube, you render it 4 times (the original and one per face you actually see). If you have a 45K geosphere... well... 22501 times... is... wow.

Do you know what I'm talking about? ;) Of course there are "approaches" A LOT less expensive, like cube-mapping reflections, with the cost of less accuracy in the reflections. But even with this is not practical to add a parameter in the material script for this, but doing it manually.
Image
User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »

If your object has a lot of faces you generally want to use a cubemap and do cube/environent mapping. (see CubeMapping and EnvMapping sample) instead of rendering each face as an reflection.
This still needs 6 render-to-textures for each reflective object though, in a dynamic environment.
User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4011
Joined: Fri Sep 19, 2003 6:28 pm
Location: Burgos, Spain
x 2
Contact:

Post by Kencho »

That's what I was talking about at the end of the post.

Anyways, I still ask myself why you have to render the scene 6 times for the cubemap reflection, while you just see reflected 3 at most :?
From top down:

Code: Select all

+------+   \
| cube |    \ <- View frustum
| map  |     \
+------+      \
               \
----------------* Camera
As you can see, you don't see more than 3 faces never, so I think you just need to use (or at least update) 3 faces each frame, instead of 6, right?
Image
User avatar
DWORD
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 1365
Joined: Tue Sep 07, 2004 12:43 pm
Location: Aalborg, Denmark
Contact:

Post by DWORD »

Looking at a reflecting sphere, I can see at least 5 faces. Left, right, top, bottom, front. I can't figure out whether you can in any situation see all six faces if there's some weird rotation, but 3 is not enough, I think.
User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »

Yeah, you are right that not all six faces need to be rendered every frame.
But for complex geometry it might be very hard to decide which ones aren't visible.
Although maybe.. hmm I'm not sure. There must be some paper or text about this.
User avatar
DWORD
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 1365
Joined: Tue Sep 07, 2004 12:43 pm
Location: Aalborg, Denmark
Contact:

Post by DWORD »

There's also the possibility to spread out the cubemap face rendering over 6 frames. That'll probably give a speedup. I can't remember where I saw this, but I think someone talked about it at some point. Is cubemap render-to-texture in and working (just curious)?
User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »

Not yet. It's on the list for Dagon. The design phase is done though, the only thing left is actually implementing it.
User avatar
SuprChikn
Bugbear
Posts: 863
Joined: Tue Apr 19, 2005 6:10 am
Location: Melbourne, Aus
Contact:

Post by SuprChikn »

:wumpus: wrote:...the only thing left is actually implementing it.
Is that all? :D
User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »

Yes, if you want to give it a spin I can send you what we have.
User avatar
japito
Halfling
Posts: 77
Joined: Mon Apr 26, 2004 11:01 pm
Location: In your MBR ... (sometimes in spain)

Post by japito »

Thanks for all :D
ummmm emmmm estoooo.....
User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4011
Joined: Fri Sep 19, 2003 6:28 pm
Location: Burgos, Spain
x 2
Contact:

Post by Kencho »

Yes, you're right. 5 faces may be needed. Anyways, you can avoid a pass for the unseen face, right?

BTW: I think I have a method to avoid drawing the 6th face always. If the reflection cameras take the same orientation from the camera, the 6th face (back) won't be needed, isn't it?

Performance tuning to the end!! :D
Image
User avatar
DWORD
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 1365
Joined: Tue Sep 07, 2004 12:43 pm
Location: Aalborg, Denmark
Contact:

Post by DWORD »

Yes, I also thought about that the reflection cameras could use the same orientation as the view camera. Then it would probably be enough with the 5 faces. Nice! :)
Post Reply