Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Solid color with shadows

Discussion in 'Shaders' started by e_tip, Feb 27, 2015.

  1. e_tip

    e_tip

    Joined:
    Jan 27, 2014
    Posts:
    18
    Hi all,
    i'm approching unity development, so sorry if my question is so noob.
    I'm looking for a simple shader that have a solid color as option.
    I'm actually using this
    Shader"SolidColor" {
    Properties { _Color ("Color", Color) = (1,1,1) }
    SubShader { Color [_Color] Pass {} }
    }​
    But this have a little problem... it doesn't receive shadows. Does anyone have a link to a simple shader ( it will run on mobile platform so lighter is better) like the color one but that receive shadows ?
    Many thanks
     
  2. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    This might be as lightweight as you get.

    Code (csharp):
    1. Shader "SolidColor" {
    2.     Properties {
    3.         _Color ("Main Color", Color) = (1,1,1,1)
    4.     }
    5.     SubShader {
    6.         Tags {"Queue" = "Geometry" "RenderType" = "Opaque"}
    7.  
    8.         Pass {
    9.             Tags {"LightMode" = "ForwardBase"}
    10.             CGPROGRAM
    11.                 #pragma vertex vert
    12.                 #pragma fragment frag
    13.                 #pragma multi_compile_fwdbase
    14.                 #pragma fragmentoption ARB_precision_hint_fastest
    15.                
    16.                 #include "UnityCG.cginc"
    17.                 #include "AutoLight.cginc"
    18.                
    19.                 struct appdata_pos {
    20.                     float4 vertex : POSITION;
    21.                 };
    22.  
    23.                 struct v2f
    24.                 {
    25.                     float4    pos            : SV_POSITION;
    26.                     LIGHTING_COORDS    (0,1)
    27.                 };
    28.  
    29.                 v2f vert (appdata_pos v)
    30.                 {
    31.                     v2f o;
    32.                     o.pos = mul( UNITY_MATRIX_MVP, v.vertex);
    33.                     TRANSFER_VERTEX_TO_FRAGMENT(o);
    34.                     return o;
    35.                 }
    36.  
    37.                 fixed4 _Color;
    38.                 fixed4 frag(v2f i) : COLOR
    39.                 {
    40.                     return _Color * LIGHT_ATTENUATION(i);
    41.                 }
    42.             ENDCG
    43.         }
    44.     }
    45.     FallBack "VertexLit"    // Use VertexLit's shadow caster/reciever passes.
    46. }
     
  3. e_tip

    e_tip

    Joined:
    Jan 27, 2014
    Posts:
    18
    Great! thank you very much.