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 - Multiple Lights in a Single Pass

11/27/2013

0 Comments

 
One quick demonstration i wanted to make before moving on is multiple vertex lights in a single pass. Unity provides an array of 4 light positions which can be accessed in the vertex shader. By utilizing these, it is possible to run multiple lighting calculations in the Forward Base pass. However, this is not the most reliable system unfortunately. The 4 lights provided are the 4 closest point lights, so you may notice issues with dynamic lights ("Shadows" or lights behaving oddly when they move/switch order in terms of which light is closest). However the shadow fidelity is comparable to the multipass vertex lit shader, so this might be useful for mobile so you can avoid multiple passes.

I believe these are the lights that Unity considers not "Important" and thus vertex lit. Perhaps someone will be able to find a better use for these in the future.
Picture

Unity SHADER File:

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

0 Comments

CG Shaders - Vertex Lit Multi-Lights

11/27/2013

0 Comments

 
This is a fairly straightforward extension of the previous shader. It adds support for point lights and multiple light sources. Unfortunately we have 2 diverging paths for lighting that makes things difficult to be 100% the same in either program. As far as i know, i can only access the position data in Maya for the point light, and not the falloff or brightness, so i used the light color alpha to determine brightness and added a custom falloff attribute. 

In terms of Unity, lighting is done in multiple passes, generally one per light as far as i can tell. This may be behind some of the draw call woes i've dealt with in the past with Unity...perhaps i should work on lightmap support for these at some point to reduce the draw calls.

In any case, both examples are available for download.
Picture

Maya CGFX File:

vertexlitlamberttexturemultilights.cgfx
File Size: 4 kb
File Type: cgfx
Download File

Unity SHADER File:

vertexlitlamberttexturemultilights.shader
File Size: 6 kb
File Type: shader
Download File

0 Comments

CG Shaders - Vertex Lit Lambert

11/26/2013

2 Comments

 
I decided to start out the lit shaders with a Vertex Lit Lambert Shader, as it was the simplest lighting I could imagine. Technically Pixel Lit shaders aren't any more difficult, but I figured I should cover it before moving on. Vertex Lighting is lower fidelity than Pixel Lighting but they are fast, which means you might want them for mobile. I don't think Maya even has any Vertex Lit shaders these days, so it might be useful for someone working on mobile assets i guess. 

These shaders utilize a single directional light and feature an Ambient Color as well.
Picture

Maya CGFX File:

vertexlitlamberttexture.cgfx
File Size: 3 kb
File Type: cgfx
Download File

Unity SHADER File:

vertexlitlamberttexture.shader
File Size: 3 kb
File Type: shader
Download File

2 Comments

CG Shaders - Double Sided Unlit Transparency 

11/25/2013

3 Comments

 
This is actually a bit trickier than you would think...for Unity at least :/ 

While Maya has backface culling off by default, Unity does not. You would think you could simply turn it off in Unity but this is not the case. I originally thought it was related to disabling the Z Depth but that didn't make it any better. So i decided to settle for the inelegant but functional solution: Render it twice. 

The first pass renders the backfaces and the second draws the front faces over them. If you make a fist and imagine your palm as the backfaces you can probably get a sense of why this works. I only included the Unity shader this time since fixing this in maya is a matter of simply commenting out the culling in the previous shader. 

If anyone has any suggestions for a better way around this please let me know :)

    Unity SHADER File:

unlittexturealphadouble.shader
File Size: 2 kb
File Type: shader
Download File

3 Comments

CG Shaders - Unlit Transparency

11/24/2013

0 Comments

 
Before moving onto lighting, I thought it might be a good time to address Transparency. Transparency is quite simple to achieve and can be used to make our Unlit shaders somewhat useful - We don't want lighting for effects like fire, so an unlit semi-transparent shader would make a nice base for that...more on how to actually make fire later :P

Since the type of Transparency is set via blending Mode, I decided to combine all the potential blending modes (that i know of) into one shader. Maya makes this easy with techniques, but Unity does not support this (that i know of) so instead i commented out the portions all but the most basic method (Alpha Clip). In order to try out the other blending modes just uncomment the relevant mode. I also included a Alpha Power attribute for adjusting the threshold of the Alpha.
Picture

Maya CGFX File:

unlittexturealpha.cgfx
File Size: 3 kb
File Type: cgfx
Download File

Unity SHADER File:

unlittexturealpha.shader
File Size: 2 kb
File Type: shader
Download File

0 Comments

CG Shaders - Unlit Texture

11/23/2013

0 Comments

 
These shaders extend our previous shaders featuring an Unlit Color and add a single texture. I have also removed much of the comments from the previous shader. Going forward, as i extend previous versions of shaders I will be removing old comments and adding new ones to explain new elements. Hopefully this will make it easy to follow along. 
Picture
*UPDATE* I added a demonstration of Scaling/Offsetting UVs via the texture parameter values in both Maya and Unity. These aren't used all that frequently but I figured i should include them for completeness :)

Unity's controls tie directly into the Tile / Offset Parameters of the texture. Maya's controls had to be implemented through a custom parameter in the shader. I'm sure there is some way to access the Repeat UV / Translate Frame parameters in Maya but I don't know how. Sorry :(

Maya CGFX File:

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

Unity SHADER File:

unlittexture.shader
File Size: 1 kb
File Type: shader
Download File

0 Comments

CG Shaders - Basics

11/23/2013

0 Comments

 
These shaders demonstrate the basic syntax and structure of CG shaders in Maya and Unity. The goal is to establish a base pair of shaders that will react in equivalent ways in both Maya and Unity. They are just about the simplest shaders possible, featuring a flat color and no lighting. Both are heavily commented for beginners. While these may seem a bit boring if you have been doing this a while, I've always found its important to start simple and build from there. 
Picture

Maya CGFX File:

unlitcolor.cgfx
File Size: 1 kb
File Type: cgfx
Download File

Unity SHADER File:

unlitcolor.shader
File Size: 1 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 Create your own unique website with customizable templates.