12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- Shader "Funly/Sky Studio/Flat Shading - Light Color"
- {
- Properties
- {
- _Ambient ("Ambient Intensity", Range(0, 5)) = .1
- _LightIntensity ("Light Intensity", Range(0, 1)) = .8
- }
- SubShader
- {
- Tags { "RenderType"="Opaque" }
- LOD 100
- Pass
- {
- CGPROGRAM
- #pragma target 2.0
- #pragma vertex vert
- #pragma fragment frag
-
- #include "UnityCG.cginc"
- #include "Lighting.cginc"
- struct appdata
- {
- float4 vertex : POSITION;
- };
- struct v2f
- {
- float3 worldPosition: TEXCOORD0;
- float4 vertex : SV_POSITION;
- };
-
- float _Ambient;
- float _LightIntensity;
- v2f vert (appdata v)
- {
- v2f o;
- o.vertex = UnityObjectToClipPos(v.vertex);
- o.worldPosition = mul(unity_ObjectToWorld, v.vertex);
- return o;
- }
-
- fixed4 frag (v2f i) : SV_Target
- {
- float3 fx = ddx(i.worldPosition);
- float3 fy = ddy(i.worldPosition);
- float3 normal = normalize(cross(fx, fy));
- // Unity variable is poorly named, it's actually a direction.
- float3 lightDir = _WorldSpaceLightPos0.xyz;
- fixed3 finalColor = _Ambient / (UNITY_HALF_PI * 2.0f) *_LightIntensity * _LightColor0.xyz * (1.0f - max(0.0f, dot(normal, lightDir)));
- return fixed4(finalColor, 1.);
- }
- ENDCG
- }
- }
- }
|