-
Notifications
You must be signed in to change notification settings - Fork 869
Expand file tree
/
Copy pathSurfaceGradientResolveNormal.cs
More file actions
60 lines (49 loc) · 2.3 KB
/
SurfaceGradientResolveNormal.cs
File metadata and controls
60 lines (49 loc) · 2.3 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
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
{
[Title("Utility", "High Definition Render Pipeline", "Surface Gradient", "SurfaceGradientResolveNormal")]
class SurfaceGradientResolveNormal : AbstractMaterialNode, IGeneratesBodyCode
{
public SurfaceGradientResolveNormal()
{
name = "Surface Gradient Resolve Normal";
UpdateNodeAfterDeserialization();
}
const int kNormalInputSlotId = 0;
const string kNormalInputSlotName = "Normal";
const int kSurfaceGradientInputSlotId = 1;
const string kSurfaceGradientInputSlotName = "SurfaceGradient";
const int kNormalOutputSlotId = 2;
const string kNormalOutputSlotName = "NormalOutput";
public override bool hasPreview { get { return false; } }
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector3MaterialSlot(kNormalInputSlotId, kNormalInputSlotName, kNormalInputSlotName, SlotType.Input, Vector3.zero, ShaderStageCapability.All));
AddSlot(new Vector3MaterialSlot(kSurfaceGradientInputSlotId, kSurfaceGradientInputSlotName, kSurfaceGradientInputSlotName, SlotType.Input, Vector3.zero, ShaderStageCapability.All));
AddSlot(new Vector3MaterialSlot(kNormalOutputSlotId, kNormalOutputSlotName, kNormalOutputSlotName, SlotType.Output, Vector3.zero));
RemoveSlotsNameNotMatching(new[]
{
kNormalInputSlotId,
kSurfaceGradientInputSlotId,
kNormalOutputSlotId,
});
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
string normal = GetSlotValue(kNormalInputSlotId, generationMode);
string surfaceGradient = GetSlotValue(kSurfaceGradientInputSlotId, generationMode);
sb.AppendLine("$precision3 {0} = SafeNormalize({1} - {2});",
GetVariableNameForSlot(kNormalOutputSlotId),
normal,
surfaceGradient
);
}
}
}