-
Notifications
You must be signed in to change notification settings - Fork 773
/
SceneDepthNode.cs
113 lines (99 loc) · 3.18 KB
/
SceneDepthNode.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System.Reflection;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
namespace UnityEditor.ShaderGraph
{
enum DepthSamplingMode
{
Linear01,
Raw,
Eye
};
[Title("Input", "Scene", "Scene Depth")]
sealed class SceneDepthNode : CodeFunctionNode, IMayRequireDepthTexture
{
const string kScreenPositionSlotName = "UV";
const string kOutputSlotName = "Out";
public const int ScreenPositionSlotId = 0;
public const int OutputSlotId = 1;
[SerializeField]
private DepthSamplingMode m_DepthSamplingMode = DepthSamplingMode.Linear01;
[EnumControl("Sampling Mode")]
public DepthSamplingMode depthSamplingMode
{
get { return m_DepthSamplingMode; }
set
{
if (m_DepthSamplingMode == value)
return;
m_DepthSamplingMode = value;
Dirty(ModificationScope.Graph);
}
}
public SceneDepthNode()
{
name = "Scene Depth";
synonyms = new string[] { "zbuffer", "zdepth" };
UpdateNodeAfterDeserialization();
}
public override bool hasPreview { get { return false; } }
protected override MethodInfo GetFunctionToConvert()
{
switch (m_DepthSamplingMode)
{
case DepthSamplingMode.Raw:
return GetType().GetMethod("Unity_SceneDepth_Raw", BindingFlags.Static | BindingFlags.NonPublic);
case DepthSamplingMode.Eye:
return GetType().GetMethod("Unity_SceneDepth_Eye", BindingFlags.Static | BindingFlags.NonPublic);
case DepthSamplingMode.Linear01:
default:
return GetType().GetMethod("Unity_SceneDepth_Linear01", BindingFlags.Static | BindingFlags.NonPublic);
}
}
static string Unity_SceneDepth_Linear01(
[Slot(0, Binding.ScreenPosition)] Vector4 UV,
[Slot(1, Binding.None, ShaderStageCapability.Fragment)] out Vector1 Out)
{
return
@"
{
Out = Linear01Depth(SHADERGRAPH_SAMPLE_SCENE_DEPTH(UV.xy), _ZBufferParams);
}
";
}
static string Unity_SceneDepth_Raw(
[Slot(0, Binding.ScreenPosition)] Vector4 UV,
[Slot(1, Binding.None, ShaderStageCapability.Fragment)] out Vector1 Out)
{
return
@"
{
Out = SHADERGRAPH_SAMPLE_SCENE_DEPTH(UV.xy);
}
";
}
static string Unity_SceneDepth_Eye(
[Slot(0, Binding.ScreenPosition)] Vector4 UV,
[Slot(1, Binding.None, ShaderStageCapability.Fragment)] out Vector1 Out)
{
return
@"
{
if (unity_OrthoParams.w == 1.0)
{
Out = LinearEyeDepth(ComputeWorldSpacePosition(UV.xy, SHADERGRAPH_SAMPLE_SCENE_DEPTH(UV.xy), UNITY_MATRIX_I_VP), UNITY_MATRIX_V);
}
else
{
Out = LinearEyeDepth(SHADERGRAPH_SAMPLE_SCENE_DEPTH(UV.xy), _ZBufferParams);
}
}
";
}
public bool RequiresDepthTexture(ShaderStageCapability stageCapability)
{
return true;
}
}
}