AdditiveFalloff.shader 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. Shader "Immersal/Samples/AdditiveFalloff"
  2. {
  3. Properties
  4. {
  5. _MainTex("Texture", 2D) = "white" {}
  6. _RandomTex("Random Color Texture", 2D) = "white" {}
  7. _TintInner("Incident Angle Color", Color) = (0.0, 0.0, 0.0)
  8. _TintOuter("Grazing Angle Color", Color) = (0.9, 0.1, 0.4)
  9. _Intensity("Intensity", Range(0, 5)) = 1.0
  10. _K("Fresnel k", Range(0, 8)) = 1.35
  11. _Displacement("Displacement Strength", Range(0, 0.1)) = 0.02
  12. }
  13. SubShader
  14. {
  15. Tags
  16. {
  17. "RenderType" = "Transparent"
  18. "Queue" = "Transparent"
  19. "IgnoreProjector" = "True"
  20. }
  21. LOD 100
  22. Lighting Off
  23. Pass
  24. {
  25. Blend One One
  26. Cull Back
  27. ZTest LEqual
  28. ZWrite Off
  29. Offset 0, -1
  30. CGPROGRAM
  31. #pragma target 3.0
  32. #pragma vertex vert
  33. #pragma fragment frag
  34. // make fog work
  35. #pragma multi_compile_fog
  36. #include "UnityCG.cginc"
  37. struct appdata
  38. {
  39. float4 vertex : POSITION;
  40. half3 N : NORMAL;
  41. fixed4 Cd : COLOR;
  42. float2 uv0 : TEXCOORD0;
  43. float2 uv1 : TEXCOORD2;
  44. fixed fresnel : TEXCOORD3;
  45. };
  46. struct v2f
  47. {
  48. float4 vertex : SV_POSITION;
  49. float2 uv0 : TEXCOORD0;
  50. float2 uv1 : TEXCOORD2;
  51. fixed fresnel : TEXCOORD3;
  52. UNITY_FOG_COORDS(1)
  53. };
  54. sampler2D _MainTex;
  55. sampler2D _RandomTex;
  56. float4 _MainTex_ST;
  57. float4 _RandomTex_ST;
  58. fixed4 _TintInner;
  59. fixed4 _TintOuter;
  60. half _Intensity;
  61. half _K;
  62. fixed _Displacement;
  63. fixed Fresnel(float3 worldP, fixed3 N, half k)
  64. {
  65. fixed3 I = normalize(worldP - _WorldSpaceCameraPos);
  66. fixed3 R = reflect(I, N);
  67. fixed3 H = normalize((N + R) * 0.5);
  68. fixed fresnel = pow(1.0 - max(0.0, dot(H, -I)), k);
  69. return fresnel;
  70. }
  71. v2f vert(appdata v)
  72. {
  73. v2f o;
  74. UNITY_INITIALIZE_OUTPUT(v2f, o);
  75. fixed displacement = (sin(_Time.y + v.Cd) + 1) * 0.5 * _Displacement;
  76. o.vertex = UnityObjectToClipPos(v.vertex + v.N * displacement);
  77. //o.vertex = UnityObjectToClipPos(v.vertex);
  78. fixed3 N = UnityObjectToWorldNormal(v.N);
  79. o.uv0 = TRANSFORM_TEX(v.uv0, _MainTex);
  80. o.uv1 = TRANSFORM_TEX(v.uv1, _RandomTex);
  81. UNITY_TRANSFER_FOG(o, o.vertex);
  82. o.fresnel = Fresnel(mul(unity_ObjectToWorld, v.vertex).xyz, N, _K);
  83. return o;
  84. }
  85. fixed4 frag(v2f i) : SV_Target
  86. {
  87. fixed4 random = tex2D(_RandomTex, i.uv1);
  88. fixed4 tex = tex2D(_MainTex, i.uv0);
  89. fixed4 col = lerp(_TintInner, _TintOuter, i.fresnel) * tex * random * _Intensity;
  90. // apply fog
  91. UNITY_APPLY_FOG(i.fogCoord, col);
  92. return col;
  93. }
  94. ENDCG
  95. }
  96. }
  97. FallBack "Diffuse"
  98. }