OverheadDepthNormal.shader 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. Shader "Hidden/Funly/Sky Studio/Weather/OverheadDepthNormal"
  2. {
  3. Properties
  4. {
  5. }
  6. SubShader
  7. {
  8. Tags { "RenderType"="Opaque" }
  9. LOD 100
  10. Pass
  11. {
  12. CGPROGRAM
  13. #pragma target 2.0
  14. #pragma vertex vert
  15. #pragma fragment frag
  16. #include "UnityCG.cginc"
  17. struct appdata
  18. {
  19. float4 vertex : POSITION;
  20. float4 normal : NORMAL;
  21. float2 uv : TEXCOORD0;
  22. };
  23. struct v2f
  24. {
  25. float4 vertex : SV_POSITION;
  26. float fragDepth : TEXCOORD1;
  27. float3 worldNormal : TEXCOORD2;
  28. };
  29. v2f vert (appdata v)
  30. {
  31. v2f o;
  32. o.vertex = UnityObjectToClipPos(v.vertex);
  33. o.worldNormal = UnityObjectToWorldNormal(v.normal);
  34. o.fragDepth = o.vertex.z / o.vertex.w;
  35. return o;
  36. }
  37. inline float GetNormalPercent(float value) {
  38. return (value + 1.0f) / 2.0f;
  39. }
  40. float3 GetPercentVector(float3 dir) {
  41. return float3(GetNormalPercent(dir.x), GetNormalPercent(dir.y), GetNormalPercent(dir.z));
  42. }
  43. fixed4 frag (v2f i) : SV_Target
  44. {
  45. float depth = i.fragDepth;
  46. if (UNITY_NEAR_CLIP_VALUE < 0.0f) {
  47. // OpenGL-like platforms are [-1,1] ranged and DirectX-like are [0,1] ranged.
  48. // Convert the -1:1 ranged value to 0:1.
  49. depth = (depth + 1.0f) / 2.0f;
  50. }
  51. #if defined(UNITY_REVERSED_Z)
  52. depth = 1.0f - depth;
  53. #endif
  54. // You can't store negative numbers so convert to a 0:1 values for normal direction.
  55. float3 percentNormal = GetPercentVector(normalize(i.worldNormal));
  56. return fixed4(percentNormal, saturate(depth));
  57. }
  58. ENDCG
  59. }
  60. }
  61. FallBack "Unlit/Color"
  62. }