Falloff.shader 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. Shader "Immersal/Samples/Falloff"
  2. {
  3. Properties
  4. {
  5. _TintOuter("Grazing Angle Color", Color) = (0.9, 0.1, 0.4)
  6. _K("Fresnel k", Range(0, 8)) = 1.35
  7. }
  8. SubShader
  9. {
  10. Tags
  11. {
  12. "RenderType" = "Transparent"
  13. "Queue" = "Transparent"
  14. "IgnoreProjector" = "True"
  15. }
  16. LOD 100
  17. Lighting Off
  18. Pass
  19. {
  20. Blend SrcAlpha OneMinusSrcAlpha
  21. Cull Back
  22. ZTest LEqual
  23. ZWrite Off
  24. Offset 0, -1
  25. CGPROGRAM
  26. #pragma target 3.0
  27. #pragma vertex vert
  28. #pragma fragment frag
  29. // make fog work
  30. #pragma multi_compile_fog
  31. #include "UnityCG.cginc"
  32. struct appdata
  33. {
  34. float4 vertex : POSITION;
  35. half3 N : NORMAL;
  36. fixed4 Cd : COLOR;
  37. fixed fresnel : TEXCOORD3;
  38. };
  39. struct v2f
  40. {
  41. float4 vertex : SV_POSITION;
  42. fixed fresnel : TEXCOORD3;
  43. UNITY_FOG_COORDS(1)
  44. };
  45. fixed4 _TintOuter;
  46. half _K;
  47. fixed Fresnel(float3 worldP, fixed3 N, half k)
  48. {
  49. fixed3 I = normalize(worldP - _WorldSpaceCameraPos);
  50. fixed3 R = reflect(I, N);
  51. fixed3 H = normalize((N + R) * 0.5);
  52. fixed fresnel = pow(1.0 - max(0.0, dot(H, -I)), k);
  53. return fresnel;
  54. }
  55. v2f vert(appdata v)
  56. {
  57. v2f o;
  58. UNITY_INITIALIZE_OUTPUT(v2f, o);
  59. o.vertex = UnityObjectToClipPos(v.vertex);
  60. fixed3 N = UnityObjectToWorldNormal(v.N);
  61. UNITY_TRANSFER_FOG(o, o.vertex);
  62. o.fresnel = Fresnel(mul(unity_ObjectToWorld, v.vertex).xyz, N, _K);
  63. return o;
  64. }
  65. fixed4 frag(v2f i) : SV_Target
  66. {
  67. fixed4 transparent = fixed4(0.0, 0.0, 0.0, 0.0);
  68. fixed4 col = lerp(transparent, _TintOuter, i.fresnel);
  69. // apply fog
  70. UNITY_APPLY_FOG(i.fogCoord, col);
  71. return col;
  72. }
  73. ENDCG
  74. }
  75. }
  76. FallBack "Diffuse"
  77. }