FlatLightColor.shader 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. Shader "Funly/Sky Studio/Flat Shading - Light Color"
  2. {
  3. Properties
  4. {
  5. _Ambient ("Ambient Intensity", Range(0, 5)) = .1
  6. _LightIntensity ("Light Intensity", Range(0, 1)) = .8
  7. }
  8. SubShader
  9. {
  10. Tags { "RenderType"="Opaque" }
  11. LOD 100
  12. Pass
  13. {
  14. CGPROGRAM
  15. #pragma target 2.0
  16. #pragma vertex vert
  17. #pragma fragment frag
  18. #include "UnityCG.cginc"
  19. #include "Lighting.cginc"
  20. struct appdata
  21. {
  22. float4 vertex : POSITION;
  23. };
  24. struct v2f
  25. {
  26. float3 worldPosition: TEXCOORD0;
  27. float4 vertex : SV_POSITION;
  28. };
  29. float _Ambient;
  30. float _LightIntensity;
  31. v2f vert (appdata v)
  32. {
  33. v2f o;
  34. o.vertex = UnityObjectToClipPos(v.vertex);
  35. o.worldPosition = mul(unity_ObjectToWorld, v.vertex);
  36. return o;
  37. }
  38. fixed4 frag (v2f i) : SV_Target
  39. {
  40. float3 fx = ddx(i.worldPosition);
  41. float3 fy = ddy(i.worldPosition);
  42. float3 normal = normalize(cross(fx, fy));
  43. // Unity variable is poorly named, it's actually a direction.
  44. float3 lightDir = _WorldSpaceLightPos0.xyz;
  45. fixed3 finalColor = _Ambient / (UNITY_HALF_PI * 2.0f) *_LightIntensity * _LightColor0.xyz * (1.0f - max(0.0f, dot(normal, lightDir)));
  46. return fixed4(finalColor, 1.);
  47. }
  48. ENDCG
  49. }
  50. }
  51. }