HeightmapBlitShader.shader 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. Shader "Hidden/ZibraEffects/Liquid/HeightmapBlit"
  2. {
  3. Properties
  4. {
  5. _MainTex("Texture", any) = "" {}
  6. }
  7. SubShader
  8. {
  9. Pass
  10. {
  11. ZTest Always
  12. Cull Off
  13. ZWrite Off
  14. CGPROGRAM
  15. #pragma vertex vert
  16. #pragma fragment frag
  17. #include "UnityCG.cginc"
  18. UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
  19. uniform float4 _MainTex_ST;
  20. uniform float4 _HeightmapScaling;
  21. uniform int _ComponentToBlit;
  22. struct appdata_t
  23. {
  24. float4 vertex : POSITION;
  25. float2 texcoord : TEXCOORD0;
  26. };
  27. struct v2f
  28. {
  29. float4 vertex : SV_POSITION;
  30. float2 texcoord : TEXCOORD0;
  31. };
  32. v2f vert(appdata_t v)
  33. {
  34. v2f o;
  35. o.vertex = UnityObjectToClipPos(v.vertex);
  36. o.texcoord = TRANSFORM_TEX(v.texcoord.xy, _MainTex);
  37. float2 screenPos = o.vertex.xy / o.vertex.w;
  38. o.vertex.xy = ((screenPos + 1.0 + 2.0*float2( _HeightmapScaling.x, _HeightmapScaling.w - 1 - _HeightmapScaling.y)) / _HeightmapScaling.zw - 1.0) * o.vertex.w;
  39. return o;
  40. }
  41. fixed4 frag(v2f i): SV_Target
  42. {
  43. return UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, i.texcoord)[_ComponentToBlit];
  44. }
  45. ENDCG
  46. }
  47. }
  48. Fallback Off
  49. }