Water Caustics Problem

Hello people.
I am trying to implement Caustics…
I have a level and i want to render all of it with caustics (dont ask why all of it! :stuck_out_tongue: )

I am doing something like this:

glBindTexture(GL_TEXTURE_2D, caustic);
GLfloat sPlane[4] = { 1.0, 0.0, 0.0, 0.0 };
GLfloat tPlane[4] = { 0.0, 1.0, 0.0, 0.0 };
GLfloat rPlane[4] = { 0.0, 0.0, 1.0, 0.0 };
GLfloat qPlane[4] = { 0.0, 0.0, 0.0, 1.0 };
glTexGenfv(GL_S, GL_OBJECT_PLANE, sPlane);
glTexGenfv(GL_T, GL_OBJECT_PLANE, tPlane);
glTexGenfv(GL_R, GL_OBJECT_PLANE, rPlane);
glTexGenfv(GL_Q, GL_OBJECT_PLANE, qPlane);

The function draw(SIMPLE_PASS) draw the Level Polygons setting for all the vertices of the same triange the same planar normal. It does not set any texture coordinate or something other.

But the results are not correct. What i am doing wrong?

PS:I dont use any shader.
PS2: keep in mind that instead of this line glBindTexture(GL_TEXTURE_2D, caustic);
i will traverse through a number of textures

Thank you.

OK, maybe I’m stupid (go on knackered, say it :wink: ,
but you’re generating 4 texture coordinates with a 2D texture. What’s with that?

If you ask me, what you want to do, if you are using a 2D texture, is generate 2 coordinates, but use non-identity plane definitions in the glTexGenfv functions.

yeah you are right. no need to use the other two. I just leave them cause they didnt affect anything :stuck_out_tongue:

but oops… yes… the problem was on the identity plane definitions in the glTexGenfv functions.

I place some other and seems to work better but what values i put in there? :stuck_out_tongue:

thank you

just curious what is going on here and what this looks like… i’m totally baffled mostly.

i could offer up my best guess, but it would probably just waste space.

caustics are radiosity right?

caustics are radiosity right?

I’m no expert on radiosity but I don’t think radiosity calculates caustics. That, I believe, is done usually with photon tracing/mapping.


Well, actually you can can anything radiosity as it computes energy(frequence) of traced photons - that’s what computer graphics tries to simulate :slight_smile:

back to topic: what dou you mean by “not correct”?

Radiosity will never compute caustics as it is only diffuse by definition (no specular component is calculated). And caustics is a totaly specular effect. So only thing resolving caustics is a distributive ray tracer (monte carlo ray tracer for example) or a photon mapping system.

so what is caustics then? what does this effect look like is what i’m asking.

i thought caustics was like placing a red object beside a white object and getting red bleeding onto the white object.

check mjk’s tutorial:


michagl, no that’s generally called global illumination.

Caustics can be used to describe several phenomenon, but in graphics it’s mostly used to describe the illumination patterns through complex refractive or reflective interfaces. Technically I think the term refers to the divergence & convergence in the energy flux (in this case the energy being light).

Someone might also use caustics to describe reflected light patterns of a curved surface (including the specular highlight) but this isn’t common (a real math boffin once used the term this way in a discussion we had). You might also use it to describe the specular component of a global illumination calculation off a curved surface but again that’s not really common useage.

Caustics is used most commonly used to refer to the underwater variations in illumination due to complex refraction effects (see mjk’s presentation of my technique above).

Caustics usually refers to the effect you see when varying amounts of light energy illuminate different part of a surface. Classic examples are the rippling light patterns on the bottom of a swimming pool and the bright spot you see under a magnifying glass.

Color bleeding from one surface to another is simply called “indirect illumination” (when light does not come directly from a light source). Usually you would use some type of global illumination technique to achieve this effect.

Ha! Angus, you beat me by one minute.

looks cool… any way to do it in a single pass with a shader?

can the generated texture coordinates be passed to a shader that is?

i take it the coordinates are generated in hardware?

funny i never thought of using the texture generation functionality for anything creative. i didn’t know you could move the projections around either.

any other interesting effects that can be achieved in this vein?

edit: at what point in the pipeline is GL_NORMALIZE and texture generation performed? does this functionality come with any costs? or are they performed where the programmable shader would normally do its stuff?

heres a demo i wrote a while ago
shows how forward thinking i was then, not, i believe i wrote it on a tnt2, ran it today on a gf5900 whoosh

i’m thinking about doing this effect for scenes with water… however, i’m not really sure what is an apropriate visual effect for instances when you are looking across the water, or into the water from outside.

this looks better than nothing underwater. but what would be the effect as seen from outside the water. maybe looking into crystal clear tropical type water. would you see pretty much the same thing?

should this effect interact with the water surface?

i guess i’m just curious about visuals for implimenting this effect in an environment where the camera is free to roam in and out of the water.

any good resource that describes the physical processes going on here with references? i don’t exactly have a crystal clear beach outside, and i’m not in the mood to go in town to visit a public pool.
also any way to leverage a repeating texture so that the repetition does not appear cheesy seen across a wide swath of geometry? some sort of regular periodic perturbations that is? i assume there are, just like animating water surfaces in a vertex shader.

i’m just curious for resources for water rendering in general. nothing involving render to texture though. i’m not prepared for that.

i’m thinking about doing a depth based water shader, with this caustics effect, an unjulating surface. their will be a height map applied to the water plane as well so that it can go up rivers and bodies of water need not be at ‘sea level’.

some sort of static environment map might be doable as well. can you do view based reflections with a static environment map? is the only reason games render water reflections to texture each frame just to capture dynamic geometry in the scene? or does it have something to do with the camera as well?

hope this isn’t too tall of an order.

if this stuff is too off topic, i can move it to a new thread.



You might want to see my old caustics demo made just for the university presentation. It’s dirty, but shows well correct caustics for flat water pool bottom case. Search for caustics in 3d stuff .

There’s also presentation explaining the whole mathematical (differential) theory behind caustics, but unfortunately it’s in polish only :frowning: