当前位置:   article > 正文

[Shader]水面深度计算_water shader

water shader
  1. Shader "Unlit/WaterDepth"
  2. {
  3. Properties
  4. {
  5. _MainTex ("Texture", 2D) = "white" {}
  6. _DepthScale("DepthScale",Range(1,1000)) = 1
  7. }
  8. SubShader
  9. {
  10. Tags { "Queue"="Transparent" }
  11. Pass
  12. {
  13. CGPROGRAM
  14. #pragma vertex vert
  15. #pragma fragment frag
  16. #include "UnityCG.cginc"
  17. struct MeshData
  18. {
  19. float4 vertex : POSITION;
  20. float2 uv : TEXCOORD0;
  21. };
  22. struct Interpolators
  23. {
  24. float2 uv : TEXCOORD0;
  25. float4 posCS : SV_POSITION;
  26. float3 posVS : TEXCOORD1;
  27. };
  28. sampler2D _MainTex;
  29. float4 _MainTex_ST;
  30. sampler2D _CameraDepthTexture;
  31. float _DepthScale;
  32. Interpolators vert (MeshData v)
  33. {
  34. Interpolators o;
  35. o.posVS = UnityObjectToViewPos(v.vertex);
  36. o.posCS = UnityObjectToClipPos(v.vertex);
  37. o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  38. return o;
  39. }
  40. float4 frag (Interpolators i) : SV_Target
  41. {
  42. float2 uvScreen = i.posCS.xy / _ScreenParams.xy;
  43. float depth = tex2D(_CameraDepthTexture,uvScreen) * _DepthScale;
  44. depth = LinearEyeDepth(depth);
  45. depth = depth + i.posVS.z;
  46. return depth;
  47. }
  48. ENDCG
  49. }
  50. }
  51. Fallback "Diffuse"
  52. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/108459
推荐阅读
相关标签
  

闽ICP备14008679号