super-three 0.162.0 → 0.164.0

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.
Files changed (187) hide show
  1. package/build/three.cjs +847 -1226
  2. package/build/three.module.js +846 -1225
  3. package/build/three.module.min.js +2 -2
  4. package/examples/jsm/animation/CCDIKSolver.js +4 -2
  5. package/examples/jsm/controls/TransformControls.js +3 -3
  6. package/examples/jsm/exporters/GLTFExporter.js +66 -5
  7. package/examples/jsm/exporters/USDZExporter.js +22 -1
  8. package/examples/jsm/geometries/TextGeometry.js +10 -2
  9. package/examples/jsm/interactive/HTMLMesh.js +7 -9
  10. package/examples/jsm/libs/draco/README.md +2 -2
  11. package/examples/jsm/libs/fflate.module.js +694 -496
  12. package/examples/jsm/lines/LineMaterial.js +0 -2
  13. package/examples/jsm/loaders/3MFLoader.js +2 -0
  14. package/examples/jsm/loaders/EXRLoader.js +351 -97
  15. package/examples/jsm/loaders/FBXLoader.js +1 -1
  16. package/examples/jsm/loaders/GLTFLoader.js +59 -0
  17. package/examples/jsm/loaders/KTX2Loader.js +3 -10
  18. package/examples/jsm/loaders/LUT3dlLoader.js +0 -15
  19. package/examples/jsm/loaders/LUTCubeLoader.js +0 -14
  20. package/examples/jsm/loaders/LUTImageLoader.js +0 -14
  21. package/examples/jsm/loaders/RGBMLoader.js +16 -0
  22. package/examples/jsm/loaders/VRMLLoader.js +1 -1
  23. package/examples/jsm/loaders/lwo/IFFParser.js +8 -5
  24. package/examples/jsm/materials/MeshGouraudMaterial.js +7 -1
  25. package/examples/jsm/math/Octree.js +26 -20
  26. package/examples/jsm/misc/GPUComputationRenderer.js +0 -6
  27. package/examples/jsm/nodes/Nodes.js +10 -4
  28. package/examples/jsm/nodes/accessors/AccessorsUtils.js +16 -1
  29. package/examples/jsm/nodes/accessors/BatchNode.js +78 -0
  30. package/examples/jsm/nodes/accessors/ClippingNode.js +3 -2
  31. package/examples/jsm/nodes/accessors/InstanceNode.js +25 -2
  32. package/examples/jsm/nodes/accessors/MaterialNode.js +107 -3
  33. package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +1 -1
  34. package/examples/jsm/nodes/accessors/MorphNode.js +13 -3
  35. package/examples/jsm/nodes/accessors/NormalNode.js +12 -2
  36. package/examples/jsm/nodes/accessors/ReferenceNode.js +1 -1
  37. package/examples/jsm/nodes/accessors/RendererReferenceNode.js +29 -0
  38. package/examples/jsm/nodes/accessors/StorageBufferNode.js +9 -0
  39. package/examples/jsm/nodes/accessors/TextureNode.js +51 -10
  40. package/examples/jsm/nodes/accessors/TextureSizeNode.js +1 -1
  41. package/examples/jsm/nodes/code/FunctionNode.js +0 -8
  42. package/examples/jsm/nodes/core/Node.js +63 -4
  43. package/examples/jsm/nodes/core/NodeBuilder.js +26 -25
  44. package/examples/jsm/nodes/core/NodeFrame.js +10 -10
  45. package/examples/jsm/nodes/core/NodeUtils.js +2 -2
  46. package/examples/jsm/nodes/core/OutputStructNode.js +2 -1
  47. package/examples/jsm/nodes/core/PropertyNode.js +10 -0
  48. package/examples/jsm/nodes/core/UniformNode.js +20 -0
  49. package/examples/jsm/nodes/display/BumpMapNode.js +7 -26
  50. package/examples/jsm/nodes/display/FrontFacingNode.js +13 -0
  51. package/examples/jsm/nodes/display/PassNode.js +17 -1
  52. package/examples/jsm/nodes/display/ToneMappingNode.js +8 -4
  53. package/examples/jsm/nodes/display/ViewportDepthNode.js +1 -1
  54. package/examples/jsm/nodes/display/ViewportNode.js +4 -2
  55. package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +6 -0
  56. package/examples/jsm/nodes/display/ViewportTextureNode.js +4 -1
  57. package/examples/jsm/nodes/fog/FogExp2Node.js +4 -5
  58. package/examples/jsm/nodes/fog/FogNode.js +13 -3
  59. package/examples/jsm/nodes/fog/FogRangeNode.js +4 -3
  60. package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +26 -7
  61. package/examples/jsm/nodes/functions/BSDF/D_GGX_Anisotropic.js +28 -0
  62. package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +1 -3
  63. package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +29 -0
  64. package/examples/jsm/nodes/functions/PhongLightingModel.js +1 -1
  65. package/examples/jsm/nodes/functions/PhysicalLightingModel.js +164 -10
  66. package/examples/jsm/nodes/functions/ShadowMaskModel.js +31 -0
  67. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +19 -5
  68. package/examples/jsm/nodes/lighting/DirectionalLightNode.js +2 -1
  69. package/examples/jsm/nodes/lighting/EnvironmentNode.js +22 -70
  70. package/examples/jsm/nodes/lighting/IrradianceNode.js +24 -0
  71. package/examples/jsm/nodes/lighting/LightsNode.js +11 -1
  72. package/examples/jsm/nodes/lighting/PointLightNode.js +2 -1
  73. package/examples/jsm/nodes/lighting/SpotLightNode.js +2 -1
  74. package/examples/jsm/nodes/materials/Line2NodeMaterial.js +10 -6
  75. package/examples/jsm/nodes/materials/Materials.js +1 -0
  76. package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +0 -2
  77. package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +2 -2
  78. package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +76 -5
  79. package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +11 -4
  80. package/examples/jsm/nodes/materials/NodeMaterial.js +55 -43
  81. package/examples/jsm/nodes/materials/ShadowNodeMaterial.js +34 -0
  82. package/examples/jsm/nodes/pmrem/PMREMNode.js +193 -0
  83. package/examples/jsm/nodes/pmrem/PMREMUtils.js +288 -0
  84. package/examples/jsm/nodes/shadernode/ShaderNode.js +3 -9
  85. package/examples/jsm/nodes/utils/EquirectUVNode.js +1 -1
  86. package/examples/jsm/objects/QuadMesh.js +7 -23
  87. package/examples/jsm/physics/JoltPhysics.js +281 -0
  88. package/examples/jsm/physics/RapierPhysics.js +4 -4
  89. package/examples/jsm/postprocessing/GlitchPass.js +0 -3
  90. package/examples/jsm/postprocessing/LUTPass.js +5 -71
  91. package/examples/jsm/postprocessing/RenderTransitionPass.js +193 -0
  92. package/examples/jsm/postprocessing/SAOPass.js +0 -1
  93. package/examples/jsm/postprocessing/SSAOPass.js +0 -3
  94. package/examples/jsm/renderers/common/Animation.js +3 -0
  95. package/examples/jsm/renderers/common/Background.js +8 -8
  96. package/examples/jsm/renderers/common/ClippingContext.js +1 -1
  97. package/examples/jsm/renderers/common/Info.js +11 -19
  98. package/examples/jsm/renderers/common/PostProcessing.js +12 -4
  99. package/examples/jsm/renderers/common/RenderContext.js +1 -1
  100. package/examples/jsm/renderers/common/RenderList.js +1 -1
  101. package/examples/jsm/renderers/common/RenderObject.js +47 -5
  102. package/examples/jsm/renderers/common/RenderObjects.js +1 -1
  103. package/examples/jsm/renderers/common/Renderer.js +153 -21
  104. package/examples/jsm/renderers/common/Textures.js +1 -1
  105. package/examples/jsm/renderers/common/extras/PMREMGenerator.js +773 -0
  106. package/examples/jsm/renderers/common/nodes/Nodes.js +34 -63
  107. package/examples/jsm/renderers/webgl/WebGLBackend.js +146 -36
  108. package/examples/jsm/renderers/webgl/WebGLBufferRenderer.js +145 -0
  109. package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +9 -3
  110. package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +1 -1
  111. package/examples/jsm/renderers/webgl/utils/WebGLConstants.js +1 -0
  112. package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +64 -7
  113. package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +6 -23
  114. package/examples/jsm/renderers/webgpu/WebGPUBackend.js +77 -60
  115. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +21 -4
  116. package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +29 -1
  117. package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +18 -4
  118. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +92 -18
  119. package/examples/jsm/transpiler/GLSLDecoder.js +1 -1
  120. package/examples/jsm/transpiler/ShaderToyDecoder.js +1 -1
  121. package/examples/jsm/utils/GPUStatsPanel.js +10 -45
  122. package/examples/jsm/utils/SceneUtils.js +60 -1
  123. package/examples/jsm/utils/TextureUtils.js +1 -1
  124. package/examples/jsm/webxr/OculusHandModel.js +3 -2
  125. package/examples/jsm/webxr/XRHandModelFactory.js +4 -2
  126. package/package.json +1 -1
  127. package/src/Three.js +0 -1
  128. package/src/animation/AnimationClip.js +1 -1
  129. package/src/constants.js +3 -3
  130. package/src/core/Object3D.js +10 -7
  131. package/src/core/RenderTarget.js +8 -0
  132. package/src/extras/PMREMGenerator.js +21 -11
  133. package/src/loaders/FileLoader.js +1 -1
  134. package/src/loaders/MaterialLoader.js +1 -0
  135. package/src/loaders/ObjectLoader.js +2 -0
  136. package/src/materials/Material.js +2 -0
  137. package/src/materials/MeshPhysicalMaterial.js +20 -0
  138. package/src/materials/ShaderMaterial.js +0 -4
  139. package/src/math/Spherical.js +4 -5
  140. package/src/objects/BatchedMesh.js +27 -3
  141. package/src/objects/InstancedMesh.js +10 -0
  142. package/src/objects/Line.js +66 -43
  143. package/src/renderers/WebGLRenderer.js +130 -158
  144. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +6 -0
  145. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +1 -0
  146. package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +2 -2
  147. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +1 -1
  148. package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +2 -10
  149. package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +2 -16
  150. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +32 -22
  151. package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +17 -9
  152. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
  153. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +47 -13
  154. package/src/renderers/shaders/ShaderChunk.js +0 -2
  155. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -0
  156. package/src/renderers/shaders/ShaderLib.js +2 -1
  157. package/src/renderers/shaders/UniformsUtils.js +10 -1
  158. package/src/renderers/webgl/WebGLAttributes.js +6 -33
  159. package/src/renderers/webgl/WebGLBackground.js +18 -3
  160. package/src/renderers/webgl/WebGLBindingStates.js +14 -51
  161. package/src/renderers/webgl/WebGLBufferRenderer.js +35 -21
  162. package/src/renderers/webgl/WebGLCapabilities.js +35 -13
  163. package/src/renderers/webgl/WebGLCubeUVMaps.js +10 -6
  164. package/src/renderers/webgl/WebGLExtensions.js +4 -19
  165. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +35 -21
  166. package/src/renderers/webgl/WebGLLights.js +6 -32
  167. package/src/renderers/webgl/WebGLMaterials.js +8 -3
  168. package/src/renderers/webgl/WebGLMorphtargets.js +79 -217
  169. package/src/renderers/webgl/WebGLProgram.js +21 -52
  170. package/src/renderers/webgl/WebGLPrograms.js +24 -31
  171. package/src/renderers/webgl/WebGLRenderStates.js +13 -7
  172. package/src/renderers/webgl/WebGLShadowMap.js +25 -25
  173. package/src/renderers/webgl/WebGLState.js +15 -59
  174. package/src/renderers/webgl/WebGLTextures.js +138 -292
  175. package/src/renderers/webgl/WebGLUniformsGroups.js +1 -1
  176. package/src/renderers/webgl/WebGLUtils.js +9 -78
  177. package/src/renderers/webxr/WebXRDepthSensing.js +2 -3
  178. package/src/renderers/webxr/WebXRManager.js +4 -6
  179. package/src/scenes/Scene.js +7 -1
  180. package/src/textures/Texture.js +11 -1
  181. package/examples/jsm/nodes/utils/SpecularMIPLevelNode.js +0 -37
  182. package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +0 -320
  183. package/examples/jsm/renderers/webgl-legacy/nodes/SlotNode.js +0 -26
  184. package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +0 -794
  185. package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodes.js +0 -51
  186. package/src/renderers/WebGL1Renderer.js +0 -7
  187. package/src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl.js +0 -10
@@ -1,794 +0,0 @@
1
- import { defaultShaderStages, NodeFrame, MathNode, GLSLNodeParser, NodeBuilder, normalView } from '../../../nodes/Nodes.js';
2
- import SlotNode from './SlotNode.js';
3
- import { PerspectiveCamera, ShaderChunk, ShaderLib, UniformsUtils, UniformsLib } from 'three';
4
-
5
- const nodeFrame = new NodeFrame();
6
- nodeFrame.camera = new PerspectiveCamera();
7
-
8
- const nodeShaderLib = {
9
- LineBasicNodeMaterial: ShaderLib.basic,
10
- MeshBasicNodeMaterial: ShaderLib.basic,
11
- PointsNodeMaterial: ShaderLib.points,
12
- MeshStandardNodeMaterial: ShaderLib.standard,
13
- MeshPhysicalNodeMaterial: ShaderLib.physical,
14
- MeshPhongNodeMaterial: ShaderLib.phong
15
- };
16
-
17
- const glslMethods = {
18
- [ MathNode.ATAN2 ]: 'atan'
19
- };
20
-
21
- const precisionLib = {
22
- low: 'lowp',
23
- medium: 'mediump',
24
- high: 'highp'
25
- };
26
-
27
- function getIncludeSnippet( name ) {
28
-
29
- return `#include <${name}>`;
30
-
31
- }
32
-
33
- function getShaderStageProperty( shaderStage ) {
34
-
35
- return `${shaderStage}Shader`;
36
-
37
- }
38
-
39
- class WebGLNodeBuilder extends NodeBuilder {
40
-
41
- constructor( object, renderer, shader, material = null ) {
42
-
43
- super( object, renderer, new GLSLNodeParser(), null, material );
44
-
45
- this.shader = shader;
46
- this.slots = { vertex: [], fragment: [] };
47
-
48
- this._parseShaderLib();
49
- this._parseInclude( 'fragment', 'lights_physical_fragment', 'clearcoat_normal_fragment_begin', 'transmission_fragment' );
50
- this._parseObject();
51
-
52
- this._sortSlotsToFlow();
53
-
54
- }
55
-
56
- getMethod( method ) {
57
-
58
- return glslMethods[ method ] || method;
59
-
60
- }
61
-
62
- addSlot( shaderStage, slotNode ) {
63
-
64
- this.slots[ shaderStage ].push( slotNode );
65
-
66
- }
67
-
68
- _parseShaderLib() {
69
-
70
- const material = this.material;
71
-
72
- let type = material.type;
73
-
74
- // see https://github.com/mrdoob/three.js/issues/23707
75
-
76
- if ( material.isMeshPhysicalNodeMaterial ) type = 'MeshPhysicalNodeMaterial';
77
- else if ( material.isMeshStandardNodeMaterial ) type = 'MeshStandardNodeMaterial';
78
- else if ( material.isMeshPhongNodeMaterial ) type = 'MeshPhongNodeMaterial';
79
- else if ( material.isMeshBasicNodeMaterial ) type = 'MeshBasicNodeMaterial';
80
- else if ( material.isPointsNodeMaterial ) type = 'PointsNodeMaterial';
81
- else if ( material.isLineBasicNodeMaterial ) type = 'LineBasicNodeMaterial';
82
-
83
- // shader lib
84
-
85
- if ( nodeShaderLib[ type ] !== undefined ) {
86
-
87
- const shaderLib = nodeShaderLib[ type ];
88
- const shader = this.shader;
89
-
90
- shader.vertexShader = shaderLib.vertexShader;
91
- shader.fragmentShader = shaderLib.fragmentShader;
92
- shader.uniforms = UniformsUtils.merge( [ shaderLib.uniforms, UniformsLib.lights ] );
93
-
94
- }
95
-
96
- }
97
-
98
- _parseObject() {
99
-
100
- const { material, renderer } = this;
101
-
102
- this.addSlot( 'fragment', new SlotNode( {
103
- node: normalView,
104
- nodeType: 'vec3',
105
- source: 'void main() {',
106
- target: 'vec3 TransformedNormalView = %RESULT%;',
107
- inclusionType: 'append'
108
- } ) );
109
-
110
- if ( renderer.toneMappingNode && renderer.toneMappingNode.isNode === true ) {
111
-
112
- this.addSlot( 'fragment', new SlotNode( {
113
- node: material.colorNode,
114
- nodeType: 'vec4',
115
- source: getIncludeSnippet( 'tonemapping_fragment' ),
116
- target: ''
117
- } ) );
118
-
119
- }
120
-
121
- // parse inputs
122
-
123
- if ( material.colorNode && material.colorNode.isNode ) {
124
-
125
- this.addSlot( 'fragment', new SlotNode( {
126
- node: material.colorNode,
127
- nodeType: 'vec4',
128
- source: 'vec4 diffuseColor = vec4( diffuse, opacity );',
129
- target: 'vec4 diffuseColor = %RESULT%; diffuseColor.a *= opacity;',
130
- } ) );
131
-
132
- }
133
-
134
- if ( material.opacityNode && material.opacityNode.isNode ) {
135
-
136
- this.addSlot( 'fragment', new SlotNode( {
137
- node: material.opacityNode,
138
- nodeType: 'float',
139
- source: getIncludeSnippet( 'alphatest_fragment' ),
140
- target: 'diffuseColor.a = %RESULT%;',
141
- inclusionType: 'append'
142
- } ) );
143
-
144
- }
145
-
146
- if ( material.normalNode && material.normalNode.isNode ) {
147
-
148
- this.addSlot( 'fragment', new SlotNode( {
149
- node: material.normalNode,
150
- nodeType: 'vec3',
151
- source: getIncludeSnippet( 'normal_fragment_begin' ),
152
- target: 'normal = %RESULT%;',
153
- inclusionType: 'append'
154
- } ) );
155
-
156
- }
157
-
158
- if ( material.emissiveNode && material.emissiveNode.isNode ) {
159
-
160
- this.addSlot( 'fragment', new SlotNode( {
161
- node: material.emissiveNode,
162
- nodeType: 'vec3',
163
- source: getIncludeSnippet( 'emissivemap_fragment' ),
164
- target: 'totalEmissiveRadiance = %RESULT%;',
165
- inclusionType: 'append'
166
- } ) );
167
-
168
- }
169
-
170
- if ( material.isMeshStandardNodeMaterial ) {
171
-
172
- if ( material.metalnessNode && material.metalnessNode.isNode ) {
173
-
174
- this.addSlot( 'fragment', new SlotNode( {
175
- node: material.metalnessNode,
176
- nodeType: 'float',
177
- source: getIncludeSnippet( 'metalnessmap_fragment' ),
178
- target: 'metalnessFactor = %RESULT%;',
179
- inclusionType: 'append'
180
- } ) );
181
-
182
- }
183
-
184
- if ( material.roughnessNode && material.roughnessNode.isNode ) {
185
-
186
- this.addSlot( 'fragment', new SlotNode( {
187
- node: material.roughnessNode,
188
- nodeType: 'float',
189
- source: getIncludeSnippet( 'roughnessmap_fragment' ),
190
- target: 'roughnessFactor = %RESULT%;',
191
- inclusionType: 'append'
192
- } ) );
193
-
194
- }
195
-
196
- if ( material.isMeshPhysicalNodeMaterial ) {
197
-
198
- if ( material.clearcoatNode && material.clearcoatNode.isNode ) {
199
-
200
- this.addSlot( 'fragment', new SlotNode( {
201
- node: material.clearcoatNode,
202
- nodeType: 'float',
203
- source: 'material.clearcoat = clearcoat;',
204
- target: 'material.clearcoat = %RESULT%;'
205
- } ) );
206
-
207
- if ( material.clearcoatRoughnessNode && material.clearcoatRoughnessNode.isNode ) {
208
-
209
- this.addSlot( 'fragment', new SlotNode( {
210
- node: material.clearcoatRoughnessNode,
211
- nodeType: 'float',
212
- source: 'material.clearcoatRoughness = clearcoatRoughness;',
213
- target: 'material.clearcoatRoughness = %RESULT%;'
214
- } ) );
215
-
216
- }
217
-
218
- if ( material.clearcoatNormalNode && material.clearcoatNormalNode.isNode ) {
219
-
220
- this.addSlot( 'fragment', new SlotNode( {
221
- node: material.clearcoatNormalNode,
222
- nodeType: 'vec3',
223
- source: 'vec3 clearcoatNormal = nonPerturbedNormal;',
224
- target: 'vec3 clearcoatNormal = %RESULT%;'
225
- } ) );
226
-
227
- }
228
-
229
- material.defines.USE_CLEARCOAT = '';
230
-
231
- } else {
232
-
233
- delete material.defines.USE_CLEARCOAT;
234
-
235
- }
236
-
237
- if ( material.sheenNode && material.sheenNode.isNode ) {
238
-
239
- this.addSlot( 'fragment', new SlotNode( {
240
- node: material.sheenNode,
241
- nodeType: 'vec3',
242
- source: 'material.sheenColor = sheenColor;',
243
- target: 'material.sheenColor = %RESULT%;'
244
- } ) );
245
-
246
- if ( material.sheenRoughnessNode && material.sheenRoughnessNode.isNode ) {
247
-
248
- this.addSlot( 'fragment', new SlotNode( {
249
- node: material.sheenRoughnessNode,
250
- nodeType: 'float',
251
- source: 'material.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 );',
252
- target: 'material.sheenRoughness = clamp( %RESULT%, 0.07, 1.0 );'
253
- } ) );
254
-
255
- }
256
-
257
- material.defines.USE_SHEEN = '';
258
-
259
- } else {
260
-
261
- delete material.defines.USE_SHEEN;
262
-
263
- }
264
-
265
- if ( material.iridescenceNode && material.iridescenceNode.isNode ) {
266
-
267
- this.addSlot( 'fragment', new SlotNode( {
268
- node: material.iridescenceNode,
269
- nodeType: 'float',
270
- source: 'material.iridescence = iridescence;',
271
- target: 'material.iridescence = %RESULT%;'
272
- } ) );
273
-
274
- if ( material.iridescenceIORNode && material.iridescenceIORNode.isNode ) {
275
-
276
- this.addSlot( 'fragment', new SlotNode( {
277
- node: material.iridescenceIORNode,
278
- nodeType: 'float',
279
- source: 'material.iridescenceIOR = iridescenceIOR;',
280
- target: 'material.iridescenceIOR = %RESULT%;'
281
- } ) );
282
-
283
- }
284
-
285
- if ( material.iridescenceThicknessNode && material.iridescenceThicknessNode.isNode ) {
286
-
287
- this.addSlot( 'fragment', new SlotNode( {
288
- node: material.iridescenceThicknessNode,
289
- nodeType: 'float',
290
- source: 'material.iridescenceThickness = iridescenceThicknessMaximum;',
291
- target: 'material.iridescenceThickness = %RESULT%;'
292
- } ) );
293
-
294
- }
295
-
296
- material.defines.USE_IRIDESCENCE = '';
297
-
298
- } else {
299
-
300
- delete material.defines.USE_IRIDESCENCE;
301
-
302
- }
303
-
304
- if ( material.iorNode && material.iorNode.isNode ) {
305
-
306
- this.addSlot( 'fragment', new SlotNode( {
307
- node: material.iorNode,
308
- nodeType: 'float',
309
- source: 'material.ior = ior;',
310
- target: 'material.ior = %RESULT%;'
311
- } ) );
312
-
313
- }
314
-
315
- if ( material.specularColorNode && material.specularColorNode.isNode ) {
316
-
317
- this.addSlot( 'fragment', new SlotNode( {
318
- node: material.specularColorNode,
319
- nodeType: 'vec3',
320
- source: 'vec3 specularColorFactor = specularColor;',
321
- target: 'vec3 specularColorFactor = %RESULT%;'
322
- } ) );
323
-
324
- }
325
-
326
- if ( material.specularIntensityNode && material.specularIntensityNode.isNode ) {
327
-
328
- this.addSlot( 'fragment', new SlotNode( {
329
- node: material.specularIntensityNode,
330
- nodeType: 'float',
331
- source: 'float specularIntensityFactor = specularIntensity;',
332
- target: 'float specularIntensityFactor = %RESULT%;'
333
- } ) );
334
-
335
- }
336
-
337
- if ( material.transmissionNode && material.transmissionNode.isNode ) {
338
-
339
- this.addSlot( 'fragment', new SlotNode( {
340
- node: material.transmissionNode,
341
- nodeType: 'float',
342
- source: 'material.transmission = transmission;',
343
- target: 'material.transmission = %RESULT%;'
344
- } ) );
345
-
346
- if ( material.thicknessNode && material.thicknessNode.isNode ) {
347
-
348
- this.addSlot( 'fragment', new SlotNode( {
349
- node: material.thicknessNode,
350
- nodeType: 'float',
351
- source: 'material.thickness = thickness;',
352
- target: 'material.thickness = %RESULT%;'
353
- } ) );
354
-
355
- }
356
-
357
- if ( material.attenuationDistanceNode && material.attenuationDistanceNode.isNode ) {
358
-
359
- this.addSlot( 'fragment', new SlotNode( {
360
- node: material.attenuationDistanceNode,
361
- nodeType: 'float',
362
- source: 'material.attenuationDistance = attenuationDistance;',
363
- target: 'material.attenuationDistance = %RESULT%;'
364
- } ) );
365
-
366
- }
367
-
368
- if ( material.attenuationColorNode && material.attenuationColorNode.isNode ) {
369
-
370
- this.addSlot( 'fragment', new SlotNode( {
371
- node: material.attenuationColorNode,
372
- nodeType: 'vec3',
373
- source: 'material.attenuationColor = attenuationColor;',
374
- target: 'material.attenuationColor = %RESULT%;'
375
- } ) );
376
-
377
- }
378
-
379
- material.transmission = 1;
380
- material.defines.USE_TRANSMISSION = '';
381
-
382
- } else {
383
-
384
- material.transmission = 0;
385
- delete material.defines.USE_TRANSMISSION;
386
-
387
- }
388
-
389
- }
390
-
391
- }
392
-
393
- //
394
-
395
- if ( material.positionNode && material.positionNode.isNode ) {
396
-
397
- this.addSlot( 'vertex', new SlotNode( {
398
- node: material.positionNode,
399
- nodeType: 'vec3',
400
- source: getIncludeSnippet( 'begin_vertex' ),
401
- target: 'transformed = %RESULT%;',
402
- inclusionType: 'append'
403
- } ) );
404
-
405
- }
406
-
407
- if ( material.sizeNode && material.sizeNode.isNode ) {
408
-
409
- this.addSlot( 'vertex', new SlotNode( {
410
- node: material.sizeNode,
411
- nodeType: 'float',
412
- source: 'gl_PointSize = size;',
413
- target: 'gl_PointSize = %RESULT%;'
414
- } ) );
415
-
416
- }
417
-
418
- }
419
-
420
- generateTexture( texture, textureProperty, uvSnippet ) {
421
-
422
- if ( texture.isTextureCube ) {
423
-
424
- return `textureCube( ${textureProperty}, ${uvSnippet} )`;
425
-
426
- } else {
427
-
428
- return `texture2D( ${textureProperty}, ${uvSnippet} )`;
429
-
430
- }
431
-
432
- }
433
-
434
- generateTextureLevel( texture, textureProperty, uvSnippet, biasSnippet ) {
435
-
436
- if ( this.material.extensions !== undefined ) this.material.extensions.shaderTextureLOD = true;
437
-
438
- return `textureLod( ${textureProperty}, ${uvSnippet}, ${biasSnippet} )`;
439
-
440
- }
441
-
442
- buildFunctionCode( shaderNode ) {
443
-
444
- const layout = shaderNode.layout;
445
- const flowData = this.flowShaderNode( shaderNode );
446
-
447
- const parameters = [];
448
-
449
- for ( const input of layout.inputs ) {
450
-
451
- parameters.push( this.getType( input.type ) + ' ' + input.name );
452
-
453
- }
454
-
455
- //
456
-
457
- const code = `${ this.getType( layout.type ) } ${ layout.name }( ${ parameters.join( ', ' ) } ) {
458
-
459
- ${ flowData.vars }
460
-
461
- ${ flowData.code }
462
- return ${ flowData.result };
463
-
464
- }`;
465
-
466
- //
467
-
468
- return code;
469
-
470
- }
471
-
472
- getUniforms( shaderStage ) {
473
-
474
- const uniforms = this.uniforms[ shaderStage ];
475
-
476
- let output = '';
477
-
478
- for ( const uniform of uniforms ) {
479
-
480
- if ( /^(modelViewMatrix|projectionMatrix)$/.test( uniform.name ) )
481
- continue;
482
-
483
- let snippet = null;
484
-
485
- if ( uniform.type === 'texture' ) {
486
-
487
- snippet = `sampler2D ${uniform.name}; `;
488
-
489
- } else if ( uniform.type === 'cubeTexture' ) {
490
-
491
- snippet = `samplerCube ${uniform.name}; `;
492
-
493
- } else {
494
-
495
- const vectorType = this.getVectorType( uniform.type );
496
-
497
- snippet = `${vectorType} ${uniform.name}; `;
498
-
499
- }
500
-
501
- const precision = uniform.node.precision;
502
-
503
- if ( precision !== null ) {
504
-
505
- snippet = 'uniform ' + precisionLib[ precision ] + ' ' + snippet;
506
-
507
- } else {
508
-
509
- snippet = 'uniform ' + snippet;
510
-
511
- }
512
-
513
- output += snippet;
514
-
515
- }
516
-
517
- return output;
518
-
519
- }
520
-
521
- getAttributes( shaderStage ) {
522
-
523
- let snippet = '';
524
-
525
- if ( shaderStage === 'vertex' ) {
526
-
527
- const attributes = this.attributes;
528
-
529
- for ( const attribute of attributes ) {
530
-
531
- // ignore common attributes to prevent redefinitions
532
- if ( /^(position|normal|uv[1-3]?)$/.test( attribute.name ) )
533
- continue;
534
-
535
- snippet += `attribute ${attribute.type} ${attribute.name}; `;
536
-
537
- }
538
-
539
- }
540
-
541
- return snippet;
542
-
543
- }
544
-
545
- getVaryings( shaderStage ) {
546
-
547
- let snippet = '';
548
-
549
- const varyings = this.varyings;
550
-
551
- if ( shaderStage === 'vertex' ) {
552
-
553
- for ( const varying of varyings ) {
554
-
555
- snippet += `${varying.needsInterpolation ? 'varying' : '/*varying*/'} ${varying.type} ${varying.name}; `;
556
-
557
- }
558
-
559
- } else if ( shaderStage === 'fragment' ) {
560
-
561
- for ( const varying of varyings ) {
562
-
563
- if ( varying.needsInterpolation ) {
564
-
565
- snippet += `varying ${varying.type} ${varying.name}; `;
566
-
567
- }
568
-
569
- }
570
-
571
- }
572
-
573
- return snippet;
574
-
575
- }
576
-
577
- addCode( shaderStage, source, code, scope = this ) {
578
-
579
- const shaderProperty = getShaderStageProperty( shaderStage );
580
-
581
- let snippet = scope[ shaderProperty ];
582
-
583
- const index = snippet.indexOf( source );
584
-
585
- if ( index !== - 1 ) {
586
-
587
- const start = snippet.substring( 0, index + source.length );
588
- const end = snippet.substring( index + source.length );
589
-
590
- snippet = `${start}\n${code}\n${end}`;
591
-
592
- }
593
-
594
- scope[ shaderProperty ] = snippet;
595
-
596
- }
597
-
598
- replaceCode( shaderStage, source, target, scope = this ) {
599
-
600
- const shaderProperty = getShaderStageProperty( shaderStage );
601
-
602
- scope[ shaderProperty ] = scope[ shaderProperty ].replaceAll( source, target );
603
-
604
- }
605
-
606
- getVertexIndex() {
607
-
608
- return 'gl_VertexID';
609
-
610
- }
611
-
612
- getFrontFacing() {
613
-
614
- return 'gl_FrontFacing';
615
-
616
- }
617
-
618
- getFragCoord() {
619
-
620
- return 'gl_FragCoord';
621
-
622
- }
623
-
624
- isFlipY() {
625
-
626
- return true;
627
-
628
- }
629
-
630
- buildCode() {
631
-
632
- const shaderData = {};
633
-
634
- for ( const shaderStage of defaultShaderStages ) {
635
-
636
- const uniforms = this.getUniforms( shaderStage );
637
- const attributes = this.getAttributes( shaderStage );
638
- const varyings = this.getVaryings( shaderStage );
639
- const vars = this.getVars( shaderStage );
640
- const codes = this.getCodes( shaderStage );
641
-
642
- shaderData[ shaderStage ] = `${this.getSignature()}
643
- // <node_builder>
644
-
645
- // uniforms
646
- ${uniforms}
647
-
648
- // attributes
649
- ${attributes}
650
-
651
- // varyings
652
- ${varyings}
653
-
654
- // vars
655
- ${vars}
656
-
657
- // codes
658
- ${codes}
659
-
660
- // </node_builder>
661
-
662
- ${this.shader[ getShaderStageProperty( shaderStage ) ]}
663
- `;
664
-
665
- }
666
-
667
- this.vertexShader = shaderData.vertex;
668
- this.fragmentShader = shaderData.fragment;
669
-
670
- }
671
-
672
- build() {
673
-
674
- super.build( false );
675
-
676
- this._addSnippets();
677
- this._addUniforms();
678
-
679
- this._updateUniforms();
680
-
681
- this.shader.vertexShader = this.vertexShader;
682
- this.shader.fragmentShader = this.fragmentShader;
683
-
684
- return this;
685
-
686
- }
687
-
688
- _parseInclude( shaderStage, ...includes ) {
689
-
690
- for ( const name of includes ) {
691
-
692
- const includeSnippet = getIncludeSnippet( name );
693
- const code = ShaderChunk[ name ];
694
-
695
- const shaderProperty = getShaderStageProperty( shaderStage );
696
-
697
- this.shader[ shaderProperty ] = this.shader[ shaderProperty ].replaceAll( includeSnippet, code );
698
-
699
- }
700
-
701
- }
702
-
703
- _sortSlotsToFlow() {
704
-
705
- for ( const shaderStage of defaultShaderStages ) {
706
-
707
- const sourceCode = this.shader[ getShaderStageProperty( shaderStage ) ];
708
-
709
- const slots = this.slots[ shaderStage ].sort( ( slotA, slotB ) => {
710
-
711
- return sourceCode.indexOf( slotA.source ) > sourceCode.indexOf( slotB.source ) ? 1 : - 1;
712
-
713
- } );
714
-
715
- for ( const slotNode of slots ) {
716
-
717
- this.addFlow( shaderStage, slotNode );
718
-
719
- }
720
-
721
- }
722
-
723
- }
724
-
725
- _addSnippets() {
726
-
727
- for ( const shaderStage of defaultShaderStages ) {
728
-
729
- for ( const slotNode of this.slots[ shaderStage ] ) {
730
-
731
- const flowData = this.getFlowData( slotNode/*, shaderStage*/ );
732
-
733
- const inclusionType = slotNode.inclusionType;
734
- const source = slotNode.source;
735
- const target = flowData.code + '\n\t' + slotNode.target.replace( '%RESULT%', flowData.result );
736
-
737
- if ( inclusionType === 'append' ) {
738
-
739
- this.addCode( shaderStage, source, target );
740
-
741
- } else if ( inclusionType === 'replace' ) {
742
-
743
- this.replaceCode( shaderStage, source, target );
744
-
745
- } else {
746
-
747
- console.warn( `Inclusion type "${ inclusionType }" not compatible.` );
748
-
749
- }
750
-
751
- }
752
-
753
- this.addCode(
754
- shaderStage,
755
- 'main() {',
756
- '\n\t' + this.flowCode[ shaderStage ]
757
- );
758
-
759
- }
760
-
761
- }
762
-
763
- _addUniforms() {
764
-
765
- for ( const shaderStage of defaultShaderStages ) {
766
-
767
- // uniforms
768
-
769
- for ( const uniform of this.uniforms[ shaderStage ] ) {
770
-
771
- this.shader.uniforms[ uniform.name ] = uniform;
772
-
773
- }
774
-
775
- }
776
-
777
- }
778
-
779
- _updateUniforms() {
780
-
781
- nodeFrame.object = this.object;
782
- nodeFrame.renderer = this.renderer;
783
-
784
- for ( const node of this.updateNodes ) {
785
-
786
- nodeFrame.updateNode( node );
787
-
788
- }
789
-
790
- }
791
-
792
- }
793
-
794
- export { WebGLNodeBuilder };