Artistic Experiments
  • Home
  • Reel
  • Shaders
    • Stylized Shaders
    • Lighting Techniques
    • Shader Effects
    • Cubemaps
    • Pixel Lit Shaders (Basic)
    • Vertex Lit Shaders (Basic)
    • Unlit Shaders (Basic)
  • Tools
  • WIP
  • Contact

CG Shaders - Cubemap Refraction

1/17/2014

0 Comments

 
I decided to give cubemap refraction a shot as well after finishing up reflection and I ran into some unexpected challenges. The standard implementation form Nvidia and everywhere else on the internet seemed to yield a refraction that looked quite out of place. In order to fix it, I had to invert the x component of the refraction vector prior to sampling the cubemap. 

Here is a before and after shot at full opacity so you can see what i mean: 

Before

Picture

After 

Picture
As far as i can tell the X flip is needed because of how Unity's skybox system works. When I implemented my own skybox with a cubemap it lined up fine. For some reason either the cubemap is coming in backwards in one direction. I wasn't happy with the results of the skybox replacement though (far too low res) so this will have to do until i figure out how to do a proper sky replacement shader.
In any case, check this out - It has normal mapped reflection AND refraction and runs on SM 2.0! 
Picture
One unfortunate thing to note is the best i can do for depth sorting in Maya is set it to Always. This makes it look essentially the same, but Unity uses the render queue to allow transparent objects to still be overwritten. I can't seem to do this in Maya, so the glass will appear in front of things it should be behind. If i find a better solution i'll post it. 

Maya CGFX File:

phongnormalrefractive.cgfx
File Size: 7 kb
File Type: cgfx
Download File

Unity SHADER File:

phongnormalrefractive.shader
File Size: 10 kb
File Type: shader
Download File

0 Comments



Leave a Reply.

    CG Shaders

    Shaders I've built as i teach myself CG. Feel free to download and use for whatever. If you like them you can buy me a beer or something.

    Archives

    December 2014
    April 2014
    March 2014
    February 2014
    January 2014
    December 2013
    November 2013

    Categories

    All

    RSS Feed

Powered by Create your own unique website with customizable templates.