Advertisement
nitroman123

Untitled

Jul 2nd, 2021
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. // Crest Ocean System
  2.  
  3. // This file is subject to the MIT License as seen in the root of this folder structure (LICENSE)
  4.  
  5. Shader "Crest/Inputs/Flow/Add Flow Map"
  6. {
  7. Properties
  8. {
  9. _FlowMap("Flow Map", 2D) = "white" {}
  10. _Strength( "Strength", float ) = 1
  11. _FlipX("Flip X", Float) = 0
  12. _FlipZ("Flip Z", Float) = 0
  13. }
  14.  
  15. SubShader
  16. {
  17. Tags { "Queue" = "Transparent" }
  18. Blend One One
  19.  
  20. Pass
  21. {
  22. CGPROGRAM
  23. #pragma vertex Vert
  24. #pragma fragment Frag
  25.  
  26. #pragma shader_feature_local _FLIPX_ON
  27. #pragma shader_feature_local _FLIPZ_ON
  28.  
  29. #include "UnityCG.cginc"
  30.  
  31. sampler2D _FlowMap;
  32.  
  33. CBUFFER_START(CrestPerOceanInput)
  34. float4 _FlowMap_ST;
  35. float _Strength;
  36. float3 _DisplacementAtInputPosition;
  37. float _FlipZ;
  38. float _FlipX;
  39. CBUFFER_END
  40.  
  41. struct Attributes
  42. {
  43. float3 positionOS : POSITION;
  44. float2 uv : TEXCOORD0;
  45. };
  46.  
  47. struct Varyings
  48. {
  49. float4 positionCS : SV_POSITION;
  50. float2 uv : TEXCOORD0;
  51. };
  52.  
  53. Varyings Vert(Attributes input)
  54. {
  55. Varyings o;
  56.  
  57. float3 worldPos = mul(unity_ObjectToWorld, float4(input.positionOS, 1.0)).xyz;
  58. // Correct for displacement
  59. worldPos.xz -= _DisplacementAtInputPosition.xz;
  60. o.positionCS = mul(UNITY_MATRIX_VP, float4(worldPos, 1.0));
  61.  
  62. o.uv = TRANSFORM_TEX(input.uv, _FlowMap);
  63. return o;
  64. }
  65.  
  66. float4 Frag(Varyings input) : SV_Target
  67. {
  68. float2 flow = tex2D(_FlowMap, input.uv).xy - 0.5;
  69.  
  70. flow.x *= _FlipX;
  71.  
  72.  
  73. flow.y *= _FlipZ;
  74.  
  75.  
  76. return float4(flow * _Strength, 0.0, 0.0);
  77. }
  78.  
  79. ENDCG
  80. }
  81. }
  82. }
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement