Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Custom/TetronObject"
- {
- Properties
- {
- _Color ("Color", Color) = (1,1,1,1)
- _IndirectIntensity ("Indirect Intensity", float) = 4
- }
- SubShader
- {
- Tags { "RenderType"="Opaque" }
- LOD 80
- Pass
- {
- Tags {"LightMode" = "ForwardBase" "PassFlag" = "OnlyDirectional"}
- Lighting On
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "UnityCG.cginc"
- #include "Lighting.cginc"
- fixed4 _Color;
- float _IndirectIntensity;
- float3 SingleDirectional (float4 vertex, float3 normal)
- {
- // Calculate world normal.
- float3 worldNormal = UnityObjectToWorldNormal(normal);
- // Calculate our light direction normal.
- float3 surfaceToLight = normalize(_WorldSpaceLightPos0.xyz);
- // Calculate dot product between surface and normal.
- float d = dot(worldNormal, surfaceToLight);
- // Calculate intensity for indirect darkness.
- float intensity = sign(d) * abs(pow(d, _IndirectIntensity));
- // Clamp our calculated intensity.
- float nl = clamp(intensity, 0, 1);
- // Calculate diffuse color.
- float3 diffuse = _Color.rgb * _LightColor0.rgb * nl;
- // Return ambient and diffuse color.
- return UNITY_LIGHTMODEL_AMBIENT.xyz + diffuse;
- }
- struct v2f
- {
- fixed4 color : COLOR0;
- float4 pos : SV_POSITION;
- };
- v2f vert (appdata_base v)
- {
- v2f output;
- UNITY_INITIALIZE_OUTPUT(v2f, output);
- output.pos = UnityObjectToClipPos(v.vertex);
- // Calculate our output color for this vertex.
- output.color = float4 (SingleDirectional(v.vertex, v.normal), 1.0);
- return output;
- }
- fixed4 frag (v2f i) : SV_Target
- {
- fixed4 c = i.color;
- return c;
- }
- ENDCG
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement