Cheap glass shader without cube sampler

2f202c9f415522f43d07a9f6b77f0527
0
vdf22 101 Jun 15, 2012 at 15:42

Hey guys I’m back, it’s been a while.

So I’m trying to make a glass shader. Basically I’m making a GUI with OpenGL, so the camera is always going to be pointing the same direction, with a background. I want to make some glass-like buttons etc, and I think it’s a bit overkill to use an cube sampler when I only have to refract what’s underneath (no reflection).

I tried this: http://www.gamasutra…pping_part_.php but it didn’t work very well for me - my object always looked the same no matter what was underneath. I’m going to try again, but if anyone has something else I could do I’d appreciate it.

6 Replies

Please log in or register to post a reply.

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Jun 15, 2012 at 17:54

If your object is too close to what’s behind it, the refraction will be amplified too much, like a magnifier. I assume that because it’s a button, rounded?!

Also, is your button’s normal facing the right way, outwards?

B20d81438814b6ba7da7ff8eb502d039
0
Vilem_Otte 117 Jun 15, 2012 at 18:18

It’s not common, but I’m putting youtube video link here - http://www.youtube.com/watch?v=57zr1vfUK7Q - (I appologize for not marking it as link, but I just cant open dialog for adding hyperlink, though I think the bug is on my side in not updated opera).

Basically you render scene behind your menu to texture - distort coordinates (with some normal map to look good) and map them projectively from camera on GUI. You can also add reflection this way, etc.

Note that it really needs fine-tuning to look good :) - but it’s worth it.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Jun 15, 2012 at 18:33

Looks like you have some dispersion going on in there… :ph34r:

2f202c9f415522f43d07a9f6b77f0527
0
vdf22 101 Jun 15, 2012 at 18:33

@Alienizer

If your object is too close to what’s behind it, the refraction will be amplified too much, like a magnifier. I assume that because it’s a button, rounded?! Also, is your button’s normal facing the right way, outwards?

It’s a flat sphere, so it shouldn’t refract too much (right). Since the article I linked to didn’t use a shader, I made one up with his formulas. But it didn’t give me the results I wanted - in fact moving it the button didn’t even change at all and it just showed the same color no matter where it was. The normals are fine, I’m using a specular shader with it right now.
@Vilem Otte

It’s not common, but I’m putting youtube video link here - [media]http://www.youtube.com/watch?v=57zr1vfUK7Q[/media] - (I appologize for not marking it as link, but I just cant open dialog for adding hyperlink, though I think the bug is on my side in not updated opera).

Basically you render scene behind your menu to texture - distort coordinates (with some normal map to look good) and map them projectively from camera on GUI. You can also add reflection this way, etc.

Note that it really needs fine-tuning to look good :) - but it’s worth it.

Actually I saw that video, which is where I got the idea. :)

I had a heck of a time finding any documentation, but eventually I found that article that uses the same formula, and I’m assuming that’s where he got it from.

B20d81438814b6ba7da7ff8eb502d039
0
Vilem_Otte 117 Jun 16, 2012 at 16:31

@Reedbeta

Looks like you have some dispersion going on in there… :ph34r:

Uff…. it’s not mine, sorry if it sounded like that (credits go to owner of that video on YT) - I just was inspired in this a while ago to do similar effect when turning reflections/refractions on PC where you don’t have enough fast GPU to actually do ray tracing in OpenCL.

I found the shaders I did for effect like this, so here they are (it’s a bit older - I mean like 2 years or so):
http://pastebin.com/XMP0s2GF - Vertex shader
http://pastebin.com/8e3v03Rq - Fragment shader

Look at the bunny - he’s got this shader on him :)
fnbib7.jpg
EDIT: My appologize for comments a bit out in those sources - I use Kate and GEdit as text editors for code (no IDE :ph34r: - pure makefile hell by me) - and pastebin seems like it doesn’t undestand the number of spaces before comments :mellow:

2f202c9f415522f43d07a9f6b77f0527
0
vdf22 101 Jun 17, 2012 at 04:43

Thanks, I’ll try that when I have time. I figured out part of my problem (it was stupid. Really) but my shader still isn’t working quite right. I’ll give yours a go :)