Turbulence2D.shader 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. Shader "Hidden/VolumetricFog2/Turbulence2D"
  2. {
  3. Properties {
  4. _MainTex ("Noise", 2D) = "white" {}
  5. _TurbulenceAmount ("Turbulence Amount", Float) = 0.5
  6. }
  7. SubShader {
  8. CGINCLUDE
  9. #include "UnityCG.cginc"
  10. struct appdata {
  11. float4 vertex : POSITION;
  12. float2 texcoord : TEXCOORD0;
  13. };
  14. struct v2f {
  15. float4 pos : SV_POSITION;
  16. float4 uv: TEXCOORD0;
  17. };
  18. sampler2D_float _MainTex;
  19. float _TurbulenceAmount;
  20. float _NoiseStrength, _NoiseFinalMultiplier;
  21. v2f vert(appdata v) {
  22. v2f o;
  23. o.pos = UnityObjectToClipPos(v.vertex);
  24. o.uv = float4(v.texcoord, 0, 0);
  25. return o;
  26. }
  27. float4 frag(v2f i): SV_Target {
  28. float sint, cost;
  29. sincos(_TurbulenceAmount, sint, cost);
  30. float4 p0 = tex2Dlod(_MainTex, i.uv);
  31. float4 p1 = tex2Dlod(_MainTex, i.uv + float4(0.25,0.25,0,0));
  32. float t0 = sint * 0.5 + 0.5;
  33. float4 r0 = lerp(p0, p1, t0);
  34. float4 p2 = tex2Dlod(_MainTex, i.uv + float4(0.5,0.5,0,0));
  35. float4 p3 = tex2Dlod(_MainTex, i.uv + float4(0.75,0.75,0,0));
  36. float t1 = cost * 0.5 + 0.5;
  37. float4 r1 = lerp(p2, p3, t1);
  38. float n = 1.0 - max(r0, r1);
  39. n = saturate( (1.0 - n * _NoiseStrength) * _NoiseFinalMultiplier);
  40. return n;
  41. }
  42. ENDCG
  43. Pass {
  44. ZTest Always Cull Off ZWrite Off
  45. CGPROGRAM
  46. #pragma target 3.0
  47. #pragma fragmentoption ARB_precision_hint_fastest
  48. #pragma vertex vert
  49. #pragma fragment frag
  50. ENDCG
  51. }
  52. }
  53. Fallback Off
  54. }