# Refraction

Hi everybody!
Has anyone a demo of refraction under OpenGL? I’ve to write a small program that shows a pool, with animated water in it, and to view the ground of the pool correctly i need an algorithm for refraction. I’ve somebody has a small program or demo with the source code i would very happy
Thx, Holyghost

Refraction is hard in OpenGL, although there
are some ways to “cheat”.

For example, you can render what’s below the
pool into a texture, and then stretch the
texture coordinates for the vertexes you
render when you render that texture to the
surface of the pool; blending it with the
actual surface.

You might want to use bump mapping or
environment mapping, too, for reflections or
caustics.

I believe there was a good demo of these
things on one of the popular graphics sites
half a year ago; try a Google search.

Or just check out a book on basic optics at your library. The algorithm isn’t too hard to pick up…

Thx Guys
I allready found out, that i will have to fake this effect.
@bgl: your right i’m going to use an enviroment map for refelctions, but first of all i must implement an algorithm for the refraction effect.

Thats for the help, if you find out something new, plz tell me

Are you trying to create a caustic? If so you want to read Advance Animation and Raytracing Techniques by Alan Watt.

This simple method creates a caustic simulation. It uses a single light point and regular grid a projection plane that is parallel to the grid. This is not the all singing / dancing method and the odd artifact is created, but it should work nicely for a looping animated texture.

[ul][li]Create a linear xy displaced grip, using say sine waves. []for each vertex in the grid, project a ray from the light source through the grid, using the refraction equation to displace it.[]Construst a new grid from the vertexs that are created from the intersection of the projection plane, creating a caustic grid. (can be fudged from the ‘height’ of the vector!)[]Triangulate both the displacement and projected grid. Each triangle in the displacement grid must coorespond to a triangle in the projected grid.[]Find the area of the cooresponding triangles and then divide the area of the displaced triangle by the area of the projected / caustic triangle.[]take the dot product of the face normal and the light vector(standard lighting equation) and multiply it by the result from the previuos step. Use this scalar result with the original light’s colour coordinates, voila you have the refracted caustic intensity.[]Apply the caustic intensity to the projected tris in the caustic grid as either a colour value or an opacity value.[*] (optional) For each vertex on the caustic grid, sum and average the caustic intensities of its associated tris. Use gourad shading[/ul][/li]
Should work, if anyone gets it goiung I’ld love to see it. Wrote this one on my MSc, sadly got the area of a triangle equation wrong!(serves me right for chunking it out f graphics gems). Then I had to do other stuff so nvere finished it

Good luck!!!