GLSL Refraction (Composition by cwright)

Author: cwright
License: (unknown)
Date: 2009.06.30
Compatibility: 10.5
Categories:
Required plugins:
(none)

This composition demonstrates on (admittedly lame) way to fake refraction using GLTools' Read Pixels and a custom GLSL shader.

Sorry for the large size -- there's an embedded background in there to make it more visually interesting.

PreviewAttachmentSize
refraction.shader.qtz822.32 KB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

usefuldesign.au's picture
Re: GLSL Refraction (Composition by cwright)

Word of the day "tractable", thx.

I have a black-teapot with white highlights. Reading the shader comments I gather I should be seeing a glass tea-pot with refracted light passing thru it.

No messages when I load comp, is it my old GPU NV geForce FX 5200?

dust's picture
Re: GLSL Refraction (Composition by cwright)

this is beautiful on geforce 9600 m GT, refraction shine. im so impressed with these shaders super glsl. i guess in the conventional cgi it just takes a lot longer to actually reflect things but now refraction, fur, physics, ray trace, volumetric all realtime. have i told you i loved you yet today quartz composer ?

gtoledo3's picture
Re: GLSL Refraction (Composition by cwright)

Genius ... you fooled it with depth testing! I remember spending all kinds of time faking something like this to show what should be the "other side" of the object (a genuine reflection), but you went with a better idea and turned it into something you can see "through". Really cool.

cwright's picture
Re: GLSL Refraction (Composition by cwright)

does ReadPixels even work at all on your machine?

If so, I don't know what's happening -- possibly a driver bug or something. If not, you can try attaching the background image to the Texture input -- you'll miss out on the live, colored-sphere refraction stuff, but it'll give you the basic idea.

cwright's picture
Re: GLSL Refraction (Composition by cwright)

Definitely -- there's a lot of cool stuff that can be done (though sadly, QC only exposes a tiny bit of that...)

This isn't by any means an accurate reflection/refraction simulation, (oo, my next glsl demo will combine environment mapping with this, to have even cooler results!) but there are more accurate ones out there. Not having Cube Map support in QC makes them very difficult to adapt though.

Glad you liked it :)

dust's picture
Re: GLSL Refraction (Composition by cwright)

fake or real doesn't matter it performs good for me when i apply it to bouncing spheres. i might have a go at adding an environment map to it seeing i have an example of that cause might even try it as water cause it looks real good as glass texture. i guess cube mapping would be very convenient in quartz like be able to trackball the texture as a projected cube map instead of just changing the U V mapping. i don't know much of how the gl shaders work yet like, i said im just trying to figure them out so i like your example here.

usefuldesign.au's picture
Re: GLSL Refraction (Composition by cwright)

When I mouse the Read Pixel patch I get a live feed of viewer image so guess its working. repatched to the bkdg image – awesome stuff – I can only imaging how good it looks with electrons. Speaking of which, 'wouldn't it be nice' if we could highlight the 9 random patches goto the setttings inspector and change the varience on all 9 patches with one adjustment.

I think you once said that's a big ask for KinemeCore so I prob needn't mention it again.

usefuldesign.au's picture
Re: GLSL Refraction (Composition by cwright)

Connected Read Pixels to a Billboard and not happening despite the preview image on output node.

toneburst's picture
Re: GLSL Refraction (Composition by cwright)

Very nice! Really impressive stuff, cwight!

About QC GLSL shaders not supporting cubemaps.... you mentioned a while back the possibility of maybe hacking some kind of support for volume textures/sampler3Ds, maybe if this is possible, support for cubemaps would also be possible. Have you had a chance to give this any thought, cwright? Just an idle thought...

a|x

cybero's picture
Re: GLSL Refraction (Composition by cwright)

What a really useful working proof of concept for GLSL fake refraction

cwright's picture
Re: GLSL Refraction (Composition by cwright)

I'm not sure that texture/sampler3D's would necessarily make samplerCube's work automagically -- they're both distinct types of data.

I've been poking about QC-SL lately to see what the current state of cubemaps/3d textures is before I really jump in -- when I get around to really working on it, it'll probably be post-SL anyway.

toneburst's picture
Re: GLSL Refraction (Composition by cwright)

Quote:
I'm not sure that texture/sampler3D's would necessarily make samplerCube's work automagically -- they're both distinct types of data.

I wasn't thinking that would be the case.

Quote:
've been poking about QC-SL lately to see what the current state of cubemaps/3d textures is before I really jump in -- when I get around to really working on it, it'll probably be post-SL anyway

Gotcha. I'd love to ask what your pokings have revealed, but I wouldn't be so indiscreet ;)

a|x

gtoledo3's picture
Re: GLSL Refraction (Composition by cwright)

Does this work in 10.6 ok?

I get correct refraction on the stem of the teapot and handle, but the body has that "blackish" look, with lighting.

I hadn't thought Read Pixels worked at all in 10.6, so I was surprised that I can see any refraction, and I'm also surprised that when I hover over input/output tooltips associated with the Read Pixels image, I see a moving image. It seems to work "ok" with a Sprite, but not with this anymore.

I made this test with an RII, and that seems "ok". It works for me, where the read pixels doesn't for some reason, even though it renders to sprite fine (just not the shader).

PreviewAttachmentSize
refraction-1.shader RII.qtz826.71 KB

cybero's picture
Re: GLSL Refraction (Composition by cwright)

The originally posted example does not render correctly in 10.6.

Your revised version does :-).

Thanks for sharing.

Still to dig into the innards of the setup / shader code to tell what is enabling this effect in one and disabling in the other.