Search Unity

Vertex Color shader

Discussion in 'Shaders' started by Airship, Jun 20, 2012.

  1. Airship

    Airship

    Joined:
    Sep 10, 2011
    Posts:
    260
    I am pretty basic with shaders. I have edited the vertex color shader on the unify wiki to fake some reflections by using a cubemap masked out by the Main textures alpha.

    What I want to do now is get my shader to be affected by lights. Is this possible: to have a shader using Baked vertex colors to also recieve realtime Unity vertex lights? Basically I want to combine this shader with the standard Unity VertexLit shader. I want specular highlights and realtime vertex lighting in addition to the baked vertex lighting and cubemap reflections.


    I am not sure how to do this. I have been looking at the unity Vertex Shader here :

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

    I think I need to do somethign like add the Material Block but I am not sure how to properly apply it.

    Thanks for any advice/ help

    Code (csharp):
    1. Material {
    2.                 Diffuse [_Color]
    3.                 Ambient [_Color]
    4.                 Shininess [_Shininess]
    5.                 Specular [_SpecColor]
    6.                 Emission [_Emission]
    7.             }
    8.             Lighting On
    9.             SeparateSpecular On
    My edited unify wiki shader.


    Code (csharp):
    1. Shader "MyVertexColors" {
    2. Properties {
    3.     _MainTex ("Texture (A = Reflect)", 2D) = "" {}
    4.    
    5.     _Cube ("Reflection Cubemap", Cube) = "_Skybox" { TexGen CubeReflect }
    6.  
    7. }
    8.  
    9. Category {
    10.     Tags { "Queue"="Geometry" }
    11.    // Lighting Off
    12.     BindChannels {
    13.         Bind "Color", color
    14.         Bind "Vertex", vertex
    15.         Bind "TexCoord", texcoord
    16.     }
    17.    
    18.     SubShader {
    19.         Pass {
    20.        
    21.             SetTexture [_MainTex] {
    22.                 Combine texture * primary DOUBLE      
    23.             }
    24.            
    25.            
    26.                  SetTexture [_Cube] {
    27.                 combine texture * previous alpha + previous//, previous
    28.                
    29.             }
    30.        
    31.         }
    32.     }
    33.    
    34.    
    35. }
    36. }
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Are you referring to this shader? It already does combine baked vertex colors with realtime vertex lights.

    --Eric
     
  3. Airship

    Airship

    Joined:
    Sep 10, 2011
    Posts:
    260
    Thanks, just what I was looking for!