-
Notifications
You must be signed in to change notification settings - Fork 869
Expand file tree
/
Copy pathCustomPassNodes.cs
More file actions
137 lines (109 loc) · 5.63 KB
/
CustomPassNodes.cs
File metadata and controls
137 lines (109 loc) · 5.63 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using System.Collections.Generic;
using System;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEditor.ShaderGraph.Internal;
using UnityEngine.Rendering.HighDefinition;
namespace UnityEditor.Rendering.HighDefinition
{
[SRPFilter(typeof(HDRenderPipeline))]
[Title("Input", "High Definition Render Pipeline", "Custom Color Buffer")]
class CustomColorBufferNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireScreenPosition, IMayRequireNDCPosition, IMayRequirePixelPosition
{
public CustomColorBufferNode()
{
name = "Custom Color Buffer";
UpdateNodeAfterDeserialization();
}
const int kUvInputSlotId = 0;
const string kUvInputSlotName = "UV";
const int kColorOutputSlotId = 1;
const string kColorOutputSlotName = "Output";
public override bool hasPreview => false;
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new ScreenPositionMaterialSlot(kUvInputSlotId, kUvInputSlotName, kUvInputSlotName, ScreenSpaceType.Default));
AddSlot(new Vector4MaterialSlot(kColorOutputSlotId, kColorOutputSlotName, kColorOutputSlotName, SlotType.Output, Vector4.zero));
RemoveSlotsNameNotMatching(new[]
{
kUvInputSlotId,
kColorOutputSlotId,
});
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
string uv = GetSlotValue(kUvInputSlotId, generationMode);
if (generationMode.IsPreview())
sb.AppendLine($"$precision4 {GetVariableNameForSlot(kColorOutputSlotId)} = 1;");
else
sb.AppendLine($"$precision4 {GetVariableNameForSlot(kColorOutputSlotId)} = SampleCustomColor({uv}.xy);");
}
public bool RequiresScreenPosition(ShaderStageCapability stageCapability = ShaderStageCapability.All) =>
FindSlot<MaterialSlot>(kUvInputSlotId)?.RequiresScreenPosition(stageCapability) ?? false;
public bool RequiresNDCPosition(ShaderStageCapability stageCapability = ShaderStageCapability.All) =>
FindSlot<MaterialSlot>(kUvInputSlotId)?.RequiresNDCPosition(stageCapability) ?? false;
public bool RequiresPixelPosition(ShaderStageCapability stageCapability = ShaderStageCapability.All) =>
FindSlot<MaterialSlot>(kUvInputSlotId)?.RequiresPixelPosition(stageCapability) ?? false;
}
[SRPFilter(typeof(HDRenderPipeline))]
[Title("Input", "High Definition Render Pipeline", "Custom Depth Buffer")]
class CustomDepthBufferNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireScreenPosition, IMayRequireNDCPosition, IMayRequirePixelPosition
{
public CustomDepthBufferNode()
{
name = "Custom Depth Buffer";
UpdateNodeAfterDeserialization();
}
[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 override string documentationURL => NodeUtils.GetDocumentationString("HD-Custom-Depth");
const int kUvInputSlotId = 0;
const string kUvInputSlotName = "UV";
const int kDepthOutputSlotId = 1;
const string kDepthOutputSlotName = "Output";
public override bool hasPreview => false;
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new ScreenPositionMaterialSlot(kUvInputSlotId, kUvInputSlotName, kUvInputSlotName, ScreenSpaceType.Default));
AddSlot(new Vector1MaterialSlot(kDepthOutputSlotId, kDepthOutputSlotName, kDepthOutputSlotName, SlotType.Output, 0));
RemoveSlotsNameNotMatching(new[]
{
kUvInputSlotId,
kDepthOutputSlotId,
});
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
string uv = GetSlotValue(kUvInputSlotId, generationMode);
string depthValue = $"SampleCustomDepth({uv}.xy)";
if (depthSamplingMode == DepthSamplingMode.Eye)
depthValue = $"LinearEyeDepth({depthValue}, _ZBufferParams)";
if (depthSamplingMode == DepthSamplingMode.Linear01)
depthValue = $"Linear01Depth({depthValue}, _ZBufferParams)";
if (generationMode.IsPreview())
sb.AppendLine($"$precision {GetVariableNameForSlot(kDepthOutputSlotId)} = 0;");
else
sb.AppendLine($"$precision {GetVariableNameForSlot(kDepthOutputSlotId)} = {depthValue};");
}
public bool RequiresScreenPosition(ShaderStageCapability stageCapability = ShaderStageCapability.All) =>
FindSlot<MaterialSlot>(kUvInputSlotId)?.RequiresScreenPosition(stageCapability) ?? false;
public bool RequiresNDCPosition(ShaderStageCapability stageCapability = ShaderStageCapability.All) =>
FindSlot<MaterialSlot>(kUvInputSlotId)?.RequiresNDCPosition(stageCapability) ?? false;
public bool RequiresPixelPosition(ShaderStageCapability stageCapability = ShaderStageCapability.All) =>
FindSlot<MaterialSlot>(kUvInputSlotId)?.RequiresPixelPosition(stageCapability) ?? false;
}
}