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 - Skyboxes

1/24/2014

0 Comments

 
I promised this a while back and so here it is: A proper fix to Unity's Sky Shader and a Sky Shader for Maya too. The sky shader uses a cubemap in Maya and is mostly useful for quick previews. With a sufficiently high res cubemap it shouldn't be an issue though. 

What i ended up having to do is invert the x component of the uvs for the sky shader (however they are provided) and then flip the Right and Left passes. Its kinda hacky but it works. And much better to fix in the sky shader one time than in each of the reflection/refraction shaders. I've also updated the old reflection/refraction shaders to work without the X flip by default now.

Maya CGFX File:

skybox.cgfx
File Size: 2 kb
File Type: cgfx
Download File

Unity SHADER File:

skybox.shader
File Size: 4 kb
File Type: shader
Download File

0 Comments

CG Shaders - Ambient Cubemaps

1/21/2014

2 Comments

 
Here's another trick based on one of Valve's GDC talks: Ambient Cubemaps. Basically, a cubemap is used to approximate the ambient light of the scene. It is similar to Spherical Harmonics in that it provides low frequency light information but doesn't require all the scary math. 

Valve's Implementation looks quite nice, but requires 3 texture samples as far as i can tell, so i tried to emulate the visual effect while only taking a single sample at a low mip level and adjusting it in the shader. It comes quite close, although Valve's implementation's colors are a bit richer.  A good improvement would be to bake out a low res cubemap based on Valve's implementation and then save that into the lowest mip level of the cubemap where you could access it directly, but that's a little beyond the scope of this demo. 

Valve's implementation is enabled by default, but you can re enable my single pass attempt in the shader.

Maya CGFX File:

phongnormalambientcube.cgfx
File Size: 8 kb
File Type: cgfx
Download File

Unity SHADER File:

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

2 Comments

CG Shaders - Cubemap Refraction 2

1/19/2014

0 Comments

 
A little update on the last one. This one includes chromatic aberration (rainbow lensing) and all the fancy reflection controls from before. I'm not sure if the contrast adjustments make sense in this case. They work well on opaque reflections, but transparent reflections only really need a brightness boost in my opinion. I'll leave that up to you though.

The biggest change though is that it also has a diffuse term again, so you can add stains and stuff to the glass. The other glass was looking a bit clean for my taste. Overall opacity is still set with a slider though - the diffuse alpha only covers its coverage of the glass. Also, the diffuse is unlit, since lighting it would produce incorrect shadows.So instead I make the specular map do all the work. This may seem odd, but it produces the best look I've found so far.
Picture

Maya CGFX File:

phongnormalrefractive2.cgfx
File Size: 9 kb
File Type: cgfx
Download File

Unity SHADER File:

phongnormalrefractive2.shader
File Size: 11 kb
File Type: shader
Download File

0 Comments

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

CG Shaders - Cubemap Reflection 2

1/14/2014

0 Comments

 
Just a small variant on the last one. This one also contains parameters for adjusting the contrast, blur, and saturation of the reflection. Unfortunately this bumps it to SM 3.0, so i decided to do it separately. They make the shader properties from before much more useful though. 

By adjusting the contrast, you get a lot more range to play with in all the other attributes from earlier, and you can get much more realistic reflections. While you can do a cheap blur with a texCubeBias, its pretty lossy and has a problem of tearing at edges. Instead i modify the reflection vector to filter the cubemap. This only costs 1 extra sample, but you could remove the extra sample if you are fill limited. Finally, I added a saturation control. I think that this might make light reflective materials easier to work with.
Picture

Maya CGFX File:

phongnormalreflective2.cgfx
File Size: 10 kb
File Type: cgfx
Download File

Unity SHADER File:

phongnormalreflective2.shader
File Size: 12 kb
File Type: shader
Download File

0 Comments

CG Shaders - CubeMap Reflection

1/14/2014

0 Comments

 
Here is a simple example of cubemap reflection, based on my emissive phong shader. I just chose that one because it looks nice and i was tired of bricks :)

I replaced the Fresnel color with the reflection and added a brightness multiplier for it. You could add the rim light back in but you might have to push into SM 3.0 and the effect is kinda meh when mixed with reflection so i cut it. My original intention for the rim light was a hack to fake highlights along grazing angles, and reflection is a more robust solution to the same problem.
Picture

Maya CGFX File:

phongnormalreflective.cgfx
File Size: 8 kb
File Type: cgfx
Download File

Unity SHADER File:

phongnormalreflective.shader
File Size: 11 kb
File Type: shader
Download File

0 Comments

Optimization

1/12/2014

0 Comments

 
Before moving onto new shaders, i thought the new year was a good point to stop and work on some optimization. After about a week of work, i'm happy to report that i was able to squeeze quite a bit more juice out of them and I've uploaded all of the new versions for download. Some shaders like parallax now can run on shader model 2.0 instead of requiring 3.0 and viewport performance in Maya is much improved. A good example of this is the flowmap shader, which feels much more responsive when painting vertex colors. 

Moving forward, i hope to do more quick optimizations before uploading. If there is something that i find a better way to do in an old shader, i will try to upload that as well.
0 Comments

    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.