1
- using System . Reflection ;
2
1
using UnityEngine ;
3
2
using UnityEditor . Graphing ;
4
3
using UnityEditor . ShaderGraph . Drawing . Controls ;
4
+ using UnityEditor . ShaderGraph . Internal ;
5
5
6
6
namespace UnityEditor . ShaderGraph
7
7
{
8
8
[ FormerName ( "UnityEditor.ShaderGraph.BakedGAbstractMaterialNode" ) ]
9
9
[ FormerName ( "UnityEditor.ShaderGraph.LightProbeNode" ) ]
10
10
[ Title ( "Input" , "Lighting" , "Baked GI" ) ]
11
- class BakedGINode : CodeFunctionNode
11
+ class BakedGINode : AbstractMaterialNode , IGeneratesBodyCode , IMayRequirePixelPosition , IMayRequirePosition , IMayRequireNormal , IMayRequireMeshUV
12
12
{
13
13
public override bool hasPreview { get { return false ; } }
14
14
@@ -18,14 +18,6 @@ public BakedGINode()
18
18
synonyms = new string [ ] { "global illumination" } ;
19
19
}
20
20
21
- protected override MethodInfo GetFunctionToConvert ( )
22
- {
23
- if ( applyScaling . isOn )
24
- return GetType ( ) . GetMethod ( "Unity_BakedGIScale" , BindingFlags . Static | BindingFlags . NonPublic ) ;
25
- else
26
- return GetType ( ) . GetMethod ( "Unity_BakedGI" , BindingFlags . Static | BindingFlags . NonPublic ) ;
27
- }
28
-
29
21
[ SerializeField ]
30
22
private bool m_ApplyScaling = true ;
31
23
@@ -42,36 +34,85 @@ public ToggleData applyScaling
42
34
}
43
35
}
44
36
45
- static string Unity_BakedGI (
46
- [ Slot ( 2 , Binding . WorldSpacePosition ) ] Vector3 Position ,
47
- [ Slot ( 0 , Binding . WorldSpaceNormal ) ] Vector3 Normal ,
48
- [ Slot ( 3 , Binding . MeshUV1 ) ] Vector2 StaticUV ,
49
- [ Slot ( 4 , Binding . MeshUV2 ) ] Vector2 DynamicUV ,
50
- [ Slot ( 1 , Binding . None ) ] out Vector3 Out )
37
+ const int kNormalWSInputSlotId = 0 ;
38
+ const string kNormalWSInputSlotName = "NormalWS" ;
39
+
40
+ const int kOutputSlotId = 1 ;
41
+ const string kOutputSlotName = "Out" ;
42
+
43
+ const int kPositionWSInputSlotId = 2 ;
44
+ const string kPositionWSInputSlotName = "PositionWS" ;
45
+
46
+ const int kStaticUVInputSlotId = 3 ;
47
+ const string kStaticUVInputSlotName = "StaticUV" ;
48
+
49
+ const int kDynamicUVInputSlotId = 4 ;
50
+ const string kDynamicUVInputSlotName = "DynamicUV" ;
51
+
52
+ public sealed override void UpdateNodeAfterDeserialization ( )
51
53
{
52
- Out = Vector3 . one ;
53
- return
54
- @"
55
- {
56
- Out = SHADERGRAPH_BAKED_GI(Position, Normal, StaticUV, DynamicUV, false);
57
- }
58
- " ;
54
+ // Input
55
+ AddSlot ( new NormalMaterialSlot ( kNormalWSInputSlotId , kNormalWSInputSlotName , kNormalWSInputSlotName , CoordinateSpace . World ) ) ;
56
+ AddSlot ( new PositionMaterialSlot ( kPositionWSInputSlotId , kPositionWSInputSlotName , kPositionWSInputSlotName , CoordinateSpace . World ) ) ;
57
+ AddSlot ( new UVMaterialSlot ( kStaticUVInputSlotId , kStaticUVInputSlotName , kStaticUVInputSlotName , UVChannel . UV1 ) ) ;
58
+ AddSlot ( new UVMaterialSlot ( kDynamicUVInputSlotId , kDynamicUVInputSlotName , kDynamicUVInputSlotName , UVChannel . UV2 ) ) ;
59
+
60
+ // Output
61
+ AddSlot ( new Vector3MaterialSlot ( kOutputSlotId , kOutputSlotName , kOutputSlotName , SlotType . Output , Vector3 . zero ) ) ;
62
+
63
+ RemoveSlotsNameNotMatching ( new [ ]
64
+ {
65
+ // Input
66
+ kNormalWSInputSlotId ,
67
+ kPositionWSInputSlotId ,
68
+ kStaticUVInputSlotId ,
69
+ kDynamicUVInputSlotId ,
70
+
71
+ // Output
72
+ kOutputSlotId ,
73
+ } ) ;
59
74
}
60
75
61
- static string Unity_BakedGIScale (
62
- [ Slot ( 2 , Binding . WorldSpacePosition ) ] Vector3 Position ,
63
- [ Slot ( 0 , Binding . WorldSpaceNormal ) ] Vector3 Normal ,
64
- [ Slot ( 3 , Binding . MeshUV1 ) ] Vector2 StaticUV ,
65
- [ Slot ( 4 , Binding . MeshUV2 ) ] Vector2 DynamicUV ,
66
- [ Slot ( 1 , Binding . None ) ] out Vector3 Out )
76
+ public void GenerateNodeCode ( ShaderStringBuilder sb , GenerationMode generationMode )
67
77
{
68
- Out = Vector3 . one ;
69
- return
70
- @"
71
- {
72
- Out = SHADERGRAPH_BAKED_GI(Position, Normal, StaticUV, DynamicUV, true);
73
- }
74
- " ;
78
+ if ( generationMode == GenerationMode . ForReals )
79
+ {
80
+ sb . AppendLine ( "$precision3 {6} = SHADERGRAPH_BAKED_GI({0}, {1}, IN.{2}.xy, {3}, {4}, {5});" ,
81
+ GetSlotValue ( kPositionWSInputSlotId , generationMode ) ,
82
+ GetSlotValue ( kNormalWSInputSlotId , generationMode ) ,
83
+ ShaderGeneratorNames . PixelPosition ,
84
+ GetSlotValue ( kStaticUVInputSlotId , generationMode ) ,
85
+ GetSlotValue ( kDynamicUVInputSlotId , generationMode ) ,
86
+ applyScaling . isOn ? "true" : "false" ,
87
+ GetVariableNameForSlot ( kOutputSlotId ) ) ;
88
+ }
89
+ else
90
+ {
91
+ // Output zeros
92
+ sb . AppendLine ( "$precision3 {0} = 0.0;" ,
93
+ GetVariableNameForSlot ( kOutputSlotId ) ) ;
94
+ }
95
+ }
96
+
97
+ public bool RequiresPixelPosition ( ShaderStageCapability stageCapability = ShaderStageCapability . All )
98
+ {
99
+ return true ; // needed for APV sampling noise when TAA is used
100
+ }
101
+
102
+ public NeededCoordinateSpace RequiresPosition ( ShaderStageCapability stageCapability = ShaderStageCapability . All )
103
+ {
104
+ return FindSlot < PositionMaterialSlot > ( kPositionWSInputSlotId ) . RequiresPosition ( ) ;
105
+ }
106
+
107
+ public NeededCoordinateSpace RequiresNormal ( ShaderStageCapability stageCapability = ShaderStageCapability . All )
108
+ {
109
+ return FindSlot < NormalMaterialSlot > ( kNormalWSInputSlotId ) . RequiresNormal ( ) ;
110
+ }
111
+
112
+ public bool RequiresMeshUV ( UVChannel channel , ShaderStageCapability stageCapability = ShaderStageCapability . All )
113
+ {
114
+ return FindSlot < UVMaterialSlot > ( kStaticUVInputSlotId ) . RequiresMeshUV ( channel ) ||
115
+ FindSlot < UVMaterialSlot > ( kDynamicUVInputSlotId ) . RequiresMeshUV ( channel ) ;
75
116
}
76
117
}
77
118
}
0 commit comments