-
Notifications
You must be signed in to change notification settings - Fork 4
/
IndirectNodeHD.cs
69 lines (56 loc) · 2.14 KB
/
IndirectNodeHD.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
using System.Reflection;
using UnityEditor.ShaderGraph;
[Title("Vegetation Studio Pro", "Instanced Indirect Node HD SRP")]
// ReSharper disable once InconsistentNaming
internal class IndirectNodeHD : CodeFunctionNode
{
public IndirectNodeHD()
{
name = "Vegetation Studio Pro Instanced Indirect Node HD SRP";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("PositionPassthroughHD",
BindingFlags.Static | BindingFlags.NonPublic);
}
// ReSharper disable once InconsistentNaming
static string PositionPassthroughHD(
[Slot(0, Binding.None)] DynamicDimensionVector A,
[Slot(1, Binding.None)] out DynamicDimensionVector Out)
{
return
@"
{
Out = A;
}
";
}
public override void GenerateNodeFunction(FunctionRegistry registry, GraphContext graphContext, GenerationMode generationMode)
{
registry.ProvideFunction("include_instancing_pragmas", s => s.Append(@"
#pragma instancing_options renderinglayer procedural:setupVSPro
#ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
struct IndirectShaderData
{
float4x4 PositionMatrix;
float4x4 InversePositionMatrix;
float4 ControlData;
};
#if defined(SHADER_API_GLCORE) || defined(SHADER_API_D3D11) || defined(SHADER_API_GLES3) || defined(SHADER_API_METAL) || defined(SHADER_API_VULKAN) || defined(SHADER_API_PSSL) || defined(SHADER_API_XBOXONE)
uniform StructuredBuffer<IndirectShaderData> VisibleShaderDataBuffer;
#endif
#endif
void setupVSPro()
{
#define unity_ObjectToWorld unity_ObjectToWorld
#define unity_WorldToObject unity_WorldToObject
#ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
unity_LODFade = VisibleShaderDataBuffer[unity_InstanceID].ControlData;
unity_ObjectToWorld = VisibleShaderDataBuffer[unity_InstanceID].PositionMatrix;
unity_WorldToObject = VisibleShaderDataBuffer[unity_InstanceID].InversePositionMatrix;
#endif
}
"));
base.GenerateNodeFunction(registry, graphContext, generationMode);
}
}