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

12/21/2013

0 Comments

 
This is one of my favorite shaders. It was really challenging implementing it the first time i read Valve's GDC paper on the subject, but I've gained a bit of understanding since then. It is super useful for not only water, but particles as well, like smoke and fire. While UV offsetting and flip-book textures will get you somewhere, flowmaps will get you even further in terms of variation between particles. Pretty much anything you want to look fluid like but don't want to pay fluid costs for is a great candidate for flowmaps IMO.

These shaders implement the full suite of techniques described in the original presentation by Valve. This includes the pulsing fix, debris flow, and normal intensity modification. It also runs off of vertex colors by default but you can change that in the pixel shader. Hope you like it!
Picture

Maya CGFX File:

phongnormalflowmap.cgfx
File Size: 12 kb
File Type: cgfx
Download File

Unity SHADER File:

phongnormalflowmap.shader
File Size: 18 kb
File Type: shader
Download File

0 Comments

CG Shaders - UV Panning

12/15/2013

2 Comments

 
Here's an example of some of the my more basic water. It uses a normal map sampled twice and offset over time. This allows the map to pan across the UVs, giving the illusion of movement. Used with tilable textures the effect is decent. I offset by sin(time) in one direction and adjust the speed and scale of the second normal map to add a little variation. It also uses alpha blending via a frensel term with a slight bias.
Picture

Maya CGFX File:

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

Unity SHADER File

phongnormalpan.shader
File Size: 13 kb
File Type: shader
Download File

2 Comments

CG Shaders - Directional Masking

12/14/2013

0 Comments

 
Here's a simple version of something i made way back in the day in Unreal - Up Vector snow. This works similarly to the RGB masking from the last shader, except you don't have to paint a mask. Instead, the shader creates a mask based on the world normals, applying snow to all faces facing upwards. I also included a vertex color mask to paint out areas. This will allow you to prevent snow from showing up in places that don't make sense, like underneath an overhang or inside a building. Finally it includes a layer of ice that is independently tweakable and paintable. 

This makes it almost as robust as my old shader. I decided to not include stuff like wind direction and heat sources, as it requires a bit of scripting and the visual effects are somewhat minute. Still, if you've been following along so far i'm pretty sure you could figure it out.
Picture

Maya CGFX File:

phongnormaldirectionalmask.cgfx
File Size: 13 kb
File Type: cgfx
Download File

Unity SHADER File:

phongnormaldirectionalmask.shader
File Size: 20 kb
File Type: shader
Download File

0 Comments

CG Shaders - RGB Masking

12/11/2013

0 Comments

 
Here's something to make up for the simplicity of the last shader: RGB masking. This is a technique generally used to blend textures via vertex colors. The advantage is that you can use tileable textures to add detail to the material, but it doesn't look like your textures are tiling. This is really useful for terrain. I've also used texture masks in the past to do basically the same thing. I also heard Unreal 4 uses this scheme to make texture masks for their multi-materials. 

Anyways, i included both texture and vertex masking in these. The Unity shader is set to use textures by default while the Maya version is set to use vertex colors. To change this, just comment out / uncomment the 3rd line (i think) of the pixel shader. You may have to connect the colors to the vertex color attribute in Maya. In the vertex data dropdown of the shader, right click vertex color and choose colorset1. If you are looking for a good vertex painting solution in Unity, i recommend VPaint. Mostly cuz my buddy Beck made it, but its not a bad tool either ;)
Picture

Maya CGFX File:

phongnormalmasked.cgfx
File Size: 13 kb
File Type: cgfx
Download File

Unity SHADER File:

phongnormalmasked.shader
File Size: 17 kb
File Type: shader
Download File

0 Comments

CG Shaders - Emissive Shaders

12/9/2013

0 Comments

 
Didn't feel like working hard today, so i made an emissive shader. Deal with it :P
Picture

Maya CGFX File:

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

Unity SHADER File:

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

0 Comments

CG Shaders - Detail Normals

12/8/2013

0 Comments

 
Here's a trick i get asked about a lot : Detail Normals. Detail Normals are a great way to add resolution to a normal map when viewing it up close. Unreal uses this a lot to add detail to their materials and i actually learned this from back in the old days of tearing apart shader networks in UDK. The best part is you can use a fairly low resolution tilable texture and still get decent results by tiling it inside the material

I included an intensity and falloff modifier for the detail normals. While many shaders like this include an intensity adjustment, i think that a falloff is useful for maintaining the shapes of the base normal map. This allows the detail to be most intense in flat areas of the base normals, where they are most needed. 

This shader is based on the original phong with normals i did earlier
Picture

Maya CGFX File:

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

Unity SHADER File:

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

0 Comments

CG Shaders - Parallax Mapping

12/8/2013

4 Comments

 
I implemented a basic parallax shader to round out the current shaders. It is similar to Unity's Implementation of parallax in CG with an exposed parallax bias. Unity uses a constant bias (of 0.42 from what i hear on the interwebs?) allowing them to only expose 1 value which is easier to understand for some users. I expose it as it allows for a greater range of control and to avoid 'magic' numbers. If you were going to bias with a constant, i would use a higher value to allow more range of control (42 sounds like a good number)

Unfortunately this shader seems to have a bug in maya related to scaling the object. I can correct for this in Unity with * unity_Scale.w, but i am not sure how to extract the object scale in maya just yet. It is possible to work around this by freezing the transforms of the object though. Since you should be freezing your transforms prior to export anyway, and it otherwise works fine...¯\_(ツ)_/¯ Should i find a solution to the scaling issue or a better implementation that works in a different way, i will update the shader to reflect this. At this point i think its a better use of my time to ask for help and move on. 

EDIT: 1-14  - I figured it out. I reversed the matrix and the camera position while converting the camera position to object space and that screwed everything up. Oops.
Picture

Maya CGFX File:

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

Unity SHADER File:

phongnormalparallax.shader
File Size: 14 kb
File Type: shader
Download File

4 Comments

CG Shaders - Pixel Lighting and Normal Maps

12/4/2013

0 Comments

 
This one is a big change compared to the last few shaders i've posted. Because normal maps effect the lighting and they must be read in the pixel shader, pixel lighting is required. This means that nearly all the work previously done must be relocated from the vertex to the pixel shaders. It also is quite a bit more expensive than the previous shaders.

On the plus side, it looks awesome compared to vertex lighting! PIXEL LIGHTING AND NORMAL MAPS OMG.
Picture

Maya CGFX File:

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

Unity Shader File:

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

0 Comments

CG Shaders - Vertex Lit Phong Textured

12/4/2013

0 Comments

 
This simply adds an alpha to the diffuse and uses it to mask the specularity. Not too exciting but it was the last thing i could think of to do lighting wise before i needed to move on to normal maps and pixel based lighting. Please excuse the quickly made brick - I promise i'll make it better with normals :)
Picture

Maya CGFX File:

vertexlitphongtexture.cgfx
File Size: 6 kb
File Type: cgfx
Download File

Unity SHADER File

vertexlitphongtexture.shader
File Size: 7 kb
File Type: shader
Download File

0 Comments

CG Shaders - Vertex Lit Phong

12/3/2013

0 Comments

 
I took 3 point lighting shaders and extended them to build a basic Phong shader. They retain the Rim Light, so you may or may not want to remove it. I like a little Fresnel in my shaders, but its just a personal preference. They are pretty standard shaders otherwise.
Picture

Maya CGFX File:

vertexlitphong.cgfx
File Size: 6 kb
File Type: cgfx
Download File

Unity SHADER File:

vertexlitphong.shader
File Size: 8 kb
File Type: shader
Download File

0 Comments

CG Shaders - Fake Rim Lighting

12/1/2013

0 Comments

 
One of the first things i learned about lighting was the importance of the 3 point lighting system. Movies and Photographers have been using it forever it seems and anything else generally just looks wrong. Games have a unique challenge with this however. We limited in the number of lights we can have and the player is generally free to mess with any character lighting we might do. This leads to a lot of extra work to tweak the lighting. Personally i am far to lazy for that, so i cheated and wrote a shader to do most of the hardest parts of this for me.

This shader takes the key light and creates a complementary fake rim / back  light. It is designed so that no matter where the key light goes, the rim light will follow into a complementary position, saving you the effort of fiddling with a rim light. It is also implemented in the forward pass in Unity, making it a fairly cheap addition to mobile shaders. Its a nice break from the generic shaders i've been writing for this so far :)
Picture

Maya CGFX File:

vertexlitlamberttexturerimlight.cgfx
File Size: 5 kb
File Type: cgfx
Download File

Unity SHADER File

vertexlitlamberttexturerimlight.shader
File Size: 7 kb
File Type: shader
Download File

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
✕