|
@@ -34,6 +34,7 @@ Shader "Custom/ParallaxCloud"
|
|
#pragma fragment frag
|
|
#pragma fragment frag
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
|
|
|
+ #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
|
|
|
|
|
|
struct Attributes
|
|
struct Attributes
|
|
{
|
|
{
|
|
@@ -73,7 +74,7 @@ Shader "Custom/ParallaxCloud"
|
|
TEXTURE2D(_ParallaxTex);
|
|
TEXTURE2D(_ParallaxTex);
|
|
SAMPLER(sampler_ParallaxTex);
|
|
SAMPLER(sampler_ParallaxTex);
|
|
|
|
|
|
- sampler2D _CameraDepthTexture;
|
|
|
|
|
|
+ // TEXTURE2D (_CameraDepthTexture);
|
|
// TEXTURE2D(_TurbulenceTex);
|
|
// TEXTURE2D(_TurbulenceTex);
|
|
// SAMPLER(sampler_TurbulenceTex);
|
|
// SAMPLER(sampler_TurbulenceTex);
|
|
|
|
|
|
@@ -116,26 +117,46 @@ Shader "Custom/ParallaxCloud"
|
|
|
|
|
|
half4 frag(Varyings i) : SV_Target
|
|
half4 frag(Varyings i) : SV_Target
|
|
{
|
|
{
|
|
- float2 positionSS = i.positionCS.xy * (_ScreenParams.zw - 1);
|
|
|
|
- float depth = tex2D(_CameraDepthTexture, positionSS).r;
|
|
|
|
- float3 positionNDC = float3(positionSS * 2 - 1, depth);
|
|
|
|
-
|
|
|
|
- #if UNITY_UV_STARTS_AT_TOP
|
|
|
|
- positionNDC.y = -positionNDC.y;
|
|
|
|
- #endif
|
|
|
|
-
|
|
|
|
- #if REQUIRE_POSITION_VS
|
|
|
|
- float4 positionVS = mul(UNITY_MATRIX_I_P, float4(positionNDC, 1));
|
|
|
|
- positionVS /= positionVS.w;
|
|
|
|
- float4 positionWS = mul(UNITY_MATRIX_I_V, positionVS);
|
|
|
|
- #else
|
|
|
|
- float4 positionWS = mul(UNITY_MATRIX_I_VP, float4(positionNDC, 1));
|
|
|
|
- positionWS /= positionWS.w;
|
|
|
|
- #endif
|
|
|
|
- float dist = length(positionWS - i.positionWS);
|
|
|
|
|
|
+ // float2 screenUV = i.screenPos.xy / i.screenPos.w;
|
|
|
|
+ // float depth = SampleSceneDepth(screenUV);
|
|
|
|
+ // float2 positionSS = i.positionCS.xy * (_ScreenParams.zw - 1);
|
|
|
|
+ // // float depth = tex2D(_CameraDepthTexture, positionSS).r;
|
|
|
|
+ // float3 positionNDC = float3(positionSS * 2 - 1, depth);
|
|
|
|
+ //
|
|
|
|
+ // #if UNITY_UV_STARTS_AT_TOP
|
|
|
|
+ // positionNDC.y = -positionNDC.y;
|
|
|
|
+ // #endif
|
|
|
|
+ //
|
|
|
|
+ // #if REQUIRE_POSITION_VS
|
|
|
|
+ // float4 positionVS = mul(UNITY_MATRIX_I_P, float4(positionNDC, 1));
|
|
|
|
+ // positionVS /= positionVS.w;
|
|
|
|
+ // float4 positionWS = mul(UNITY_MATRIX_I_V, positionVS);
|
|
|
|
+ // #else
|
|
|
|
+ // float4 positionWS = mul(UNITY_MATRIX_I_VP, float4(positionNDC, 1));
|
|
|
|
+ // positionWS /= positionWS.w;
|
|
|
|
+ // #endif
|
|
|
|
+ // float dist = length(positionWS - i.positionWS);
|
|
// return half4(dist * 0.1, 0, 0, 1.0);
|
|
// return half4(dist * 0.1, 0, 0, 1.0);
|
|
- dist = dist * 0.2;
|
|
|
|
- dist = clamp(dist, 0, 1);
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ float2 screenUV = i.screenPos.xy / i.screenPos.w;
|
|
|
|
+
|
|
|
|
+ #if UNITY_REVERSED_Z
|
|
|
|
+ float depth = SampleSceneDepth(screenUV);
|
|
|
|
+ #else
|
|
|
|
+ // OpenGL 兼容:调整 Z 到 NDC
|
|
|
|
+ float depth = lerp(UNITY_NEAR_CLIP_VALUE, 1, SampleSceneDepth(screenUV));
|
|
|
|
+ #endif
|
|
|
|
+
|
|
|
|
+ // 重建世界位置(使用 URP 内置函数,更可靠)
|
|
|
|
+ float3 depthWS = ComputeWorldSpacePosition(screenUV, depth, UNITY_MATRIX_I_VP);
|
|
|
|
+
|
|
|
|
+ float dist = length(depthWS - i.positionWS);
|
|
|
|
+ dist = dist * 0.1;
|
|
|
|
+ dist = clamp(dist, 0, 1);
|
|
|
|
+
|
|
|
|
+ // dist = dist * 0.6;
|
|
|
|
+ // dist = clamp(dist, 0, 1);
|
|
|
|
|
|
float ptcpos = length(i.positionWS - _WorldSpaceCameraPos);
|
|
float ptcpos = length(i.positionWS - _WorldSpaceCameraPos);
|
|
ptcpos = 1 - (ptcpos - 0) / _ruiHua;
|
|
ptcpos = 1 - (ptcpos - 0) / _ruiHua;
|