Search Unity

Diffuse texture with vertex colors?

Discussion in 'Shaders' started by yoonitee, Jul 24, 2014.

  1. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,363
    OK, this has been asked before but in the answers the links are always broken!

    I'm trying to find a simple shader that is more or less the default diffuse shader with texture but tinted with vertex colors. (Actually I mainly need it to darken at some vertices but tinting would do).
     
  2. TechnicalArtist

    TechnicalArtist

    Joined:
    Jul 9, 2012
    Posts:
    736
  3. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,363
    Thanks, but I nearly have it:
    Code (CSharp):
    1. Shader "Custom/CubeShader" {
    2.     Properties {
    3.         _MainTex ("Base (RGB)", 2D) = "white" {}
    4.     }
    5.     SubShader {
    6.         Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
    7.         //Tags { "RenderType" = "Opaque" }
    8.         LOD 300
    9.      
    10.         CGPROGRAM
    11.         #pragma surface surf Lambert alpha
    12.      
    13.         sampler2D _MainTex;
    14.         struct Input {
    15.             float2 uv_MainTex;
    16.             float4 color: Color; // Vertex color
    17.         };
    18.         void surf (Input IN, inout SurfaceOutput o) {
    19.             half4 c = tex2D (_MainTex, IN.uv_MainTex);
    20.             o.Albedo = c.rgb * IN.color.rgb; // vertex RGB
    21.             o.Alpha = c.a * IN.color.a; // vertex Alpha
    22.         }
    23.         ENDCG
    24.     }
    25.     FallBack "Diffuse"
    26. }
    Except that I don't want it transparent. Since the objects keep hiding behind transparent objects.
     
    zigannkevin likes this.
  4. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,363
    No worries I've found it:

    Code (CSharp):
    1. Shader "Custom/CubeShader" {
    2.     Properties {
    3.         _MainTex ("Base (RGB)", 2D) = "white" {}
    4.     }
    5.     SubShader {
    6.         Tags { "RenderType"="Opaque" }
    7.         LOD 200
    8.    
    9.     CGPROGRAM
    10.     #pragma surface surf Lambert
    11.  
    12.         sampler2D _MainTex;
    13.         struct Input {
    14.             float2 uv_MainTex;
    15.             float4 color: Color; // Vertex color
    16.         };
    17.         void surf (Input IN, inout SurfaceOutput o) {
    18.             half4 c = tex2D (_MainTex, IN.uv_MainTex);
    19.             o.Albedo = c.rgb * IN.color.rgb; // vertex RGB
    20.             o.Alpha = c.a * IN.color.a; // vertex Alpha
    21.         }
    22.         ENDCG
    23.     }
    24.     FallBack "Diffuse"
    25. }