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

Light probes only shader

Discussion in 'Shaders' started by Bravo_cr, Feb 24, 2013.

  1. Bravo_cr

    Bravo_cr

    Joined:
    Jul 19, 2012
    Posts:
    148
    Hi there,

    I just want to share with the community this simple CG shader. It only uses a texture and light probes for illumination. Hope is useful for somebody:


    Code (csharp):
    1. Shader "Unlit/LightProbesOnly" {
    2.     Properties {
    3.         _MainTex ("Base (RGB)", 2D) = "white" {}   
    4.        
    5.     }
    6.    
    7.     Subshader {
    8.         Tags { "RenderType"="Opaque" }
    9.         Fog { Mode Off }
    10.        
    11.         Pass {
    12.             Name "FORWARD"
    13.             Tags { "LightMode" = "ForwardBase" }
    14.            
    15.             CGPROGRAM
    16.                 #pragma vertex vert
    17.                 #pragma fragment frag
    18.                 #pragma fragmentoption ARB_precision_hint_fastest
    19.                 #include "UnityCG.cginc"               
    20.    
    21.  
    22.                 struct v2f {
    23.                     half4   pos : SV_POSITION;
    24.                     half2   uv : TEXCOORD0;
    25.                     fixed3  vlight : TEXCOORD1;
    26.                 };
    27.                
    28.                
    29.                
    30.                 v2f vert (appdata_full v)
    31.                 {
    32.                     v2f o;
    33.                     o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    34.                     o.uv = v.texcoord;
    35.                     half3 worldN = mul((float3x3)_Object2World, SCALED_NORMAL);
    36.                     half3 shlight = ShadeSH9 (float4(worldN,1.0));
    37.                     o.vlight = shlight;
    38.                     return o;
    39.                 }
    40.                
    41.                 sampler2D _MainTex;
    42.                
    43.                 fixed4 frag (v2f i) : COLOR
    44.                 {
    45.                     fixed4 mainTextColor = tex2D(_MainTex,i.uv);
    46.                     fixed4 c;
    47.                     c.rgb = i.vlight;
    48.                     return mainTextColor*c;
    49.                 }
    50.             ENDCG
    51.         }
    52.     }
    53. }
     
    sua060928, blueivy, renewal90 and 3 others like this.