FlatColor.shader 1.3 KB

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