Advertisement
tonynogo

Demo 58 - Lambert diffuse per vertex

Jul 6th, 2017
2,348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/Lighting/VertexLambertDiffuse"
  2. {
  3.     Properties
  4.     {
  5.         _Color ("Color", Color) = (1.0, 1.0, 1.0, 1.0)
  6.         _Diffuse ("Diffuse value", Range(0, 1)) = 1.0
  7.     }
  8.     SubShader
  9.     {
  10.         Tags { "LightMode"="ForwardBase" }
  11.  
  12.         Pass
  13.         {
  14.             CGPROGRAM
  15.             #pragma vertex vert
  16.             #pragma fragment frag
  17.             #include "UnityCG.cginc"
  18.  
  19.             struct appdata {
  20.                 float4 vertex : POSITION;
  21.                 float3 normal : NORMAL;
  22.             };
  23.  
  24.             struct v2f {
  25.                 float4 pos : SV_POSITION;
  26.                 fixed4 col : COLOR0;
  27.             };
  28.  
  29.             fixed4 _Color;
  30.             fixed4 _LightColor0;
  31.             float _Diffuse;
  32.  
  33.             v2f vert(appdata v) {
  34.                 v2f o;
  35.                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  36.                 float3 worldNormal = normalize(mul(v.normal, (float3x3)unity_WorldToObject));
  37.                 float3 lightDir = normalize(_WorldSpaceLightPos0.xyz);
  38.                 float NdotL = max(0.0, dot(worldNormal, lightDir));
  39.                 fixed4 diff = _Color * NdotL * _LightColor0 * _Diffuse;
  40.                 o.col = diff;
  41.                 return o;
  42.             }
  43.  
  44.             float4 frag(v2f i) : SV_Target {
  45.                 return i.col;
  46.             }
  47.  
  48.             ENDCG
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement