赞
踩
- Shader "Unlit/WaterDepth"
- {
- Properties
- {
- _MainTex ("Texture", 2D) = "white" {}
- _DepthScale("DepthScale",Range(1,1000)) = 1
- }
- SubShader
- {
- Tags { "Queue"="Transparent" }
-
- Pass
- {
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
-
- #include "UnityCG.cginc"
-
- struct MeshData
- {
- float4 vertex : POSITION;
- float2 uv : TEXCOORD0;
- };
-
- struct Interpolators
- {
- float2 uv : TEXCOORD0;
- float4 posCS : SV_POSITION;
- float3 posVS : TEXCOORD1;
- };
-
- sampler2D _MainTex;
- float4 _MainTex_ST;
- sampler2D _CameraDepthTexture;
- float _DepthScale;
-
- Interpolators vert (MeshData v)
- {
- Interpolators o;
- o.posVS = UnityObjectToViewPos(v.vertex);
- o.posCS = UnityObjectToClipPos(v.vertex);
- o.uv = TRANSFORM_TEX(v.uv, _MainTex);
- return o;
- }
-
- float4 frag (Interpolators i) : SV_Target
- {
- float2 uvScreen = i.posCS.xy / _ScreenParams.xy;
- float depth = tex2D(_CameraDepthTexture,uvScreen) * _DepthScale;
- depth = LinearEyeDepth(depth);
- depth = depth + i.posVS.z;
- return depth;
- }
- ENDCG
- }
- }
- Fallback "Diffuse"
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。