View Full Version : Reflection and Refraction
12-02-2000, 11:43 AM
As part of an assignment, I have to do a "high-quality" scene with several objects, one of which is a fish bowl half filled with water. I have the fish bowl itself, done with triangles, grey, translucent, all that fun stuff. I thought I was hot stuff for getting that done so fast, but now he gave us an addition. We have to use environment mapping to draw the reflection of the room in the bowl, and use reflection and refraction to make the water look like water.
I found the environment mapping section in the red book, and I think I can puzzle my way through it, but I can't find anything on how to manage reflection and refraction. I'd hate to have to use clipping planes in any way, because the container's shape is fairly complex, and hence the water's boundaries are too. Does anyone have any ideas? I'd appreciate at least a general description of the process.
12-02-2000, 11:49 AM
Yeah, using multiple viewports is bad...
Maybe you could try to make the bowl a texture every frame and work with "moving" texture coordinates. That would give an effect that would be at least getting closer to what you need.
12-02-2000, 11:51 AM
Oh, I asssume that this refraction thing is that what the surface of whater does. I wonder if this can really be done realtime with polys, it would fit better to the raytracing algorithm.
12-02-2000, 11:52 AM
Could you elaborate on that a little? It's been a long day. http://www.opengl.org/discussion_boards/ubb/wink.gif Actually, maybe I should too. Just to clarify, it's a static scene, so I don't have to make the water ripple or glisten or anything like that. I just have to refract the light that goes through this static shape, and I guess reflect the scene from all 8,000 or so of my individual triangles that make up its border.
12-04-2000, 07:57 AM
As for reflection, I'm certainly no expert myself, but you can texture the bowl with a texture you generate by rendering the scene from the direction of the bowl and then load that into a texture and then use sphere mapping to map it onto the bowl. As for refraction... is this guy SERIOUS!?!? Does he really expect you to do this real time? Are you taking "God-like 3D rendering" 101? Or does it matter how long it takes to render the scene? If not, I'd suggest looking into raytracing. Perhaps you could do a multi-pass rendering thing and multi-texture the bowl by finding out what lies behind the bowl and then render just that to a texture and then wrap that around the bowl as well thus creating an illusion of a magnified image of what's behind the bowl. But, as you said, this would be difficult since the bowl is only half-full so you'd actually have to find out where the water is and then somehow just render that texture to the part of the bowl where the water is. You may just have to hard-code texture coordinates that cooincide with where the water line is on the bowl. Sounds like a pretty cheap way to go but, hey, this guy's asking ALOT! Does this teacher of yours have any idea if this is really possible or does he just enjoy asking the world of his students just to see the horrified looks on their faces when he hands out the assignments?
Do you have to use sphere maps, or are you allowed to use cube maps (Which only work on GeForce or Radeon right now)?
If you can use cube maps, the NVIDIA developer site has a paper on simulating refraction. You might be able to adapt the algorithm to use sphere maps. http://www.nvidia.com/Marketing/Developer/DevRel.nsf/WhitepapersFrame?OpenPage
They also have stuff on reflections.
On www.gamasutra.com, (http://www.gamasutra.com,) there's a two part article on simulating reflections and refractions with sphere mapping. It demonstrates the effect with DX, but it's probably easily adaptable to OpenGL.
The article is at http://www.gamasutra.com/features/20001110/oliveira_01.htm
The second half of it is at http://www.gamasutra.com/features/20001117/oliveira_01.htm
Hope you find this helpful.
[This message has been edited by j (edited 12-04-2000).]
12-04-2000, 11:29 AM
Thanks for all the input guys. It doesn't matter how long it takes to render, it's just a static scene. And to use sphere mapping, don't I actually have to have a sphere object like gluSphere or something? My bowl is just made up of polygons. We just started textures a week or two ago, so I'm still feeling my way around. We don't HAVE to use any particular kind of technique. He just wants the end result. In his words:
"You can use environment mapping to render the reflection of the room as seen on the bowl. Also, since the bowl is half filled with water, the portion above the water level would look different. Remember that a light bends as it passes through water. Take reflection, refraction, etc into account."
I think it's probably a lot simpler than I'm making it seem somehow, since some of the stuff you guys are describing sounds significantly more advanced than anything we've done so far. Anyway, I'll see what I can do with what everyone has suggested so far, and if anyone has a flash of inspiration, I'll be checkin on this post a lot. Thanks guys!
And to use sphere mapping, don't I actually have to have a sphere object like gluSphere or something? My bowl is just made up of polygons.
As long as you specify a normal for every vertex in your model, you can use sphere mapping.
We don't HAVE to use any particular kind of technique. He just wants the end result.
Yes, but the techniques that you can use depend on what the teacher is going to use to view the assignment, which determines some of the techniques you can use.
For example, if he's using a software implementation of OpenGL to view the assignments, you could use sphere mapping, but you probably couldn't use cube mapping, which is an extension to OpenGL.
12-04-2000, 12:28 PM
Does the teacher even wants you to use OpenGL for rendering refraction? What are you learning???
implement a raytracer (not that hard) and just use opengl for rasterization.....
just a thought
12-04-2000, 03:17 PM
J, thanks for the info. He's going to be using the same implementation I am - software on Sun Solaris. I just love being at a school where Windows is so frowned upon...
Michael, the course is just called "Computer Graphics" but we've done almost nothing but OpenGL since the first week or so. I'm not sure if he expects me to get the refraction completely accurate, or just fudge it somehow. At the rate I'm going, I'll be lucky to get that environmental mapping working..
X, that sounds like a good way to do it, and if I was just now starting the project I'd probably try that way. Unfortunately, my fish bowl has to mesh with a few other people's components, and it's due tomorrow night (we're trying to finish tonight). So I think that much work is probably not gonna get done.
Thanks for all your help. I think some variation on the sphere mapping a render done from the bowl's perspective will probably take care of my reflection problem. As for the refraction, the gamasutra articles outlined a general approach that makes sense, I just don't know how well I'll be able to implement it. But I'll take a crack at it, at least.
12-13-2000, 04:26 PM
You may want to drop by your local Barnes & Noble and have a look at the last chapter in the book Game Programming Gems. It is an article on doing real-time reflection and refraction mapping as you suggest. Not worth buying the whole book for that one gem (especially for a student) but worth a read.
-JasonM at ATI
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.