Jump to content


Cheap glass shader without cube sampler


6 replies to this topic

#1 vdf22

    New Member

  • Members
  • PipPip
  • 30 posts

Posted 15 June 2012 - 03:42 PM

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.

#2 Alienizer

    Member

  • Members
  • PipPipPipPip
  • 435 posts

Posted 15 June 2012 - 05:54 PM

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?

#3 Vilem Otte

    Valued Member

  • Members
  • PipPipPipPip
  • 345 posts

Posted 15 June 2012 - 06:18 PM

It's not common, but I'm putting youtube video link here - - (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.
My blog about game development (and not just game development) - http://gameprogramme...y.blogspot.com/

If you don't know how to speed up application, go "roarrrrrr!", hit the compiler with the club and use -O3 :D

#4 Reedbeta

    DevMaster Staff

  • Administrators
  • 5308 posts
  • LocationSanta Clara, CA

Posted 15 June 2012 - 06:33 PM

Looks like you have some dispersion going on in there... :ph34r:
reedbeta.com - developer blog, OpenGL demos, and other projects

#5 vdf22

    New Member

  • Members
  • PipPip
  • 30 posts

Posted 15 June 2012 - 06:33 PM

View PostAlienizer, on 15 June 2012 - 05:54 PM, said:

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.

View PostVilem Otte, on 15 June 2012 - 06:18 PM, said:

It's not common, but I'm putting youtube video link here - - (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.

#6 Vilem Otte

    Valued Member

  • Members
  • PipPipPipPip
  • 345 posts

Posted 16 June 2012 - 04:31 PM

View PostReedbeta, on 15 June 2012 - 06:33 PM, said:

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 :)
Posted Image
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:
My blog about game development (and not just game development) - http://gameprogramme...y.blogspot.com/

If you don't know how to speed up application, go "roarrrrrr!", hit the compiler with the club and use -O3 :D

#7 vdf22

    New Member

  • Members
  • PipPip
  • 30 posts

Posted 17 June 2012 - 04:43 AM

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 :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users