Search Unity

How to make this simple vertex shader receive shadows

Discussion in 'Shaders' started by uk, Aug 11, 2014.

  1. uk

    uk

    Joined:
    Apr 8, 2013
    Posts:
    14
    I got the following shader code:

    Shader " Vertex Colored 2" {
    Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _MainTex ("Base (RGB)", 2D) = "white" {}
    }

    SubShader {
    Pass {
    ColorMaterial AmbientAndDiffuse
    SetTexture [_MainTex] {
    Combine texture * primary, texture * primary
    }
    SetTexture [_MainTex] {
    constantColor [_Color]
    Combine previous * constant DOUBLE, previous * constant
    }
    }
    }

    Fallback " VertexLit", 1
    }​

    Wich does exactly what I want. Except the fact that it does not receive any shadows. I have very little experience with shaders, is there any simple solution too this?
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,620
    Code (csharp):
    1. Fallback " VertexLit", 1
    Remove the space character from " VertexLit". The ", 1" syntax is also to new and I couldn't find any documentation about it.

    I think using this following line should give you shadows back, because the VertexLit shader provides a shadow pass.
    Code (csharp):
    1. Fallback "VertexLit"
     
  3. uk

    uk

    Joined:
    Apr 8, 2013
    Posts:
    14
    I tried the VertexLit shader and it does not recive any shadow, at least not for me.

    Also, I dont think the "Fallback" have anything to do with it. The shader runs fine on my hardware.

    But thanks anyway :)
     
  4. uk

    uk

    Joined:
    Apr 8, 2013
    Posts:
    14
    I found another shader, wich alsmot solved the problem. The problem now is that I dont want the diffuse lightning. Only the shadows, anyone? :)

    Code (CSharp):
    1. Shader "Custom/Vertex Colored Diffuse" {
    2. Properties {
    3.     _Color ("Main Color", Color) = (1,1,1,1)
    4.     _MainTex ("Base (RGB)", 2D) = "white" {}
    5. }
    6. SubShader {
    7.     Tags { "RenderType"="Opaque" }
    8.     LOD 150
    9. CGPROGRAM
    10. #pragma surface surf Lambert vertex:vert
    11. sampler2D _MainTex;
    12. fixed4 _Color;
    13. struct Input {
    14.     float2 uv_MainTex;
    15.     float3 vertColor;
    16. };
    17. void vert (inout appdata_full v, out Input o) {
    18.     UNITY_INITIALIZE_OUTPUT(Input, o);
    19.     o.vertColor = v.color;
    20. }
    21. void surf (Input IN, inout SurfaceOutput o) {
    22.     fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    23.     o.Albedo = c.rgb * IN.vertColor;
    24.     o.Alpha = c.a;
    25. }
    26. ENDCG
    27. }
    28. Fallback "Diffuse"
    29. }