Thursday, April 26, 2012

Day 3 (Surface Shaders)

Wohoo, really tired right now but I am committed to completing these 7 days.

Writing Surface Shaders
Surface shaders in Unity is a gcode generation approach that makes it much easier to write shaders using low level vertex/pixel shader programs. The code just generates all the repetitive code that it would have to be written by hand.  (can be written in CG/HLSL)

Here is how it works

1) Define a surface function that takes in any UVs or data you need as input and fills in output structure SurfaceOutput. SurfaceOutput basically describes properties of the surface. (can be written in CG/HLSL) The shaders compiler then figures out what inputs are needed, what outputs are filled, then generates actual vertex&pixel shaders, as well as rendering passes to handle forward and deferrend rendering.

Standard output structure of surface shaders is this:
struct SurfaceOutput
{
     half3 Albedo;
     half3 Albedo;
     half3 Emission;
     half Specular;
     half Gloss;
     half Alpha;
}

Surface shader compile directives should be placed in between
CGPROGRAM
and
ENDCG

For more information reference here Surface Shaders

Wednesday, April 25, 2012

ShaderLab Day(2) (Passes)



Day 2 learning all of this stuff, just as a recap of what I did the yesterday

I have learned about Properties and how they should be implemented.
Syntax
Properties
{
     Available parameters
     Float, Color, Vector, Range, 2D, Cube, and Rect
}
Subshaders are essentially used for rendering and it is required for the graphics card to read all of passes that make the shader what it is.

OKAY so new lesson today..

PASSES
The Pass block causes the geometry of an object to be rendered once.
Syntax:
  • Pass
    {
         [Name and Tags] Reference: Name and PassTags
         [RenderSetup]
         [TextureSetup]
    }
This basic pass command contains an optional list of render setup commands, optionally followed by a list of textures to use

Name and Tags:
A pass can define it's Name and arbitrary number of pass tags - name/value strings that communicate Pass intent to the rendering engine

Render Set up
A pass sets up various states of the graphics hardware, for example
Should alpha blending be turned on?
Should fog be used?
Here are the possible components that can be used:
  • Material { Material Block }
    Defines a material to use in a vertex lighting pipeline. 
    • Materials include:
      • Diffuse Color
        Object's base color
      • Ambient Color
        The ambient color component. This is the color the object has when it's hit by the ambient light set in the RenderSettings!
      • Specular color
        The color of the object's specular highlight
      • Shininess Number
        The sharpness of the highlight, between 0 and 1. At 0 you get a huge highlight that looks a lot like diffuse lighting, at 1 you get a tiny speck.
      • Emission Color
        The color of the object when it is not hit by any light
    • Examples can be found here  Materials
  • Lighting ON | OFF
    Turn vertex lighting on or off. 
    Reference: Materials
  • Cull Back | Font | Off
    Set polygon culling mode.
  • ZTest ( Less | Greater | LEqual | GEqual | Equal | NotEqual | Always)
    Set depth testing mode
  • ZWrite ON | OFF
    Set depth writing mode.
  • Fog { Fog Block}
    Set fog parameters.
  • AlphaTest  ( Less | Greater | LEqual | GEqual | Equal | NotEqual | Always CutoffValue
    Turns on alpha testing.
  • Blend SourceBlendMode DestBlendMode
    Sets alpha blending modes:
    SourceBlendMode
    DestBlendMode
  • Color Color value
    Sets color to use if vertex lighting is turned off
  • ColorMask RGB | A | 0 | any combination of R, G, B, A
    Set color writing mask, Writing ColorMask 0 turns off rendering to all color channels
  • Offset OffsetFactor, Offset Units
    Set depth offset. Note that this command intentionally only accepts constrants
    (Not really sure what this does yet... )
  • SeparateSpecular ON | OFF
    Turns separate specular color for vertex lighting on or off 
  • ColorMaterial AmbiendAndDiffuse | Emission 
Texture Setup
After the render state setup, we want to specify a number of textures and their combining modes to apply using SetTexture commands:

SetTexture 
texture property {[combine options]}
The texture setup configures fixed function multitexturing pipeline, and is ignored if custom fragmend shaders are used. Reference: Custom Fragment Shaders


Details:
Per-pixel Lighting
The per-pixel lighting pipeline works by rendering objects in multiple passes. Unity renders the object once to get ambient and any vertex lights in. Then it renders each pixel lighting affecting object in a separate addictive pass. Reference: Rendering Pilepine



Per-vertex Lighting
Per-vertex lighting is the standard Direct3D/OpenGL lighting model that is computed for each vertex. Lighting On turns it on. Lighting is affected by Material ColorMaterial and SeparateSpecular commands.


There are other variations of passes that are similar to the Pass command but different.


UsePass
The UsePass command uses named passes from another shader.
Syntax
UsePass "Shader/Name"
This inserts all passes with a given name from a given shader. Shader/Name contains the name of the shader and the name of the pass, separated by a slash character


Some of the shaders could reuse existing passes from other shaders, reducing code duplication. For example, in most pixel lit shaders the ambient or vertex lighting passes are the same as in the corresponding VertexLit shaders. The UsePass command includes a given pass from another shader.
Example:
UsePass "Specular/BASE"

Name "MyPassName"


Tuesday, April 24, 2012

ShaderLab: Day 1 (Properties & SubShaders)

For the next 7 days I will be blogging about my ShaderLab findings,

PROPERTIES
Shaders can define a list of parameters to be set by the artists in the material inspector.

Syntax:there are a only few things I need to look out for when setting up properties:
  • When setting up Properties you begin the section with:
    Properties
    {
           Property [Property]
    }
  • Some of the properties that you can include are as follows:
    • name = variable Name that is used in code
    • display name = the name that is showed in the inspector
    • name( "display name", Range (min, max)) = number)
      • example: _WaveScale("Wave scale", Range(0.02, 0.15)) = 0.07
        // sliders default is 0.07
    • name("display name", Color) = (number, number, number, number)
      • example: _RefractionColor("Refraction Color", Color) = (0.34, 0.85, 0.92,1)
        // this is a color, where the last value is the alpha color
    • name("display name", 2D) = "name"{ options }
      • example: _Fresnel{"Fresnel (A)", 2D) = "" { }
    • name("display name", Rect) = "name" {options}
      • example: _ReflectiveRect( "Reflective Rectangle, Rect) = "" { }
    • name("display name", Cube) = "name" {options}
      • example: _CubeMap ("Cube Map", Cube) = "" { }
    • name("display name", Float) = number
      • example: _RippleFrequency( "Ripple Frequency", Float) = 2.0
        //2 is the default value
    • name("display name", Vector) = (number, number, number, number)
      • example: _InfluenceVector("Influence Vector", Vector) = (0.2,0.0,0.0,1.0)
    • *Special Note: in the options field -> { options } here are the available options
      • TexGen texgenmode -> Automatic texture coordinate generation mode
        for the texture. TexGen is ignored if custom vertex programs are used.
      • LightmapMode -> Texture will be affected by pre-renderer lightmap parameters.
        That is, the texture to use can be not  in the material, but taken from the settings of the Renderer instead.
SUBSHADERS

Each shader in Unity consists of a list of subshaders. When Unity has to display a mesh it will find the shader to use and pick the first subshader that runs on the user's graphics card.

Syntax:
  • SubShader
    {
         [Tags] [CommonState] Passdef [Passdef.. ]}
         //defines the subshader as optional tags, common state and a list of pass definitions
    }
A subshader defines a list of rendering passes and optionally setup any state that is common to all passes. Additionally, subshader specific Tags can be set up. All tags can be found here: TAGS. When Unity chooses which subshader to render with it renders the object once for each Pass defined. As each render of the object is an expensive operation. The shader must be defined in the least number of passes possible. Sometimes on some graphics hardware the needed effect can't be done in a single pass.

On my journey to graduation I need to compete the following:

Create a Water Shader that utilizes Caustics, Fresnel, and Refraction
Create a Motion Blur environment
Create an all purpose shader
Finish a few rigs

I am almost there... :)
Here are a few references that will get me to my goals
Overall ShaderLab syntax
http://unity3d.com/support/documentation/Components/SL-Reference.html

ShaderLab: Pass
http://unity3d.com/support/documentation/Components/SL-Pass.html

ShaderLab: UsePass
http://unity3d.com/support/documentation/Components/SL-UsePass.html

ShaderLab: Grab Pass
http://unity3d.com/support/documentation/Components/SL-GrabPass.html

ShaderLab: Writing Surface Shaders
http://unity3d.com/support/documentation/Components/SL-SurfaceShaders.html

ShaderLab: Writing Vertex and Fragment Shaders
http://unity3d.com/support/documentation/Components/SL-ShaderPrograms.html

ShaderLab: Advanced ShaderLab Topics
http://unity3d.com/support/documentation/Components/SL-AdvancedTopics.html

Wish Me Luck :)

Friday, April 13, 2012

Now I can work on multiple computers with ease

http://synergy-foss.org/
This program allows you to share a keyboard and mouse on multiple computers. AWESOME!!

Thursday, April 12, 2012

Don't have to pull overtime tonight!








Finally I get a night to myself, tonight is going to be the night where I play some Street Fighter X Tekken. Or Should I work on my demo reel... decisions decisions.

This is how I feel right now...

Wednesday, April 11, 2012

So.. Tired...

I am soo tired. And I thought last quarter was hard balancing 6 classes and a few small jobs. This quarter tops it off with my full time job + 4 classes + being a peer mentor. GRRR I don't know what to do, and it's week 2. I think I'll be fine. I just need to focus and relax a bit, so that is why even though it is going to be 10:43 I will be playing at least 1 game of League Of Legends.. SO ha beat that.

Btw before I forget, this is a useful link for getting a list of possible attributes that you can access at any time.
http://www.cgsutra.com/autodesk_maya_tutorials/mel/chapter_07/ch07_mel_attributes.php

Sunday, April 1, 2012

AUTO RIG (REDESIGNED)

So I have spend most of my weekend thinking about the things that I should do for my portfolio and my auto rig came into mind.
The progress that I have made to it is essentiall
  • Dolling it up with colors and buttons.
  • I made it so that based on a naming convention you can add or remove components
  • I also have it so that you can either use the location based system or have joints aready within the scene.
  • Lastly i am working out the error that i had with my IK FK Matching
Hoping to get the arms and the legs done by the end of the week. :)