PDA

View Full Version : Glass and water shaders?



halo
11-26-2006, 06:52 AM
Where can I find glass and water shaders with refraction, for things like the glass in HL2? There's got to be a huge resource of glsl textures on the web somewhere.

ZbuffeR
11-26-2006, 12:35 PM
What about this (with source):
http://www.ozone3d.net/demos_projects/chromatic_aberration.php

halo
11-26-2006, 12:53 PM
Hmmm...it looks like that uses a cubemap. Is it possible to just read the pixels beneath whatever is being rendered, and distort those? Or do I have to do a special render-to-texture of whatever is behind the object?

ZbuffeR
11-26-2006, 03:28 PM
You can't read "what is behind" inside a shader.
But in HL2 it is most likely they copy to texture the already-rendered behind-water/glass part.

halo
11-26-2006, 03:34 PM
Do I have to render the scene once to an FBO, then use that as a texture on the glass object and distort the pixels, or is there a simpler way?

ZbuffeR
11-26-2006, 04:04 PM
mmh, and what did I say already ?
Render scene, glCopyTexSubImage2D to a large-enough texture. Guaranteed to work as long as your rendering window is not obscured.

k_szczech
11-27-2006, 03:25 PM
Do I have to render the scene once to an FBO, then use that as a texture on the glass object and distort the pixels, or is there a simpler way?Well, even if you render scene to texture, then you can't render that glass object to this texture and you would probably want this glass object to appear in the rendered scene :)
So you need a COPY of the scene (actually just the fragment that can be seen through glass object). This is why ZbuffeR suggested to copy fragment of framebuffer to texture and not render to texture.

halo
11-27-2006, 03:52 PM
I think I'll just implement a render-to-texture with an FBO. Then I can use the same routine for water reflections, glass, and security cameras.