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

Prevent compounding of multiple spot lights

Discussion in 'Shaders' started by sarah22, Dec 2, 2018.

  1. sarah22

    sarah22

    Joined:
    Aug 6, 2017
    Posts:
    15
    How can I prevent multiple spot lights adding each other and resulting to really bright sprite? I'm really new with shaders so if anyone could also give me a links that could help me get started with lighting in shaders that would be really helpful. Thank you.



    Code (CSharp):
    1. Shader "Sprites/Default with Shadow"
    2. {
    3.     Properties {
    4.         _Color ("Color", Color) = (1,1,1,1)
    5.         [PerRendererData]_MainTex ("Sprite Texture", 2D) = "white" {}
    6.     }
    7.     SubShader {
    8.         Tags
    9.         {
    10.             "Queue" = "Transparent"
    11.             "RenderType" = "Opaque"
    12.         }
    13.         LOD 200
    14.         Cull Off
    15.         ZWrite Off
    16.         ZTest Always
    17.  
    18.         CGPROGRAM
    19.         #pragma surface surf Lambert alpha addshadow fullforwardshadows vertex:vert
    20.         #pragma multi_compile DUMMY PIXELSNAP_ON
    21.         #pragma target 3.0
    22.  
    23.         sampler2D _MainTex;
    24.         fixed4 _Color;
    25.  
    26.         struct Input
    27.         {
    28.             float2 uv_MainTex;
    29.             fixed4 color;
    30.         };
    31.        
    32.         void vert (inout appdata_full v, out Input o)
    33.         {
    34.             UNITY_INITIALIZE_OUTPUT(Input, o);
    35.             o.color = v.color * _Color;
    36.         }
    37.  
    38.         void surf (Input IN, inout SurfaceOutput o) {
    39.             fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * IN.color;
    40.             o.Albedo = c.rgb;
    41.             o.Alpha = c.a;
    42.         }
    43.         ENDCG
    44.     }
    45. }
     

    Attached Files: