Cheap reflection/refraction

Started by
8 comments, last by InvalidPointer 15 years, 5 months ago
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
Advertisement
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...
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.
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.
So I have no idea how to get started here :(
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.
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.
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?
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.
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.
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...
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!
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.

This topic is closed to new replies.

Advertisement