@@ -25,6 +25,8 @@ export class PrePassOutputBlock extends NodeMaterialBlock {
25
25
this . registerInput ( "viewNormal" , NodeMaterialBlockConnectionPointTypes . AutoDetect , true ) ;
26
26
this . registerInput ( "worldNormal" , NodeMaterialBlockConnectionPointTypes . AutoDetect , true ) ;
27
27
this . registerInput ( "reflectivity" , NodeMaterialBlockConnectionPointTypes . AutoDetect , true ) ;
28
+ this . registerInput ( "velocity" , NodeMaterialBlockConnectionPointTypes . AutoDetect , true ) ;
29
+ this . registerInput ( "velocityLinear" , NodeMaterialBlockConnectionPointTypes . AutoDetect , true ) ;
28
30
29
31
this . inputs [ 2 ] . addExcludedConnectionPointFromAllowedTypes ( NodeMaterialBlockConnectionPointTypes . Vector3 | NodeMaterialBlockConnectionPointTypes . Vector4 ) ;
30
32
this . inputs [ 3 ] . addExcludedConnectionPointFromAllowedTypes ( NodeMaterialBlockConnectionPointTypes . Vector3 | NodeMaterialBlockConnectionPointTypes . Vector4 ) ;
@@ -36,6 +38,8 @@ export class PrePassOutputBlock extends NodeMaterialBlock {
36
38
NodeMaterialBlockConnectionPointTypes . Color3 |
37
39
NodeMaterialBlockConnectionPointTypes . Color4
38
40
) ;
41
+ this . inputs [ 7 ] . addExcludedConnectionPointFromAllowedTypes ( NodeMaterialBlockConnectionPointTypes . Vector3 | NodeMaterialBlockConnectionPointTypes . Vector4 ) ;
42
+ this . inputs [ 8 ] . addExcludedConnectionPointFromAllowedTypes ( NodeMaterialBlockConnectionPointTypes . Vector3 | NodeMaterialBlockConnectionPointTypes . Vector4 ) ;
39
43
}
40
44
41
45
/**
@@ -95,6 +99,20 @@ export class PrePassOutputBlock extends NodeMaterialBlock {
95
99
return this . _inputs [ 6 ] ;
96
100
}
97
101
102
+ /**
103
+ * Gets the velocity component
104
+ */
105
+ public get velocity ( ) : NodeMaterialConnectionPoint {
106
+ return this . _inputs [ 7 ] ;
107
+ }
108
+
109
+ /**
110
+ * Gets the linear velocity component
111
+ */
112
+ public get velocityLinear ( ) : NodeMaterialConnectionPoint {
113
+ return this . _inputs [ 8 ] ;
114
+ }
115
+
98
116
private _getFragData ( isWebGPU : boolean , index : number ) {
99
117
return isWebGPU ? `fragmentOutputs.fragData${ index } ` : `gl_FragData[${ index } ]` ;
100
118
}
@@ -109,6 +127,8 @@ export class PrePassOutputBlock extends NodeMaterialBlock {
109
127
const viewDepth = this . viewDepth ;
110
128
const reflectivity = this . reflectivity ;
111
129
const screenDepth = this . screenDepth ;
130
+ const velocity = this . velocity ;
131
+ const velocityLinear = this . velocityLinear ;
112
132
113
133
state . sharedData . blocksWithDefines . push ( this ) ;
114
134
@@ -186,6 +206,26 @@ export class PrePassOutputBlock extends NodeMaterialBlock {
186
206
state . compilationString += ` fragData[PREPASS_REFLECTIVITY_INDEX] = ${ vec4 } (0.0, 0.0, 0.0, 1.0);\r\n` ;
187
207
}
188
208
state . compilationString += `#endif\r\n` ;
209
+ state . compilationString += `#ifdef PREPASS_VELOCITY\r\n` ;
210
+ if ( velocity . connectedPoint ) {
211
+ state . compilationString += ` fragData[PREPASS_VELOCITY_INDEX] = ${ vec4 } (${ velocity . associatedVariableName } .rgb, ${
212
+ velocity . connectedPoint . type === NodeMaterialBlockConnectionPointTypes . Vector4 ? velocity . associatedVariableName + ".a" : "1.0"
213
+ } );\r\n`;
214
+ } else {
215
+ // We have to write something on the reflectivity output or it will raise a gl error
216
+ state . compilationString += ` fragData[PREPASS_VELOCITY_INDEX] = ${ vec4 } (0.0, 0.0, 0.0, 1.0);\r\n` ;
217
+ }
218
+ state . compilationString += `#endif\r\n` ;
219
+ state . compilationString += `#ifdef PREPASS_VELOCITY_LINEAR\r\n` ;
220
+ if ( velocityLinear . connectedPoint ) {
221
+ state . compilationString += ` fragData[PREPASS_VELOCITY_LINEAR_INDEX] = ${ vec4 } (${ velocityLinear . associatedVariableName } .rgb, ${
222
+ velocityLinear . connectedPoint . type === NodeMaterialBlockConnectionPointTypes . Vector4 ? velocityLinear . associatedVariableName + ".a" : "1.0"
223
+ } );\r\n`;
224
+ } else {
225
+ // We have to write something on the reflectivity output or it will raise a gl error
226
+ state . compilationString += ` fragData[PREPASS_VELOCITY_LINEAR_INDEX] = ${ vec4 } (0.0, 0.0, 0.0, 1.0);\r\n` ;
227
+ }
228
+ state . compilationString += `#endif\r\n` ;
189
229
190
230
state . compilationString += `#if SCENE_MRT_COUNT > 1\r\n` ;
191
231
state . compilationString += `${ this . _getFragData ( isWebGPU , 1 ) } = fragData[1];\r\n` ;
0 commit comments