Sign in to follow this  
AmidaBucu

Cheap reflection/refraction

Recommended Posts

AmidaBucu    104
Hi! I was thinking about reflection/refraction algorithms. Some ideas came, but all of them needs the render to draw the scene min 2 times. Unfortunately, google gives me links about just cubemap, etc. Or, are there no transparency simulation without more than one drawing at once? If aren't any, could U tell me some cheap one? (Name will be enough) I'm apologizing for my noobility. An thanx ahead for Ur help. BB

Share this post


Link to post
Share on other sites
VerMan    116
Hi,
you might consider Hardware-accelerating ray tracing/reflection using pixel shaders (?).

For instance, for just 1 reflected ray
1. send a light ray to a triangle and get first color (i.e. ray-triangle intersection algorithm)
2. compute the reflected ray (i.e. reflect())
3. get the secondary color using this ray
4. mix the two colors

that will do the trick in only 1 rendering pass, however, it's expensive and it involves some acceleration structures and so on...

Share this post


Link to post
Share on other sites
BlindSide    136
Refraction doesn't always require rendering the scene twice. Render the scene without the glass, then copy the current texture to another (This is a quick operation, if you don't have the functions to do the copy on hardware you can just use a screen quad and blast it to another render target.). Make sure you don't clear the z buffer here, try and do the previous operation without writing/reading from the z buffer. After that just draw the glass as normal with the texture that you copied to applied.

Share this post


Link to post
Share on other sites
AmidaBucu    104
So. At first time I have to draw everything except the glass, then i draw the glass. I do understand at this point. And even I can compute the reflected vectors, I don't know how to get the first occlusion of that vector.

That I know are:
drawing scene without glass (and here I have to store st., but I dunno what that is)
drawing glass
using reflect(worldPos-camPos, normal) function
take the color of the first occlusion of the reflected vector

I know I'm wrong. And I don't know how to get that first occlusion of the reflected vector.

Share this post


Link to post
Share on other sites
InvalidPointer    1842
Quote:
Original post by AmidaBucu
So. At first time I have to draw everything except the glass, then i draw the glass. I do understand at this point. And even I can compute the reflected vectors, I don't know how to get the first occlusion of that vector.

That I know are:
drawing scene without glass (and here I have to store st., but I dunno what that is)
drawing glass
using reflect(worldPos-camPos, normal) function
take the color of the first occlusion of the reflected vector

I know I'm wrong. And I don't know how to get that first occlusion of the reflected vector.

Answer: Don't. ;) This is the idea behind approximation-- you get something that looks pretty close. Once you have your refracted vector, just add the coordinates to the screen-space position of the point you're shading and directly sample that from the back buffer that you stored earlier. There are some issues, sure, but it looks pretty good in practice. You can even get fancy and do some depth comparisons if you have that info available, or maybe even do some additional blending on top of that. This is how Crysis handles its water. Look around for the GDC '08 slides; they have a very nice section on how they did many different kinds of effects you may find interesting.

Share this post


Link to post
Share on other sites
AmidaBucu    104
And what about scenes there are mirrors?
Can I get pixels behind of the camera from the backbuffers?
Or what about a tree and a lake? If I am under the tree and I am looking down vertically at the lake, I would see the reflection of the tree, right? But it isn't in the backbuffer. Am I wrong?

Share this post


Link to post
Share on other sites
InvalidPointer    1842
That's a different beast entirely, or so the saying goes. You could theoretically just do the same thing-- in the situation you described you could calculate a Fresnel term to control the reflection/refraction ratio. Looking directly down would result in 100% refraction and 0% reflection, so the tree probably wouldn't be very visible.

Other than that there's really not too much you can do other than rendering again. It isn't the performance-killer you seem to think if you render at sensible resolutions and have some LoD systems in place.

Share this post


Link to post
Share on other sites
AmidaBucu    104
So, I will render two times for a real reflection. Second reflection will be with low resolution and etc.

And what about non-flat objects? I think there aren't any solution for (such as) a glass. Situtations like that aren't any optional camera position/direction. Just concerned...

Share this post


Link to post
Share on other sites
InvalidPointer    1842
Quote:
Original post by AmidaBucu
So, I will render two times for a real reflection. Second reflection will be with low resolution and etc.

And what about non-flat objects? I think there aren't any solution for (such as) a glass. Situtations like that aren't any optional camera position/direction. Just concerned...

Cubemaps!

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