Advertisement
tonynogo

Demo 47 - Diffuse per fragment

Jul 6th, 2017
2,839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/Diffuse per fragment"
  2. {
  3.     Properties
  4.     {
  5.         _MainTex ("Texture", 2D) = "white" {}
  6.     }
  7.  
  8.     SubShader
  9.     {
  10.         Pass {
  11.             Tags { "LightMode" = "ForwardBase" }
  12.  
  13.             CGPROGRAM
  14.                 #pragma vertex vert
  15.                 #pragma fragment frag
  16.                 #include "UnityCG.cginc"
  17.  
  18.                 struct v2f {
  19.                     float4 pos : SV_POSITION;
  20.                     float2 uv : TEXCOORD0;
  21.                     float3 normal : NORMAL;
  22.                 };
  23.  
  24.                 sampler2D _MainTex;
  25.                 float4 _MainTex_ST;
  26.  
  27.                 v2f vert(appdata_full v)
  28.                 {
  29.                     v2f o;
  30.                     o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  31.                     o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
  32.                     o.normal = normalize(mul(v.normal, unity_WorldToObject).xyz);
  33.                    
  34.                     return o;
  35.                 }
  36.  
  37.                 fixed4 _LightColor0;
  38.  
  39.                 fixed4 frag(v2f i) : SV_Target {
  40.                     float dif = max(0.0, dot(i.normal, normalize(_WorldSpaceLightPos0.xyz)));
  41.                     fixed4 col = tex2D(_MainTex, i.uv);
  42.                     return fixed4(col.rgb * dif * _LightColor0.rgb, 1);
  43.                 }
  44.             ENDCG
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement