Skip to content

Commit c3084bc

Browse files
Esmeralda SalamoneEvergreen
authored andcommitted
[ShaderGraph] make scene depth difference start with positionVS by default
1 parent 17f36a2 commit c3084bc

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

Packages/com.unity.shadergraph/Editor/Data/Nodes/Input/Scene/SceneDepthDifferenceNode.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ protected override MethodInfo GetFunctionToConvert()
5656
static string Unity_SceneDepthDifference_Linear01(
5757
[Slot(0, Binding.None, ShaderStageCapability.Fragment)] out Vector1 Out,
5858
[Slot(1, Binding.ScreenPosition)] Vector2 SceneUV,
59-
[Slot(2, Binding.WorldSpacePosition)] Vector2 PositionWS)
59+
[Slot(2, Binding.ViewSpacePosition)] Vector2 PositionVS)
6060
{
6161
return
6262
@"
6363
{
64-
$precision dist = Remap01(length(PositionWS), _ProjectionParams.y, _ProjectionParams.z);
64+
$precision dist = Remap01(length(PositionVS), _ProjectionParams.y, _ProjectionParams.z);
6565
#if defined(UNITY_REVERSED_Z)
6666
Out = Linear01Depth(SHADERGRAPH_SAMPLE_SCENE_DEPTH(SceneUV.xy), _ZBufferParams) - dist;
6767
#else
@@ -74,12 +74,12 @@ static string Unity_SceneDepthDifference_Linear01(
7474
static string Unity_SceneDepthDifference_Raw(
7575
[Slot(0, Binding.None, ShaderStageCapability.Fragment)] out Vector1 Out,
7676
[Slot(1, Binding.ScreenPosition)] Vector2 SceneUV,
77-
[Slot(2, Binding.WorldSpacePosition)] Vector3 PositionWS)
77+
[Slot(2, Binding.ViewSpacePosition)] Vector3 PositionVS)
7878
{
7979
return
8080
@"
8181
{
82-
$precision deviceDepth = ComputeNormalizedDeviceCoordinatesWithZ(PositionWS, GetWorldToHClipMatrix()).z;
82+
$precision deviceDepth = ComputeNormalizedDeviceCoordinatesWithZ(PositionVS, GetWorldToHClipMatrix()).z;
8383
#if defined(UNITY_REVERSED_Z)
8484
Out = deviceDepth - SHADERGRAPH_SAMPLE_SCENE_DEPTH(SceneUV.xy);
8585
#else
@@ -92,25 +92,25 @@ static string Unity_SceneDepthDifference_Raw(
9292
static string Unity_SceneDepthDifference_Eye(
9393
[Slot(0, Binding.None, ShaderStageCapability.Fragment)] out Vector1 Out,
9494
[Slot(1, Binding.ScreenPosition)] Vector2 SceneUV,
95-
[Slot(2, Binding.WorldSpacePosition)] Vector3 PositionWS)
95+
[Slot(2, Binding.ViewSpacePosition)] Vector3 PositionVS)
9696
{
9797
return
9898
@"
9999
{
100100
if (IsPerspectiveProjection())
101101
{
102102
#if defined(UNITY_REVERSED_Z)
103-
Out = LinearEyeDepth(ComputeWorldSpacePosition(SceneUV.xy, SHADERGRAPH_SAMPLE_SCENE_DEPTH(SceneUV.xy), UNITY_MATRIX_I_VP), UNITY_MATRIX_V) - length(PositionWS);
103+
Out = LinearEyeDepth(ComputeWorldSpacePosition(SceneUV.xy, SHADERGRAPH_SAMPLE_SCENE_DEPTH(SceneUV.xy), UNITY_MATRIX_I_VP), UNITY_MATRIX_V) - length(PositionVS);
104104
#else
105-
Out = length(PositionWS) - LinearEyeDepth(ComputeWorldSpacePosition(SceneUV.xy, SHADERGRAPH_SAMPLE_SCENE_DEPTH(SceneUV.xy), UNITY_MATRIX_I_VP), UNITY_MATRIX_V);
105+
Out = length(PositionVS) - LinearEyeDepth(ComputeWorldSpacePosition(SceneUV.xy, SHADERGRAPH_SAMPLE_SCENE_DEPTH(SceneUV.xy), UNITY_MATRIX_I_VP), UNITY_MATRIX_V);
106106
#endif
107107
}
108108
else
109109
{
110110
#if defined(UNITY_REVERSED_Z)
111-
Out = LinearEyeDepth(SHADERGRAPH_SAMPLE_SCENE_DEPTH(SceneUV.xy), _ZBufferParams) - length(PositionWS);
111+
Out = LinearEyeDepth(SHADERGRAPH_SAMPLE_SCENE_DEPTH(SceneUV.xy), _ZBufferParams) - length(PositionVS);
112112
#else
113-
Out = length(PositionWS) - LinearEyeDepth(SHADERGRAPH_SAMPLE_SCENE_DEPTH(SceneUV.xy), _ZBufferParams);
113+
Out = length(PositionVS) - LinearEyeDepth(SHADERGRAPH_SAMPLE_SCENE_DEPTH(SceneUV.xy), _ZBufferParams);
114114
#endif
115115
}
116116
}
@@ -129,7 +129,7 @@ bool IMayRequireScreenPosition.RequiresScreenPosition(ShaderStageCapability stag
129129

130130
NeededCoordinateSpace IMayRequirePosition.RequiresPosition(ShaderStageCapability stageCapability)
131131
{
132-
return NeededCoordinateSpace.World;
132+
return NeededCoordinateSpace.View;
133133
}
134134
}
135135
}

0 commit comments

Comments
 (0)