Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/TetronObject"
  2. {
  3.     Properties
  4.     {
  5.         _Color ("Color", Color) = (1,1,1,1)
  6.         _IndirectIntensity ("Indirect Intensity", float) = 4
  7.     }
  8.     SubShader
  9.     {
  10.         Tags { "RenderType"="Opaque" }
  11.         LOD 80
  12.  
  13.         Pass
  14.         {
  15.             Tags {"LightMode" = "ForwardBase" "PassFlag" = "OnlyDirectional"}
  16.             Lighting On
  17.  
  18.             CGPROGRAM
  19.             #pragma vertex vert
  20.             #pragma fragment frag
  21.             #include "UnityCG.cginc"
  22.             #include "Lighting.cginc"
  23.  
  24.             fixed4 _Color;
  25.             float _IndirectIntensity;
  26.  
  27.             float3 SingleDirectional (float4 vertex, float3 normal)
  28.             {
  29.                 // Calculate world normal.
  30.                 float3 worldNormal = UnityObjectToWorldNormal(normal);
  31.  
  32.                 // Calculate our light direction normal.
  33.                 float3 surfaceToLight = normalize(_WorldSpaceLightPos0.xyz);
  34.  
  35.                 // Calculate dot product between surface and normal.
  36.                 float d = dot(worldNormal, surfaceToLight);
  37.  
  38.                 // Calculate intensity for indirect darkness.
  39.                 float intensity = sign(d) * abs(pow(d, _IndirectIntensity));
  40.  
  41.                 // Clamp our calculated intensity.
  42.                 float nl = clamp(intensity, 0, 1);
  43.                
  44.                 // Calculate diffuse color.
  45.                 float3 diffuse = _Color.rgb * _LightColor0.rgb * nl;
  46.  
  47.                 // Return ambient and diffuse color.
  48.                 return  UNITY_LIGHTMODEL_AMBIENT.xyz + diffuse;
  49.             }
  50.  
  51.             struct v2f
  52.             {
  53.                 fixed4 color : COLOR0;
  54.                 float4 pos : SV_POSITION;
  55.             };
  56.  
  57.             v2f vert (appdata_base v)
  58.             {
  59.                 v2f output;
  60.                 UNITY_INITIALIZE_OUTPUT(v2f, output);
  61.  
  62.                 output.pos = UnityObjectToClipPos(v.vertex);
  63.  
  64.                 // Calculate our output color for this vertex.
  65.                 output.color = float4 (SingleDirectional(v.vertex, v.normal), 1.0);
  66.  
  67.                 return output;
  68.             }
  69.  
  70.             fixed4 frag (v2f i) : SV_Target
  71.             {
  72.                 fixed4 c = i.color;
  73.                 return c;
  74.             }
  75.             ENDCG
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement