@needle-tools/three 0.153.1 → 0.154.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/three.cjs +1260 -1517
- package/build/three.js +1267 -1524
- package/build/three.min.js +7 -8
- package/build/three.module.js +859 -1097
- package/build/three.module.min.js +6 -7
- package/examples/jsm/controls/ArcballControls.js +2 -1
- package/examples/jsm/controls/FlyControls.js +25 -9
- package/examples/jsm/controls/OrbitControls.js +7 -1
- package/examples/jsm/csm/CSM.js +1 -1
- package/examples/jsm/effects/AnaglyphEffect.js +1 -1
- package/examples/jsm/effects/OutlineEffect.js +1 -1
- package/examples/jsm/effects/ParallaxBarrierEffect.js +1 -1
- package/examples/jsm/environments/RoomEnvironment.js +6 -2
- package/examples/jsm/lines/LineMaterial.js +1 -1
- package/examples/jsm/loaders/3DMLoader.js +1 -1
- package/examples/jsm/loaders/3MFLoader.js +5 -1
- package/examples/jsm/loaders/AMFLoader.js +5 -1
- package/examples/jsm/loaders/ColladaLoader.js +4 -1
- package/examples/jsm/loaders/FBXLoader.js +9 -2
- package/examples/jsm/loaders/LDrawLoader.js +4 -7
- package/examples/jsm/loaders/PLYLoader.js +16 -6
- package/examples/jsm/loaders/VRMLLoader.js +16 -4
- package/examples/jsm/materials/MeshGouraudMaterial.js +2 -2
- package/examples/jsm/math/MeshSurfaceSampler.js +76 -35
- package/examples/jsm/nodes/Nodes.js +20 -15
- package/examples/jsm/nodes/accessors/BufferAttributeNode.js +21 -8
- package/examples/jsm/nodes/accessors/CameraNode.js +25 -4
- package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +7 -1
- package/examples/jsm/nodes/accessors/InstanceNode.js +2 -4
- package/examples/jsm/nodes/accessors/MaterialNode.js +55 -47
- package/examples/jsm/nodes/accessors/ModelNode.js +3 -1
- package/examples/jsm/nodes/accessors/MorphNode.js +70 -0
- package/examples/jsm/nodes/accessors/NormalNode.js +3 -2
- package/examples/jsm/nodes/accessors/Object3DNode.js +10 -2
- package/examples/jsm/nodes/accessors/SceneNode.js +46 -0
- package/examples/jsm/nodes/accessors/SkinningNode.js +43 -62
- package/examples/jsm/nodes/accessors/TangentNode.js +2 -2
- package/examples/jsm/nodes/accessors/TextureBicubicNode.js +94 -0
- package/examples/jsm/nodes/accessors/TextureNode.js +68 -6
- package/examples/jsm/nodes/accessors/TextureSizeNode.js +35 -0
- package/examples/jsm/nodes/accessors/UVNode.js +1 -1
- package/examples/jsm/nodes/code/CodeNode.js +3 -0
- package/examples/jsm/nodes/code/FunctionNode.js +25 -4
- package/examples/jsm/nodes/core/BypassNode.js +2 -2
- package/examples/jsm/nodes/core/ContextNode.js +2 -0
- package/examples/jsm/nodes/core/IndexNode.js +66 -0
- package/examples/jsm/nodes/core/LightingModel.js +2 -1
- package/examples/jsm/nodes/core/Node.js +12 -15
- package/examples/jsm/nodes/core/NodeBuilder.js +24 -5
- package/examples/jsm/nodes/core/PropertyNode.js +4 -0
- package/examples/jsm/nodes/core/StackNode.js +1 -1
- package/examples/jsm/nodes/core/UniformNode.js +1 -1
- package/examples/jsm/nodes/core/VarNode.js +1 -3
- package/examples/jsm/nodes/display/BlendModeNode.js +9 -9
- package/examples/jsm/nodes/display/ColorAdjustmentNode.js +7 -7
- package/examples/jsm/nodes/display/ColorSpaceNode.js +50 -49
- package/examples/jsm/nodes/display/NormalMapNode.js +3 -3
- package/examples/jsm/nodes/display/ToneMappingNode.js +8 -8
- package/examples/jsm/nodes/display/ViewportDepthNode.js +69 -0
- package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +34 -0
- package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +6 -5
- package/examples/jsm/nodes/display/ViewportTextureNode.js +23 -15
- package/examples/jsm/nodes/functions/BSDF/BRDF_BlinnPhong.js +5 -5
- package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +10 -8
- package/examples/jsm/nodes/functions/BSDF/BRDF_Lambert.js +2 -2
- package/examples/jsm/nodes/functions/BSDF/BRDF_Sheen.js +43 -0
- package/examples/jsm/nodes/functions/BSDF/DFGApprox.js +4 -4
- package/examples/jsm/nodes/functions/BSDF/D_GGX.js +2 -2
- package/examples/jsm/nodes/functions/BSDF/EnvironmentBRDF.js +13 -0
- package/examples/jsm/nodes/functions/BSDF/F_Schlick.js +2 -4
- package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +2 -2
- package/examples/jsm/nodes/functions/PhongLightingModel.js +7 -7
- package/examples/jsm/nodes/functions/PhysicalLightingModel.js +129 -18
- package/examples/jsm/nodes/functions/material/getGeometryRoughness.js +2 -2
- package/examples/jsm/nodes/functions/material/getRoughness.js +3 -3
- package/examples/jsm/nodes/geometry/RangeNode.js +1 -1
- package/examples/jsm/nodes/lighting/DirectionalLightNode.js +2 -2
- package/examples/jsm/nodes/lighting/EnvironmentNode.js +91 -62
- package/examples/jsm/nodes/lighting/LightUtils.js +2 -2
- package/examples/jsm/nodes/lighting/LightingContextNode.js +17 -15
- package/examples/jsm/nodes/lighting/PointLightNode.js +3 -3
- package/examples/jsm/nodes/lighting/SpotLightNode.js +3 -3
- package/examples/jsm/nodes/materials/LineBasicNodeMaterial.js +0 -15
- package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +0 -15
- package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +0 -10
- package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +0 -9
- package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +41 -0
- package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +1 -14
- package/examples/jsm/nodes/materials/NodeMaterial.js +79 -28
- package/examples/jsm/nodes/materials/PointsNodeMaterial.js +0 -9
- package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +0 -7
- package/examples/jsm/nodes/materialx/lib/mx_hsv.js +3 -3
- package/examples/jsm/nodes/materialx/lib/mx_noise.js +14 -14
- package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +4 -4
- package/examples/jsm/nodes/math/MathNode.js +6 -0
- package/examples/jsm/nodes/math/OperatorNode.js +1 -1
- package/examples/jsm/nodes/procedural/CheckerNode.js +3 -3
- package/examples/jsm/nodes/shadernode/ShaderNode.js +24 -4
- package/examples/jsm/nodes/utils/LoopNode.js +1 -1
- package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +1 -1
- package/examples/jsm/objects/GroundProjectedSkybox.js +1 -1
- package/examples/jsm/objects/Reflector.js +1 -1
- package/examples/jsm/objects/Refractor.js +1 -1
- package/examples/jsm/objects/Sky.js +1 -1
- package/examples/jsm/objects/Water.js +1 -1
- package/examples/jsm/objects/Water2.js +1 -1
- package/examples/jsm/offscreen/scene.js +1 -0
- package/examples/jsm/postprocessing/EffectComposer.js +2 -0
- package/examples/jsm/postprocessing/OutlinePass.js +1 -3
- package/examples/jsm/postprocessing/SSAARenderPass.js +3 -12
- package/examples/jsm/postprocessing/SavePass.js +3 -1
- package/examples/jsm/postprocessing/TAARenderPass.js +14 -2
- package/examples/jsm/postprocessing/TexturePass.js +2 -1
- package/examples/jsm/postprocessing/UnrealBloomPass.js +9 -10
- package/examples/jsm/renderers/common/Backend.js +2 -0
- package/examples/jsm/renderers/common/Background.js +7 -6
- package/examples/jsm/renderers/common/Pipelines.js +26 -14
- package/examples/jsm/renderers/common/RenderObject.js +18 -0
- package/examples/jsm/renderers/common/RenderObjects.js +29 -29
- package/examples/jsm/renderers/common/Renderer.js +48 -6
- package/examples/jsm/renderers/common/nodes/Nodes.js +1 -1
- package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +340 -0
- package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +23 -19
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +123 -41
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +29 -9
- package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +4 -0
- package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +8 -13
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +85 -3
- package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +5 -1
- package/examples/jsm/shaders/BlendShader.js +1 -2
- package/examples/jsm/shaders/BokehShader2.js +1 -1
- package/examples/jsm/shaders/CopyShader.js +2 -2
- package/examples/jsm/shaders/ToonShader.js +4 -4
- package/examples/jsm/shaders/WaterRefractionShader.js +1 -1
- package/examples/jsm/webxr/OculusHandPointerModel.js +34 -13
- package/package.json +2 -1
- package/src/Three.Legacy.js +0 -228
- package/src/animation/PropertyBinding.js +1 -1
- package/src/constants.js +1 -1
- package/src/core/BufferAttribute.js +0 -24
- package/src/core/BufferGeometry.js +0 -7
- package/src/loaders/Loader.js +2 -0
- package/src/loaders/MaterialLoader.js +1 -0
- package/src/materials/Material.js +3 -0
- package/src/objects/Skeleton.js +0 -2
- package/src/renderers/WebGLRenderer.js +9 -21
- package/src/renderers/shaders/ShaderChunk/alphahash_fragment.glsl.js +7 -0
- package/src/renderers/shaders/ShaderChunk/alphahash_pars_fragment.glsl.js +68 -0
- package/src/renderers/shaders/ShaderChunk/begin_vertex.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/common.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js +9 -1
- package/src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/uv_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk.js +10 -6
- package/src/renderers/shaders/ShaderLib/background.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/cube.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/distanceRGBA.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/equirect.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/linedashed.glsl.js +2 -2
- package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +4 -2
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +4 -2
- package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +4 -2
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +4 -2
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -2
- package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +4 -2
- package/src/renderers/shaders/ShaderLib/points.glsl.js +4 -2
- package/src/renderers/shaders/ShaderLib/shadow.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/sprite.glsl.js +4 -2
- package/src/renderers/webgl/WebGLObjects.js +23 -3
- package/src/renderers/webgl/WebGLProgram.js +24 -5
- package/src/renderers/webgl/WebGLPrograms.js +3 -0
- package/src/renderers/webxr/WebXRManager.js +11 -33
- package/src/scenes/Scene.js +0 -14
- package/examples/jsm/nodes/core/InstanceIndexNode.js +0 -45
- /package/src/renderers/shaders/ShaderChunk/{encodings_fragment.glsl.js → colorspace_fragment.glsl.js} +0 -0
- /package/src/renderers/shaders/ShaderChunk/{encodings_pars_fragment.glsl.js → colorspace_pars_fragment.glsl.js} +0 -0
- /package/src/renderers/shaders/ShaderChunk/{output_fragment.glsl.js → opaque_fragment.glsl.js} +0 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import { MathNode, GLSLNodeParser, NodeBuilder, NodeMaterial } from 'three/nodes';
|
|
2
|
+
|
|
3
|
+
const glslMethods = {
|
|
4
|
+
[ MathNode.ATAN2 ]: 'atan'
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const precisionLib = {
|
|
8
|
+
low: 'lowp',
|
|
9
|
+
medium: 'mediump',
|
|
10
|
+
high: 'highp'
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
class GLSLNodeBuilder extends NodeBuilder {
|
|
14
|
+
|
|
15
|
+
constructor( object, renderer, scene = null ) {
|
|
16
|
+
|
|
17
|
+
super( object, renderer, new GLSLNodeParser(), scene );
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getMethod( method ) {
|
|
22
|
+
|
|
23
|
+
return glslMethods[ method ] || method;
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
getTexture( texture, textureProperty, uvSnippet ) {
|
|
28
|
+
|
|
29
|
+
if ( texture.isTextureCube ) {
|
|
30
|
+
|
|
31
|
+
return `textureCube( ${textureProperty}, ${uvSnippet} )`;
|
|
32
|
+
|
|
33
|
+
} else {
|
|
34
|
+
|
|
35
|
+
return `texture2D( ${textureProperty}, ${uvSnippet} )`;
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
getTextureBias( texture, textureProperty, uvSnippet, biasSnippet ) {
|
|
42
|
+
|
|
43
|
+
if ( this.material.extensions !== undefined ) this.material.extensions.shaderTextureLOD = true;
|
|
44
|
+
|
|
45
|
+
return `textureLod( ${textureProperty}, ${uvSnippet}, ${biasSnippet} )`;
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
getVars( shaderStage ) {
|
|
50
|
+
|
|
51
|
+
const snippets = [];
|
|
52
|
+
|
|
53
|
+
const vars = this.vars[ shaderStage ];
|
|
54
|
+
|
|
55
|
+
for ( const variable of vars ) {
|
|
56
|
+
|
|
57
|
+
snippets.push( `${ this.getVar( variable.type, variable.name ) };` );
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return snippets.join( '\n\t' );
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
getUniforms( shaderStage ) {
|
|
66
|
+
|
|
67
|
+
const uniforms = this.uniforms[ shaderStage ];
|
|
68
|
+
|
|
69
|
+
let output = '';
|
|
70
|
+
|
|
71
|
+
for ( const uniform of uniforms ) {
|
|
72
|
+
|
|
73
|
+
let snippet = null;
|
|
74
|
+
|
|
75
|
+
if ( uniform.type === 'texture' ) {
|
|
76
|
+
|
|
77
|
+
snippet = `sampler2D ${uniform.name};\n`;
|
|
78
|
+
|
|
79
|
+
} else if ( uniform.type === 'cubeTexture' ) {
|
|
80
|
+
|
|
81
|
+
snippet = `samplerCube ${uniform.name};\n`;
|
|
82
|
+
|
|
83
|
+
} else {
|
|
84
|
+
|
|
85
|
+
const vectorType = this.getVectorType( uniform.type );
|
|
86
|
+
|
|
87
|
+
snippet = `${vectorType} ${uniform.name};\n`;
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const precision = uniform.node.precision;
|
|
92
|
+
|
|
93
|
+
if ( precision !== null ) {
|
|
94
|
+
|
|
95
|
+
snippet = 'uniform ' + precisionLib[ precision ] + ' ' + snippet;
|
|
96
|
+
|
|
97
|
+
} else {
|
|
98
|
+
|
|
99
|
+
snippet = 'uniform ' + snippet;
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
output += snippet;
|
|
104
|
+
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return output;
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
getAttributes( shaderStage ) {
|
|
112
|
+
|
|
113
|
+
let snippet = '';
|
|
114
|
+
|
|
115
|
+
if ( shaderStage === 'vertex' ) {
|
|
116
|
+
|
|
117
|
+
const attributes = this.attributes;
|
|
118
|
+
|
|
119
|
+
for ( const attribute of attributes ) {
|
|
120
|
+
|
|
121
|
+
snippet += `attribute ${attribute.type} ${attribute.name};\n`;
|
|
122
|
+
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return snippet;
|
|
128
|
+
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
getVaryings( shaderStage ) {
|
|
132
|
+
|
|
133
|
+
let snippet = '';
|
|
134
|
+
|
|
135
|
+
const varyings = this.varyings;
|
|
136
|
+
|
|
137
|
+
if ( shaderStage === 'vertex' ) {
|
|
138
|
+
|
|
139
|
+
for ( const varying of varyings ) {
|
|
140
|
+
|
|
141
|
+
snippet += `${varying.needsInterpolation ? 'varying' : '/*varying*/'} ${varying.type} ${varying.name};\n`;
|
|
142
|
+
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
} else if ( shaderStage === 'fragment' ) {
|
|
146
|
+
|
|
147
|
+
for ( const varying of varyings ) {
|
|
148
|
+
|
|
149
|
+
if ( varying.needsInterpolation ) {
|
|
150
|
+
|
|
151
|
+
snippet += `varying ${varying.type} ${varying.name};\n`;
|
|
152
|
+
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return snippet;
|
|
160
|
+
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
getVertexIndex() {
|
|
164
|
+
|
|
165
|
+
return 'gl_VertexID';
|
|
166
|
+
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
getFrontFacing() {
|
|
170
|
+
|
|
171
|
+
return 'gl_FrontFacing';
|
|
172
|
+
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
getFragCoord() {
|
|
176
|
+
|
|
177
|
+
return 'gl_FragCoord';
|
|
178
|
+
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
isFlipY() {
|
|
182
|
+
|
|
183
|
+
return true;
|
|
184
|
+
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
_getGLSLVertexCode( shaderData ) {
|
|
188
|
+
|
|
189
|
+
return `${ this.getSignature() }
|
|
190
|
+
|
|
191
|
+
// uniforms
|
|
192
|
+
${shaderData.uniforms}
|
|
193
|
+
|
|
194
|
+
// varyings
|
|
195
|
+
${shaderData.varyings}
|
|
196
|
+
|
|
197
|
+
// attributes
|
|
198
|
+
${shaderData.attributes}
|
|
199
|
+
|
|
200
|
+
// codes
|
|
201
|
+
${shaderData.codes}
|
|
202
|
+
|
|
203
|
+
void main() {
|
|
204
|
+
|
|
205
|
+
// vars
|
|
206
|
+
${shaderData.vars}
|
|
207
|
+
|
|
208
|
+
// flow
|
|
209
|
+
${shaderData.flow}
|
|
210
|
+
|
|
211
|
+
}
|
|
212
|
+
`;
|
|
213
|
+
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
_getGLSLFragmentCode( shaderData ) {
|
|
217
|
+
|
|
218
|
+
return `${ this.getSignature() }
|
|
219
|
+
|
|
220
|
+
// precision
|
|
221
|
+
precision highp float;
|
|
222
|
+
precision highp int;
|
|
223
|
+
|
|
224
|
+
// uniforms
|
|
225
|
+
${shaderData.uniforms}
|
|
226
|
+
|
|
227
|
+
// varyings
|
|
228
|
+
${shaderData.varyings}
|
|
229
|
+
|
|
230
|
+
// codes
|
|
231
|
+
${shaderData.codes}
|
|
232
|
+
|
|
233
|
+
void main() {
|
|
234
|
+
|
|
235
|
+
// vars
|
|
236
|
+
${shaderData.vars}
|
|
237
|
+
|
|
238
|
+
// flow
|
|
239
|
+
${shaderData.flow}
|
|
240
|
+
|
|
241
|
+
}
|
|
242
|
+
`;
|
|
243
|
+
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
buildCode() {
|
|
247
|
+
|
|
248
|
+
const shadersData = this.material !== null ? { fragment: {}, vertex: {} } : { compute: {} };
|
|
249
|
+
|
|
250
|
+
for ( const shaderStage in shadersData ) {
|
|
251
|
+
|
|
252
|
+
let flow = '// code\n\n';
|
|
253
|
+
flow += this.flowCode[ shaderStage ];
|
|
254
|
+
|
|
255
|
+
const flowNodes = this.flowNodes[ shaderStage ];
|
|
256
|
+
const mainNode = flowNodes[ flowNodes.length - 1 ];
|
|
257
|
+
|
|
258
|
+
for ( const node of flowNodes ) {
|
|
259
|
+
|
|
260
|
+
const flowSlotData = this.getFlowData( node/*, shaderStage*/ );
|
|
261
|
+
const slotName = node.name;
|
|
262
|
+
|
|
263
|
+
if ( slotName ) {
|
|
264
|
+
|
|
265
|
+
if ( flow.length > 0 ) flow += '\n';
|
|
266
|
+
|
|
267
|
+
flow += `\t// flow -> ${ slotName }\n\t`;
|
|
268
|
+
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
flow += `${ flowSlotData.code }\n\t`;
|
|
272
|
+
|
|
273
|
+
if ( node === mainNode && shaderStage !== 'compute' ) {
|
|
274
|
+
|
|
275
|
+
flow += '// result\n\t';
|
|
276
|
+
|
|
277
|
+
if ( shaderStage === 'vertex' ) {
|
|
278
|
+
|
|
279
|
+
flow += 'gl_Position = ';
|
|
280
|
+
|
|
281
|
+
} else if ( shaderStage === 'fragment' ) {
|
|
282
|
+
|
|
283
|
+
flow += 'gl_FragColor = ';
|
|
284
|
+
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
flow += `${ flowSlotData.result };`;
|
|
288
|
+
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const stageData = shadersData[ shaderStage ];
|
|
294
|
+
|
|
295
|
+
stageData.uniforms = this.getUniforms( shaderStage );
|
|
296
|
+
stageData.attributes = this.getAttributes( shaderStage );
|
|
297
|
+
stageData.varyings = this.getVaryings( shaderStage );
|
|
298
|
+
stageData.vars = this.getVars( shaderStage );
|
|
299
|
+
stageData.codes = this.getCodes( shaderStage );
|
|
300
|
+
stageData.flow = flow;
|
|
301
|
+
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if ( this.material !== null ) {
|
|
305
|
+
|
|
306
|
+
this.vertexShader = this._getGLSLVertexCode( shadersData.vertex );
|
|
307
|
+
this.fragmentShader = this._getGLSLFragmentCode( shadersData.fragment );
|
|
308
|
+
|
|
309
|
+
} else {
|
|
310
|
+
|
|
311
|
+
console.warn( 'GLSLNodeBuilder: compute shaders are not supported.' );
|
|
312
|
+
//this.computeShader = this._getGLSLComputeCode( shadersData.compute );
|
|
313
|
+
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
build() {
|
|
319
|
+
|
|
320
|
+
// @TODO: Move this code to super.build()
|
|
321
|
+
|
|
322
|
+
const { object, material } = this;
|
|
323
|
+
|
|
324
|
+
if ( material !== null ) {
|
|
325
|
+
|
|
326
|
+
NodeMaterial.fromMaterial( material ).build( this );
|
|
327
|
+
|
|
328
|
+
} else {
|
|
329
|
+
|
|
330
|
+
this.addFlow( 'compute', object );
|
|
331
|
+
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
return super.build();
|
|
335
|
+
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export default GLSLNodeBuilder;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defaultShaderStages, NodeFrame, MathNode, GLSLNodeParser, NodeBuilder } from 'three/nodes';
|
|
1
|
+
import { defaultShaderStages, NodeFrame, MathNode, GLSLNodeParser, NodeBuilder, normalView } from 'three/nodes';
|
|
2
2
|
import SlotNode from './SlotNode.js';
|
|
3
3
|
import { PerspectiveCamera, ShaderChunk, ShaderLib, UniformsUtils, UniformsLib } from 'three';
|
|
4
4
|
|
|
@@ -10,7 +10,8 @@ const nodeShaderLib = {
|
|
|
10
10
|
MeshBasicNodeMaterial: ShaderLib.basic,
|
|
11
11
|
PointsNodeMaterial: ShaderLib.points,
|
|
12
12
|
MeshStandardNodeMaterial: ShaderLib.standard,
|
|
13
|
-
MeshPhysicalNodeMaterial: ShaderLib.physical
|
|
13
|
+
MeshPhysicalNodeMaterial: ShaderLib.physical,
|
|
14
|
+
MeshPhongNodeMaterial: ShaderLib.phong
|
|
14
15
|
};
|
|
15
16
|
|
|
16
17
|
const glslMethods = {
|
|
@@ -74,6 +75,7 @@ class WebGLNodeBuilder extends NodeBuilder {
|
|
|
74
75
|
|
|
75
76
|
if ( material.isMeshPhysicalNodeMaterial ) type = 'MeshPhysicalNodeMaterial';
|
|
76
77
|
else if ( material.isMeshStandardNodeMaterial ) type = 'MeshStandardNodeMaterial';
|
|
78
|
+
else if ( material.isMeshPhongNodeMaterial ) type = 'MeshPhongNodeMaterial';
|
|
77
79
|
else if ( material.isMeshBasicNodeMaterial ) type = 'MeshBasicNodeMaterial';
|
|
78
80
|
else if ( material.isPointsNodeMaterial ) type = 'PointsNodeMaterial';
|
|
79
81
|
else if ( material.isLineBasicNodeMaterial ) type = 'LineBasicNodeMaterial';
|
|
@@ -97,6 +99,14 @@ class WebGLNodeBuilder extends NodeBuilder {
|
|
|
97
99
|
|
|
98
100
|
const { material, renderer } = this;
|
|
99
101
|
|
|
102
|
+
this.addSlot( 'fragment', new SlotNode( {
|
|
103
|
+
node: normalView,
|
|
104
|
+
nodeType: 'vec3',
|
|
105
|
+
source: getIncludeSnippet( 'clipping_planes_fragment' ),
|
|
106
|
+
target: 'vec3 TransformedNormalView = %RESULT%;',
|
|
107
|
+
inclusionType: 'append'
|
|
108
|
+
} ) );
|
|
109
|
+
|
|
100
110
|
if ( renderer.toneMappingNode && renderer.toneMappingNode.isNode === true ) {
|
|
101
111
|
|
|
102
112
|
this.addSlot( 'fragment', new SlotNode( {
|
|
@@ -116,7 +126,7 @@ class WebGLNodeBuilder extends NodeBuilder {
|
|
|
116
126
|
node: material.colorNode,
|
|
117
127
|
nodeType: 'vec4',
|
|
118
128
|
source: 'vec4 diffuseColor = vec4( diffuse, opacity );',
|
|
119
|
-
target: 'vec4 diffuseColor = %RESULT%;'
|
|
129
|
+
target: 'vec4 diffuseColor = %RESULT%; diffuseColor.a *= opacity;',
|
|
120
130
|
} ) );
|
|
121
131
|
|
|
122
132
|
}
|
|
@@ -131,10 +141,6 @@ class WebGLNodeBuilder extends NodeBuilder {
|
|
|
131
141
|
inclusionType: 'append'
|
|
132
142
|
} ) );
|
|
133
143
|
|
|
134
|
-
} else {
|
|
135
|
-
|
|
136
|
-
this.addCode( 'fragment', getIncludeSnippet( 'alphatest_fragment' ), 'diffuseColor.a = opacity;', this.shader );
|
|
137
|
-
|
|
138
144
|
}
|
|
139
145
|
|
|
140
146
|
if ( material.normalNode && material.normalNode.isNode ) {
|
|
@@ -348,17 +354,6 @@ class WebGLNodeBuilder extends NodeBuilder {
|
|
|
348
354
|
|
|
349
355
|
}
|
|
350
356
|
|
|
351
|
-
if ( material.thicknessNode && material.thicknessNode.isNode ) {
|
|
352
|
-
|
|
353
|
-
this.addSlot( 'fragment', new SlotNode( {
|
|
354
|
-
node: material.thicknessNode,
|
|
355
|
-
nodeType: 'float',
|
|
356
|
-
source: 'material.thickness = thickness;',
|
|
357
|
-
target: 'material.thickness = %RESULT%;'
|
|
358
|
-
} ) );
|
|
359
|
-
|
|
360
|
-
}
|
|
361
|
-
|
|
362
357
|
if ( material.attenuationDistanceNode && material.attenuationDistanceNode.isNode ) {
|
|
363
358
|
|
|
364
359
|
this.addSlot( 'fragment', new SlotNode( {
|
|
@@ -452,6 +447,9 @@ class WebGLNodeBuilder extends NodeBuilder {
|
|
|
452
447
|
|
|
453
448
|
for ( const uniform of uniforms ) {
|
|
454
449
|
|
|
450
|
+
if ( /^(modelViewMatrix|projectionMatrix)$/.test( uniform.name ) )
|
|
451
|
+
continue;
|
|
452
|
+
|
|
455
453
|
let snippet = null;
|
|
456
454
|
|
|
457
455
|
if ( uniform.type === 'texture' ) {
|
|
@@ -501,7 +499,7 @@ class WebGLNodeBuilder extends NodeBuilder {
|
|
|
501
499
|
for ( const attribute of attributes ) {
|
|
502
500
|
|
|
503
501
|
// ignore common attributes to prevent redefinitions
|
|
504
|
-
if (
|
|
502
|
+
if ( /^(position|normal|uv\d?)$/.test( attribute.name ) )
|
|
505
503
|
continue;
|
|
506
504
|
|
|
507
505
|
snippet += `attribute ${attribute.type} ${attribute.name}; `;
|
|
@@ -575,6 +573,12 @@ class WebGLNodeBuilder extends NodeBuilder {
|
|
|
575
573
|
|
|
576
574
|
}
|
|
577
575
|
|
|
576
|
+
getVertexIndex() {
|
|
577
|
+
|
|
578
|
+
return 'gl_VertexID';
|
|
579
|
+
|
|
580
|
+
}
|
|
581
|
+
|
|
578
582
|
getFrontFacing() {
|
|
579
583
|
|
|
580
584
|
return 'gl_FrontFacing';
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
/*// debugger tools
|
|
2
|
+
import 'https://greggman.github.io/webgpu-avoid-redundant-state-setting/webgpu-check-redundant-state-setting.js';
|
|
3
|
+
//*/
|
|
4
|
+
|
|
1
5
|
import { GPUFeatureName, GPUTextureFormat, GPULoadOp, GPUStoreOp, GPUIndexFormat, GPUTextureViewDimension } from './utils/WebGPUConstants.js';
|
|
2
6
|
|
|
3
|
-
import
|
|
7
|
+
import WGSLNodeBuilder from './nodes/WGSLNodeBuilder.js';
|
|
4
8
|
import Backend from '../common/Backend.js';
|
|
5
9
|
|
|
6
|
-
import { DepthFormat, WebGPUCoordinateSystem } from 'three';
|
|
10
|
+
import { DepthTexture, DepthFormat, DepthStencilFormat, UnsignedInt248Type, UnsignedIntType, WebGPUCoordinateSystem } from 'three';
|
|
7
11
|
|
|
8
12
|
import WebGPUUtils from './utils/WebGPUUtils.js';
|
|
9
13
|
import WebGPUAttributeUtils from './utils/WebGPUAttributeUtils.js';
|
|
@@ -49,7 +53,8 @@ class WebGPUBackend extends Backend {
|
|
|
49
53
|
this.device = null;
|
|
50
54
|
this.context = null;
|
|
51
55
|
this.colorBuffer = null;
|
|
52
|
-
|
|
56
|
+
|
|
57
|
+
this.depthBuffers = new WeakMap();
|
|
53
58
|
|
|
54
59
|
this.utils = new WebGPUUtils( this );
|
|
55
60
|
this.attributeUtils = new WebGPUAttributeUtils( this );
|
|
@@ -180,7 +185,7 @@ class WebGPUBackend extends Backend {
|
|
|
180
185
|
|
|
181
186
|
}
|
|
182
187
|
|
|
183
|
-
depthStencilAttachment.view = this.
|
|
188
|
+
depthStencilAttachment.view = this._getDepthBufferGPU( renderContext ).createView();
|
|
184
189
|
|
|
185
190
|
}
|
|
186
191
|
|
|
@@ -243,6 +248,7 @@ class WebGPUBackend extends Backend {
|
|
|
243
248
|
renderContextData.descriptor = descriptor;
|
|
244
249
|
renderContextData.encoder = encoder;
|
|
245
250
|
renderContextData.currentPass = currentPass;
|
|
251
|
+
renderContextData.currentAttributesSet = {};
|
|
246
252
|
|
|
247
253
|
//
|
|
248
254
|
|
|
@@ -316,7 +322,7 @@ class WebGPUBackend extends Backend {
|
|
|
316
322
|
|
|
317
323
|
}
|
|
318
324
|
|
|
319
|
-
descriptor.depthStencilAttachment.view = this.
|
|
325
|
+
descriptor.depthStencilAttachment.view = this._getDepthBufferGPU( renderContext ).createView();
|
|
320
326
|
|
|
321
327
|
if ( color ) {
|
|
322
328
|
|
|
@@ -395,6 +401,7 @@ class WebGPUBackend extends Backend {
|
|
|
395
401
|
const bindingsData = this.get( renderObject.getBindings() );
|
|
396
402
|
const contextData = this.get( context );
|
|
397
403
|
const pipelineGPU = this.get( pipeline ).pipeline;
|
|
404
|
+
const attributesSet = contextData.currentAttributesSet;
|
|
398
405
|
|
|
399
406
|
// pipeline
|
|
400
407
|
|
|
@@ -406,18 +413,26 @@ class WebGPUBackend extends Backend {
|
|
|
406
413
|
const bindGroupGPU = bindingsData.group;
|
|
407
414
|
passEncoderGPU.setBindGroup( 0, bindGroupGPU );
|
|
408
415
|
|
|
409
|
-
//
|
|
416
|
+
// attributes
|
|
410
417
|
|
|
411
418
|
const index = renderObject.getIndex();
|
|
412
419
|
|
|
413
420
|
const hasIndex = ( index !== null );
|
|
414
421
|
|
|
422
|
+
// index
|
|
423
|
+
|
|
415
424
|
if ( hasIndex === true ) {
|
|
416
425
|
|
|
417
|
-
|
|
418
|
-
|
|
426
|
+
if ( attributesSet.index !== index ) {
|
|
427
|
+
|
|
428
|
+
const buffer = this.get( index ).buffer;
|
|
429
|
+
const indexFormat = ( index.array instanceof Uint16Array ) ? GPUIndexFormat.Uint16 : GPUIndexFormat.Uint32;
|
|
419
430
|
|
|
420
|
-
|
|
431
|
+
passEncoderGPU.setIndexBuffer( buffer, indexFormat );
|
|
432
|
+
|
|
433
|
+
attributesSet.index = index;
|
|
434
|
+
|
|
435
|
+
}
|
|
421
436
|
|
|
422
437
|
}
|
|
423
438
|
|
|
@@ -427,8 +442,16 @@ class WebGPUBackend extends Backend {
|
|
|
427
442
|
|
|
428
443
|
for ( let i = 0, l = attributes.length; i < l; i ++ ) {
|
|
429
444
|
|
|
430
|
-
const
|
|
431
|
-
|
|
445
|
+
const attribute = attributes[ i ];
|
|
446
|
+
|
|
447
|
+
if ( attributesSet[ i ] !== attribute ) {
|
|
448
|
+
|
|
449
|
+
const buffer = this.get( attribute ).buffer;
|
|
450
|
+
passEncoderGPU.setVertexBuffer( i, buffer );
|
|
451
|
+
|
|
452
|
+
attributesSet[ i ] = attribute;
|
|
453
|
+
|
|
454
|
+
}
|
|
432
455
|
|
|
433
456
|
}
|
|
434
457
|
|
|
@@ -549,11 +572,17 @@ class WebGPUBackend extends Backend {
|
|
|
549
572
|
|
|
550
573
|
}
|
|
551
574
|
|
|
575
|
+
copyTextureToBuffer( texture, x, y, width, height ) {
|
|
576
|
+
|
|
577
|
+
return this.textureUtils.copyTextureToBuffer( texture, x, y, width, height );
|
|
578
|
+
|
|
579
|
+
}
|
|
580
|
+
|
|
552
581
|
// node builder
|
|
553
582
|
|
|
554
|
-
createNodeBuilder( object, renderer ) {
|
|
583
|
+
createNodeBuilder( object, renderer, scene = null ) {
|
|
555
584
|
|
|
556
|
-
return new
|
|
585
|
+
return new WGSLNodeBuilder( object, renderer, scene );
|
|
557
586
|
|
|
558
587
|
}
|
|
559
588
|
|
|
@@ -648,7 +677,6 @@ class WebGPUBackend extends Backend {
|
|
|
648
677
|
|
|
649
678
|
this._configureContext();
|
|
650
679
|
this._setupColorBuffer();
|
|
651
|
-
this._setupDepthBuffer();
|
|
652
680
|
|
|
653
681
|
}
|
|
654
682
|
|
|
@@ -674,40 +702,114 @@ class WebGPUBackend extends Backend {
|
|
|
674
702
|
|
|
675
703
|
}
|
|
676
704
|
|
|
677
|
-
copyFramebufferToTexture(
|
|
705
|
+
copyFramebufferToTexture( texture, renderContext ) {
|
|
678
706
|
|
|
679
707
|
const renderContextData = this.get( renderContext );
|
|
680
708
|
|
|
681
709
|
const { encoder, descriptor } = renderContextData;
|
|
682
710
|
|
|
683
|
-
|
|
684
|
-
|
|
711
|
+
let sourceGPU = null;
|
|
712
|
+
|
|
713
|
+
if ( texture.isFramebufferTexture ) {
|
|
714
|
+
|
|
715
|
+
sourceGPU = this.context.getCurrentTexture();
|
|
716
|
+
|
|
717
|
+
} else if ( texture.isDepthTexture ) {
|
|
718
|
+
|
|
719
|
+
sourceGPU = this._getDepthBufferGPU( renderContext );
|
|
720
|
+
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
const destinationGPU = this.get( texture ).texture;
|
|
685
724
|
|
|
686
725
|
renderContextData.currentPass.end();
|
|
687
726
|
|
|
688
727
|
encoder.copyTextureToTexture(
|
|
689
728
|
{
|
|
690
|
-
|
|
729
|
+
texture: sourceGPU,
|
|
730
|
+
origin: { x: 0, y: 0, z: 0 }
|
|
691
731
|
},
|
|
692
732
|
{
|
|
693
|
-
|
|
733
|
+
texture: destinationGPU
|
|
694
734
|
},
|
|
695
735
|
[
|
|
696
|
-
|
|
697
|
-
|
|
736
|
+
texture.image.width,
|
|
737
|
+
texture.image.height
|
|
698
738
|
]
|
|
699
739
|
);
|
|
700
740
|
|
|
741
|
+
if ( texture.generateMipmaps ) this.textureUtils.generateMipmaps( texture );
|
|
742
|
+
|
|
701
743
|
descriptor.colorAttachments[ 0 ].loadOp = GPULoadOp.Load;
|
|
702
744
|
if ( renderContext.depth ) descriptor.depthStencilAttachment.depthLoadOp = GPULoadOp.Load;
|
|
703
745
|
if ( renderContext.stencil ) descriptor.depthStencilAttachment.stencilLoadOp = GPULoadOp.Load;
|
|
704
746
|
|
|
705
747
|
renderContextData.currentPass = encoder.beginRenderPass( descriptor );
|
|
748
|
+
renderContextData.currentAttributesSet = {};
|
|
706
749
|
|
|
707
750
|
}
|
|
708
751
|
|
|
709
752
|
// utils
|
|
710
753
|
|
|
754
|
+
_getDepthBufferGPU( renderContext ) {
|
|
755
|
+
|
|
756
|
+
const { depthBuffers } = this;
|
|
757
|
+
const { width, height } = this.getDrawingBufferSize();
|
|
758
|
+
|
|
759
|
+
let depthTexture = depthBuffers.get( renderContext );
|
|
760
|
+
|
|
761
|
+
if ( depthTexture !== undefined && depthTexture.image.width === width && depthTexture.image.height === height ) {
|
|
762
|
+
|
|
763
|
+
return this.get( depthTexture ).texture;
|
|
764
|
+
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
this._destroyDepthBufferGPU( renderContext );
|
|
768
|
+
|
|
769
|
+
depthTexture = new DepthTexture();
|
|
770
|
+
depthTexture.name = 'depthBuffer';
|
|
771
|
+
|
|
772
|
+
if ( renderContext.stencil ) {
|
|
773
|
+
|
|
774
|
+
depthTexture = new DepthTexture();
|
|
775
|
+
depthTexture.format = DepthStencilFormat;
|
|
776
|
+
depthTexture.type = UnsignedInt248Type;
|
|
777
|
+
|
|
778
|
+
} else if ( renderContext.depth ) {
|
|
779
|
+
|
|
780
|
+
depthTexture = new DepthTexture();
|
|
781
|
+
depthTexture.format = DepthFormat;
|
|
782
|
+
depthTexture.type = UnsignedIntType;
|
|
783
|
+
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
depthTexture.image.width = width;
|
|
787
|
+
depthTexture.image.height = height;
|
|
788
|
+
|
|
789
|
+
this.textureUtils.createTexture( depthTexture, { sampleCount: this.parameters.sampleCount } );
|
|
790
|
+
|
|
791
|
+
depthBuffers.set( renderContext, depthTexture );
|
|
792
|
+
|
|
793
|
+
return this.get( depthTexture ).texture;
|
|
794
|
+
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
_destroyDepthBufferGPU( renderContext ) {
|
|
798
|
+
|
|
799
|
+
const { depthBuffers } = this;
|
|
800
|
+
|
|
801
|
+
const depthTexture = depthBuffers.get( renderContext );
|
|
802
|
+
|
|
803
|
+
if ( depthTexture !== undefined ) {
|
|
804
|
+
|
|
805
|
+
this.textureUtils.destroyTexture( depthTexture );
|
|
806
|
+
|
|
807
|
+
depthBuffers.delete( renderContext );
|
|
808
|
+
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
}
|
|
812
|
+
|
|
711
813
|
_configureContext() {
|
|
712
814
|
|
|
713
815
|
this.context.configure( {
|
|
@@ -740,26 +842,6 @@ class WebGPUBackend extends Backend {
|
|
|
740
842
|
|
|
741
843
|
}
|
|
742
844
|
|
|
743
|
-
_setupDepthBuffer() {
|
|
744
|
-
|
|
745
|
-
if ( this.depthBuffer ) this.depthBuffer.destroy();
|
|
746
|
-
|
|
747
|
-
const { width, height } = this.getDrawingBufferSize();
|
|
748
|
-
|
|
749
|
-
this.depthBuffer = this.device.createTexture( {
|
|
750
|
-
label: 'depthBuffer',
|
|
751
|
-
size: {
|
|
752
|
-
width: width,
|
|
753
|
-
height: height,
|
|
754
|
-
depthOrArrayLayers: 1
|
|
755
|
-
},
|
|
756
|
-
sampleCount: this.parameters.sampleCount,
|
|
757
|
-
format: GPUTextureFormat.Depth24PlusStencil8,
|
|
758
|
-
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC
|
|
759
|
-
} );
|
|
760
|
-
|
|
761
|
-
}
|
|
762
|
-
|
|
763
845
|
}
|
|
764
846
|
|
|
765
847
|
export default WebGPUBackend;
|