super-three 0.133.5 → 0.135.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 (246) hide show
  1. package/build/three.js +617 -536
  2. package/build/three.min.js +1 -1
  3. package/build/three.module.js +760 -613
  4. package/examples/fonts/open-sans/open-sans-v15-cyrillic-ext_greek_greek-ext_cyrillic_latin_latin-ext_vietnamese-regular.woff +0 -0
  5. package/examples/fonts/open-sans/open-sans-v15-cyrillic-ext_greek_greek-ext_cyrillic_latin_latin-ext_vietnamese-regular.woff2 +0 -0
  6. package/examples/fonts/open-sans/open-sans.css +9 -0
  7. package/examples/fonts/tabler-icons/fonts/tabler-icons.eot +0 -0
  8. package/examples/fonts/tabler-icons/fonts/tabler-icons.ttf +0 -0
  9. package/examples/fonts/tabler-icons/fonts/tabler-icons.woff +0 -0
  10. package/examples/fonts/tabler-icons/fonts/tabler-icons.woff2 +0 -0
  11. package/examples/fonts/tabler-icons/tabler-icons.min.css +4 -0
  12. package/examples/js/controls/ArcballControls.js +68 -27
  13. package/examples/js/controls/DragControls.js +7 -0
  14. package/examples/js/controls/OrbitControls.js +5 -36
  15. package/examples/js/controls/TrackballControls.js +3 -2
  16. package/examples/js/csm/CSM.js +2 -2
  17. package/examples/js/csm/CSMFrustum.js +133 -0
  18. package/examples/js/exporters/GLTFExporter.js +147 -63
  19. package/examples/js/exporters/USDZExporter.js +45 -26
  20. package/examples/js/lines/LineMaterial.js +58 -20
  21. package/examples/js/lines/LineSegments2.js +29 -24
  22. package/examples/js/loaders/3DMLoader.js +24 -11
  23. package/examples/js/loaders/3MFLoader.js +2 -2
  24. package/examples/js/loaders/ColladaLoader.js +61 -3
  25. package/examples/js/loaders/FBXLoader.js +1 -1
  26. package/examples/js/loaders/GLTFLoader.js +94 -31
  27. package/examples/js/loaders/KTX2Loader.js +12 -0
  28. package/examples/js/loaders/LWOLoader.js +8 -6
  29. package/examples/js/loaders/LogLuvLoader.js +766 -0
  30. package/examples/js/loaders/PLYLoader.js +32 -7
  31. package/examples/js/loaders/RGBELoader.js +2 -1
  32. package/examples/js/loaders/SVGLoader.js +7 -3
  33. package/examples/js/loaders/TDSLoader.js +237 -271
  34. package/examples/js/loaders/lwo/LWO2Parser.js +1 -0
  35. package/examples/js/loaders/lwo/LWO3Parser.js +4 -2
  36. package/examples/js/objects/MarchingCubes.js +42 -128
  37. package/examples/js/renderers/CSS2DRenderer.js +4 -4
  38. package/examples/js/renderers/CSS3DRenderer.js +4 -4
  39. package/examples/js/utils/RoughnessMipmapper.js +1 -0
  40. package/examples/jsm/controls/ArcballControls.js +61 -29
  41. package/examples/jsm/controls/DragControls.js +7 -0
  42. package/examples/jsm/controls/OrbitControls.js +9 -51
  43. package/examples/jsm/controls/TrackballControls.js +1 -1
  44. package/examples/jsm/csm/CSM.js +3 -3
  45. package/examples/jsm/csm/{Frustum.js → CSMFrustum.js} +3 -3
  46. package/examples/jsm/exporters/GLTFExporter.js +160 -74
  47. package/examples/jsm/exporters/USDZExporter.js +47 -26
  48. package/examples/jsm/libs/flow.module.js +3218 -0
  49. package/examples/jsm/libs/lil-gui.module.min.js +8 -0
  50. package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
  51. package/examples/jsm/lines/LineMaterial.js +59 -23
  52. package/examples/jsm/lines/LineSegments2.js +22 -18
  53. package/examples/jsm/loaders/3DMLoader.js +18 -12
  54. package/examples/jsm/loaders/3MFLoader.js +2 -2
  55. package/examples/jsm/loaders/ColladaLoader.js +61 -3
  56. package/examples/jsm/loaders/FBXLoader.js +1 -1
  57. package/examples/jsm/loaders/GLTFLoader.js +99 -35
  58. package/examples/jsm/loaders/KTX2Loader.js +19 -0
  59. package/examples/jsm/loaders/LWOLoader.js +8 -6
  60. package/examples/jsm/loaders/LogLuvLoader.js +606 -0
  61. package/examples/jsm/loaders/PLYLoader.js +33 -7
  62. package/examples/jsm/loaders/SVGLoader.js +7 -4
  63. package/examples/jsm/loaders/TDSLoader.js +225 -285
  64. package/examples/jsm/loaders/lwo/LWO2Parser.js +1 -0
  65. package/examples/jsm/loaders/lwo/LWO3Parser.js +2 -2
  66. package/examples/jsm/node-editor/NodeEditor.js +455 -0
  67. package/examples/jsm/node-editor/accessors/NormalEditor.js +30 -0
  68. package/examples/jsm/node-editor/accessors/PositionEditor.js +30 -0
  69. package/examples/jsm/node-editor/accessors/UVEditor.js +26 -0
  70. package/examples/jsm/node-editor/display/BlendEditor.js +43 -0
  71. package/examples/jsm/node-editor/examples/animate-uv.json +1 -0
  72. package/examples/jsm/node-editor/examples/fake-top-light.json +1 -0
  73. package/examples/jsm/node-editor/examples/oscillator-color.json +1 -0
  74. package/examples/jsm/node-editor/examples/rim.json +1 -0
  75. package/examples/jsm/node-editor/inputs/ColorEditor.js +91 -0
  76. package/examples/jsm/node-editor/inputs/FloatEditor.js +24 -0
  77. package/examples/jsm/node-editor/inputs/SliderEditor.js +68 -0
  78. package/examples/jsm/node-editor/inputs/Vector2Editor.js +28 -0
  79. package/examples/jsm/node-editor/inputs/Vector3Editor.js +30 -0
  80. package/examples/jsm/node-editor/inputs/Vector4Editor.js +37 -0
  81. package/examples/jsm/node-editor/materials/StandardMaterialEditor.js +69 -0
  82. package/examples/jsm/node-editor/math/DotEditor.js +36 -0
  83. package/examples/jsm/node-editor/math/InvertEditor.js +38 -0
  84. package/examples/jsm/node-editor/math/LimiterEditor.js +48 -0
  85. package/examples/jsm/node-editor/math/NormalizeEditor.js +26 -0
  86. package/examples/jsm/node-editor/math/OperatorEditor.js +50 -0
  87. package/examples/jsm/node-editor/math/PowerEditor.js +34 -0
  88. package/examples/jsm/node-editor/math/TrigonometryEditor.js +39 -0
  89. package/examples/jsm/node-editor/procedural/CheckerEditor.js +26 -0
  90. package/examples/jsm/node-editor/utils/OscillatorEditor.js +42 -0
  91. package/examples/jsm/node-editor/utils/TimerEditor.js +57 -0
  92. package/examples/jsm/nodes/materials/StandardNodeMaterial.js +1 -1
  93. package/examples/jsm/nodes/materials/nodes/StandardNode.js +6 -6
  94. package/examples/jsm/nodes/utils/ColorSpaceNode.js +1 -49
  95. package/examples/jsm/objects/MarchingCubes.js +46 -152
  96. package/examples/jsm/postprocessing/AdaptiveToneMappingPass.js +1 -1
  97. package/examples/jsm/postprocessing/AfterimagePass.js +1 -1
  98. package/examples/jsm/postprocessing/BloomPass.js +1 -1
  99. package/examples/jsm/postprocessing/BokehPass.js +1 -1
  100. package/examples/jsm/postprocessing/ClearPass.js +1 -1
  101. package/examples/jsm/postprocessing/CubeTexturePass.js +1 -1
  102. package/examples/jsm/postprocessing/DotScreenPass.js +1 -1
  103. package/examples/jsm/postprocessing/EffectComposer.js +3 -3
  104. package/examples/jsm/postprocessing/FilmPass.js +1 -1
  105. package/examples/jsm/postprocessing/GlitchPass.js +1 -1
  106. package/examples/jsm/postprocessing/HalftonePass.js +1 -1
  107. package/examples/jsm/postprocessing/MaskPass.js +1 -1
  108. package/examples/jsm/postprocessing/OutlinePass.js +1 -1
  109. package/examples/jsm/postprocessing/RenderPass.js +1 -1
  110. package/examples/jsm/postprocessing/SAOPass.js +1 -1
  111. package/examples/jsm/postprocessing/SMAAPass.js +1 -1
  112. package/examples/jsm/postprocessing/SSAARenderPass.js +1 -1
  113. package/examples/jsm/postprocessing/SSAOPass.js +1 -1
  114. package/examples/jsm/postprocessing/SSRPass.js +1 -1
  115. package/examples/jsm/postprocessing/SSRrPass.js +1 -1
  116. package/examples/jsm/postprocessing/SavePass.js +1 -1
  117. package/examples/jsm/postprocessing/ShaderPass.js +1 -1
  118. package/examples/jsm/postprocessing/TAARenderPass.js +1 -1
  119. package/examples/jsm/postprocessing/TexturePass.js +1 -1
  120. package/examples/jsm/postprocessing/UnrealBloomPass.js +1 -1
  121. package/examples/jsm/renderers/CSS2DRenderer.js +5 -4
  122. package/examples/jsm/renderers/CSS3DRenderer.js +5 -4
  123. package/examples/jsm/renderers/nodes/Nodes.js +14 -13
  124. package/examples/jsm/renderers/nodes/ShaderNode.js +193 -41
  125. package/examples/jsm/renderers/nodes/accessors/MaterialNode.js +6 -6
  126. package/examples/jsm/renderers/nodes/accessors/ModelViewProjectionNode.js +5 -5
  127. package/examples/jsm/renderers/nodes/accessors/NormalNode.js +14 -3
  128. package/examples/jsm/renderers/nodes/accessors/PointUVNode.js +3 -3
  129. package/examples/jsm/renderers/nodes/accessors/PositionNode.js +15 -5
  130. package/examples/jsm/renderers/nodes/accessors/SkinningNode.js +107 -0
  131. package/examples/jsm/renderers/nodes/accessors/UVNode.js +7 -5
  132. package/examples/jsm/renderers/nodes/core/ArrayInputNode.js +3 -3
  133. package/examples/jsm/renderers/nodes/core/AttributeNode.js +6 -0
  134. package/examples/jsm/renderers/nodes/core/BypassNode.js +38 -0
  135. package/examples/jsm/renderers/nodes/core/CodeNode.js +3 -3
  136. package/examples/jsm/renderers/nodes/core/ContextNode.js +4 -19
  137. package/examples/jsm/renderers/nodes/core/ExpressionNode.js +13 -2
  138. package/examples/jsm/renderers/nodes/core/FunctionNode.js +19 -132
  139. package/examples/jsm/renderers/nodes/core/InputNode.js +13 -3
  140. package/examples/jsm/renderers/nodes/core/Node.js +32 -10
  141. package/examples/jsm/renderers/nodes/core/NodeBuilder.js +146 -128
  142. package/examples/jsm/renderers/nodes/core/NodeFunction.js +22 -0
  143. package/examples/jsm/renderers/nodes/core/NodeFunctionInput.js +4 -4
  144. package/examples/jsm/renderers/nodes/core/NodeKeywords.js +18 -179
  145. package/examples/jsm/renderers/nodes/core/NodeParser.js +11 -0
  146. package/examples/jsm/renderers/nodes/core/NodeVar.js +2 -2
  147. package/examples/jsm/renderers/nodes/core/PropertyNode.js +14 -2
  148. package/examples/jsm/renderers/nodes/core/TempNode.js +10 -13
  149. package/examples/jsm/renderers/nodes/core/VarNode.js +12 -7
  150. package/examples/jsm/renderers/nodes/core/VaryNode.js +23 -8
  151. package/examples/jsm/renderers/nodes/core/constants.js +2 -0
  152. package/examples/jsm/renderers/nodes/display/ColorSpaceNode.js +47 -25
  153. package/examples/jsm/renderers/nodes/display/NormalMapNode.js +21 -22
  154. package/examples/jsm/renderers/nodes/functions/BSDFs.js +64 -101
  155. package/examples/jsm/renderers/nodes/inputs/BufferNode.js +25 -0
  156. package/examples/jsm/renderers/nodes/inputs/IntNode.js +17 -0
  157. package/examples/jsm/renderers/nodes/inputs/TextureNode.js +10 -2
  158. package/examples/jsm/renderers/nodes/lights/LightContextNode.js +20 -14
  159. package/examples/jsm/renderers/nodes/lights/LightNode.js +32 -36
  160. package/examples/jsm/renderers/nodes/math/CondNode.js +60 -0
  161. package/examples/jsm/renderers/nodes/math/MathNode.js +87 -36
  162. package/examples/jsm/renderers/nodes/math/OperatorNode.js +124 -31
  163. package/examples/jsm/renderers/nodes/parsers/GLSLNodeFunction.js +137 -0
  164. package/examples/jsm/renderers/nodes/parsers/GLSLNodeParser.js +14 -0
  165. package/examples/jsm/renderers/nodes/parsers/WGSLNodeFunction.js +89 -0
  166. package/examples/jsm/renderers/nodes/parsers/WGSLNodeParser.js +14 -0
  167. package/examples/jsm/renderers/nodes/procedural/CheckerNode.js +7 -9
  168. package/examples/jsm/renderers/nodes/utils/ArrayElementNode.js +31 -0
  169. package/examples/jsm/renderers/nodes/utils/ConvertNode.js +33 -0
  170. package/examples/jsm/renderers/nodes/utils/JoinNode.js +7 -7
  171. package/examples/jsm/renderers/nodes/utils/OscNode.js +58 -0
  172. package/examples/jsm/renderers/nodes/utils/SplitNode.js +18 -8
  173. package/examples/jsm/renderers/nodes/utils/SpriteSheetUVNode.js +7 -7
  174. package/examples/jsm/renderers/webgl/nodes/SlotNode.js +22 -0
  175. package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +191 -94
  176. package/examples/jsm/renderers/webgl/nodes/WebGLNodes.js +2 -2
  177. package/examples/jsm/renderers/webgl/nodes/WebGLPhysicalContextNode.js +2 -2
  178. package/examples/jsm/renderers/webgpu/WebGPUBackground.js +1 -1
  179. package/examples/jsm/renderers/webgpu/WebGPUBindings.js +3 -3
  180. package/examples/jsm/renderers/webgpu/WebGPUComputePipelines.js +2 -4
  181. package/examples/jsm/renderers/webgpu/WebGPUProgrammableStage.js +2 -4
  182. package/examples/jsm/renderers/webgpu/WebGPURenderPipeline.js +15 -23
  183. package/examples/jsm/renderers/webgpu/WebGPURenderPipelines.js +3 -5
  184. package/examples/jsm/renderers/webgpu/WebGPURenderer.js +11 -27
  185. package/examples/jsm/renderers/webgpu/WebGPUTextureUtils.js +62 -28
  186. package/examples/jsm/renderers/webgpu/WebGPUTextures.js +34 -27
  187. package/examples/jsm/renderers/webgpu/constants.js +2 -2
  188. package/examples/jsm/renderers/webgpu/nodes/WebGPUNodeBuilder.js +430 -98
  189. package/examples/jsm/renderers/webgpu/nodes/WebGPUNodes.js +1 -1
  190. package/examples/jsm/utils/RoughnessMipmapper.js +1 -0
  191. package/examples/jsm/webxr/OculusHandPointerModel.js +6 -6
  192. package/package.json +10 -10
  193. package/src/Three.Legacy.js +6 -0
  194. package/src/Three.js +0 -1
  195. package/src/cameras/StereoCamera.js +8 -7
  196. package/src/constants.js +1 -2
  197. package/src/core/Layers.js +7 -1
  198. package/src/core/Object3D.js +2 -0
  199. package/src/extras/PMREMGenerator.js +11 -6
  200. package/src/loaders/FileLoader.js +89 -152
  201. package/src/loaders/ImageLoader.js +9 -4
  202. package/src/loaders/LoaderUtils.js +26 -0
  203. package/src/loaders/MaterialLoader.js +7 -4
  204. package/src/loaders/ObjectLoader.js +2 -0
  205. package/src/materials/Material.js +4 -4
  206. package/src/materials/MeshPhysicalMaterial.js +20 -14
  207. package/src/math/MathUtils.js +5 -16
  208. package/src/renderers/WebGLMultisampleRenderTarget.js +7 -1
  209. package/src/renderers/WebGLRenderer.js +83 -117
  210. package/src/renderers/shaders/ShaderChunk/bsdfs.glsl.js +2 -2
  211. package/src/renderers/shaders/ShaderChunk/encodings_pars_fragment.glsl.js +0 -27
  212. package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +0 -1
  213. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +19 -6
  214. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +2 -2
  215. package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
  216. package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +1 -1
  217. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +13 -5
  218. package/src/renderers/shaders/ShaderLib/vsm.glsl.js +2 -1
  219. package/src/renderers/shaders/ShaderLib.js +6 -4
  220. package/src/renderers/shaders/UniformsLib.js +1 -2
  221. package/src/renderers/webgl/WebGLExtensions.js +1 -0
  222. package/src/renderers/webgl/WebGLMaterials.js +27 -15
  223. package/src/renderers/webgl/WebGLProgram.js +10 -6
  224. package/src/renderers/webgl/WebGLPrograms.js +17 -12
  225. package/src/renderers/webgl/WebGLShadowMap.js +14 -5
  226. package/src/renderers/webgl/WebGLState.js +31 -17
  227. package/src/renderers/webgl/WebGLTextures.js +188 -51
  228. package/src/renderers/webgl/WebGLUniforms.js +45 -1
  229. package/src/renderers/webxr/WebXRManager.js +68 -107
  230. package/src/textures/Texture.js +6 -0
  231. package/src/utils.js +37 -1
  232. package/examples/js/controls/DeviceOrientationControls.js +0 -147
  233. package/examples/js/libs/dat.gui.min.js +0 -14
  234. package/examples/jsm/controls/DeviceOrientationControls.js +0 -153
  235. package/examples/jsm/libs/dat.gui.module.js +0 -3575
  236. package/examples/jsm/libs/glslang.js +0 -78
  237. package/examples/jsm/libs/glslang.wasm +0 -0
  238. package/examples/jsm/renderers/nodes/consts/MathConsts.js +0 -7
  239. package/examples/jsm/renderers/nodes/core/ConstNode.js +0 -39
  240. package/examples/jsm/renderers/nodes/core/NodeSlot.js +0 -13
  241. package/examples/jsm/renderers/nodes/core/StructNode.js +0 -80
  242. package/examples/jsm/renderers/nodes/core/StructVarNode.js +0 -75
  243. package/examples/jsm/renderers/nodes/functions/EncodingFunctions.js +0 -99
  244. package/examples/jsm/renderers/nodes/functions/MathFunctions.js +0 -47
  245. package/examples/jsm/renderers/webgpu/nodes/ShaderLib.js +0 -152
  246. package/src/extras/objects/ImmediateRenderObject.js +0 -31
@@ -1,68 +1,43 @@
1
- import FunctionNode from '../core/FunctionNode.js';
2
- import { pow2 } from './MathFunctions.js';
1
+ import { ShaderNode,
2
+ add, addTo, sub, mul, div, saturate, dot, pow, pow2, exp2, normalize, max, sqrt, negate,
3
+ cond, greaterThan, and,
4
+ transformedNormalView, positionViewDirection,
5
+ diffuseColor, specularColor, roughness,
6
+ PI, RECIPROCAL_PI, EPSILON
7
+ } from '../ShaderNode.js';
3
8
 
4
- export const F_Schlick = new FunctionNode( `
5
- vec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {
9
+ export const F_Schlick = new ShaderNode( ( inputs ) => {
10
+
11
+ const { f0, f90, dotVH } = inputs;
6
12
 
7
13
  // Original approximation by Christophe Schlick '94
8
14
  // float fresnel = pow( 1.0 - dotVH, 5.0 );
9
15
 
10
16
  // Optimized variant (presented by Epic at SIGGRAPH '13)
11
17
  // https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf
12
- float fresnel = exp2( ( -5.55473 * dotVH - 6.98316 ) * dotVH );
13
-
14
- return ( f90 - f0 ) * fresnel + f0;
15
-
16
- }` ); // validated
17
-
18
- export const G_BlinnPhong_Implicit = new FunctionNode( `
19
- float G_BlinnPhong_Implicit() {
20
-
21
- // ( const in float dotNL, const in float dotNV )
22
- // geometry term is (n dot l)(n dot v) / 4(n dot l)(n dot v)
23
-
24
- return 0.25;
25
-
26
- }` ); // validated
27
-
28
- export const BRDF_Lambert = new FunctionNode( `
29
- vec3 BRDF_Lambert( const in vec3 diffuseColor ) {
30
-
31
- return RECIPROCAL_PI * diffuseColor;
32
-
33
- }` ); // validated
18
+ const fresnel = exp2( mul( sub( mul( - 5.55473, dotVH ), 6.98316 ), dotVH ) );
34
19
 
35
- export const getDistanceAttenuation = new FunctionNode( `
36
- float getDistanceAttenuation( float lightDistance, float cutoffDistance, float decayExponent ) {
20
+ return add( mul( f0, sub( 1.0, fresnel ) ), mul( f90, fresnel ) );
37
21
 
38
- #if defined ( PHYSICALLY_CORRECT_LIGHTS )
22
+ } ); // validated
39
23
 
40
- // based upon Frostbite 3 Moving to Physically-based Rendering
41
- // page 32, equation 26: E[window1]
42
- // https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
43
- float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );
24
+ export const BRDF_Lambert = new ShaderNode( ( inputs ) => {
44
25
 
45
- if( cutoffDistance > 0.0 ) {
26
+ return mul( RECIPROCAL_PI, inputs.diffuseColor ); // punctual light
46
27
 
47
- distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );
28
+ } ); // validated
48
29
 
49
- }
30
+ export const getDistanceAttenuation = new ShaderNode( ( inputs ) => {
50
31
 
51
- return distanceFalloff;
32
+ const { lightDistance, cutoffDistance, decayExponent } = inputs;
52
33
 
53
- #else
34
+ return cond(
35
+ and( greaterThan( cutoffDistance, 0 ), greaterThan( decayExponent, 0 ) ),
36
+ pow( saturate( add( div( negate( lightDistance ), cutoffDistance ), 1.0 ) ), decayExponent ),
37
+ 1.0
38
+ );
54
39
 
55
- if( cutoffDistance > 0.0 && decayExponent > 0.0 ) {
56
-
57
- return pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );
58
-
59
- }
60
-
61
- return 1.0;
62
-
63
- #endif
64
-
65
- }` ).setIncludes( [ pow2 ] );
40
+ } ); // validated
66
41
 
67
42
  //
68
43
  // STANDARD
@@ -70,90 +45,78 @@ float getDistanceAttenuation( float lightDistance, float cutoffDistance, float d
70
45
 
71
46
  // Moving Frostbite to Physically Based Rendering 3.0 - page 12, listing 2
72
47
  // https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
73
- export const V_GGX_SmithCorrelated = new FunctionNode( `
74
- float V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {
48
+ export const V_GGX_SmithCorrelated = new ShaderNode( ( inputs ) => {
75
49
 
76
- float a2 = pow2( alpha );
50
+ const { alpha, dotNL, dotNV } = inputs;
77
51
 
78
- float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );
79
- float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );
52
+ const a2 = pow2( alpha );
80
53
 
81
- return 0.5 / max( gv + gl, EPSILON );
54
+ const gv = mul( dotNL, sqrt( add( a2, mul( sub( 1.0, a2 ), pow2( dotNV ) ) ) ) );
55
+ const gl = mul( dotNV, sqrt( add( a2, mul( sub( 1.0, a2 ), pow2( dotNL ) ) ) ) );
82
56
 
83
- }` ).setIncludes( [ pow2 ] );
57
+ return div( 0.5, max( add( gv, gl ), EPSILON ) );
58
+
59
+ } ); // validated
84
60
 
85
61
  // Microfacet Models for Refraction through Rough Surfaces - equation (33)
86
62
  // http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html
87
63
  // alpha is "roughness squared" in Disney’s reparameterization
88
- export const D_GGX = new FunctionNode( `
89
- float D_GGX( const in float alpha, const in float dotNH ) {
90
-
91
- float a2 = pow2( alpha );
64
+ export const D_GGX = new ShaderNode( ( inputs ) => {
92
65
 
93
- float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0; // avoid alpha = 0 with dotNH = 1
66
+ const { alpha, dotNH } = inputs;
94
67
 
95
- return RECIPROCAL_PI * a2 / pow2( denom );
68
+ const a2 = pow2( alpha );
96
69
 
97
- }` ).setIncludes( [ pow2 ] );
70
+ const denom = add( mul( pow2( dotNH ), sub( a2, 1.0 ) ), 1.0 ); // avoid alpha = 0 with dotNH = 1
98
71
 
99
- // GGX Distribution, Schlick Fresnel, GGX_SmithCorrelated Visibility
100
- export const BRDF_Specular_GGX = new FunctionNode( `
101
- vec3 BRDF_Specular_GGX( vec3 lightDirection, const in vec3 f0, const in float f90, const in float roughness ) {
72
+ return mul( RECIPROCAL_PI, div( a2, pow2( denom ) ) );
102
73
 
103
- float alpha = pow2( roughness ); // UE4's roughness
74
+ } ); // validated
104
75
 
105
- vec3 halfDir = normalize( lightDirection + PositionViewDirection );
106
76
 
107
- float dotNL = saturate( dot( TransformedNormalView, lightDirection ) );
108
- float dotNV = saturate( dot( TransformedNormalView, PositionViewDirection ) );
109
- float dotNH = saturate( dot( TransformedNormalView, halfDir ) );
110
- float dotVH = saturate( dot( PositionViewDirection, halfDir ) );
111
-
112
- vec3 F = F_Schlick( f0, f90, dotVH );
77
+ // GGX Distribution, Schlick Fresnel, GGX_SmithCorrelated Visibility
78
+ export const BRDF_Specular_GGX = new ShaderNode( ( inputs ) => {
113
79
 
114
- float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );
80
+ const { lightDirection, f0, f90, roughness } = inputs;
115
81
 
116
- float D = D_GGX( alpha, dotNH );
82
+ const alpha = pow2( roughness ); // UE4's roughness
117
83
 
118
- return F * ( V * D );
84
+ const halfDir = normalize( add( lightDirection, positionViewDirection ) );
119
85
 
120
- }` ).setIncludes( [ pow2, F_Schlick, V_GGX_SmithCorrelated, D_GGX ] ); // validated
86
+ const dotNL = saturate( dot( transformedNormalView, lightDirection ) );
87
+ const dotNV = saturate( dot( transformedNormalView, positionViewDirection ) );
88
+ const dotNH = saturate( dot( transformedNormalView, halfDir ) );
89
+ const dotVH = saturate( dot( positionViewDirection, halfDir ) );
121
90
 
122
- export const RE_Direct_Physical = new FunctionNode( `
123
- void RE_Direct_Physical( inout ReflectedLight reflectedLight, vec3 lightDirection, vec3 lightColor ) {
91
+ const F = F_Schlick( { f0, f90, dotVH } );
124
92
 
125
- float dotNL = saturate( dot( TransformedNormalView, lightDirection ) );
126
- vec3 irradiance = dotNL * lightColor;
93
+ const V = V_GGX_SmithCorrelated( { alpha, dotNL, dotNV } );
127
94
 
128
- #ifndef PHYSICALLY_CORRECT_LIGHTS
95
+ const D = D_GGX( { alpha, dotNH } );
129
96
 
130
- irradiance *= PI; // punctual light
97
+ return mul( F, mul( V, D ) );
131
98
 
132
- #endif
99
+ } ); // validated
133
100
 
134
- reflectedLight.directDiffuse += irradiance * BRDF_Lambert( MaterialDiffuseColor.rgb );
101
+ export const RE_Direct_Physical = new ShaderNode( ( inputs ) => {
135
102
 
136
- reflectedLight.directSpecular += irradiance * BRDF_Specular_GGX( lightDirection, MaterialSpecularTint, 1.0, MaterialRoughness );
103
+ const { lightDirection, lightColor, directDiffuse, directSpecular } = inputs;
137
104
 
138
- }` ).setIncludes( [ BRDF_Lambert, BRDF_Specular_GGX ] );
105
+ const dotNL = saturate( dot( transformedNormalView, lightDirection ) );
106
+ let irradiance = mul( dotNL, lightColor );
139
107
 
140
- export const PhysicalLightingModel = new FunctionNode( `
141
- void ( inout ReflectedLight reflectedLight, vec3 lightDirection, vec3 lightColor ) {
108
+ irradiance = mul( irradiance, PI ); // punctual light
142
109
 
143
- RE_Direct_Physical( reflectedLight, lightDirection, lightColor );
110
+ addTo( directDiffuse, mul( irradiance, BRDF_Lambert( { diffuseColor } ) ) );
144
111
 
145
- }` ).setIncludes( [ RE_Direct_Physical ] );
112
+ addTo( directSpecular, mul( irradiance, BRDF_Specular_GGX( { lightDirection, f0: specularColor, f90: 1, roughness } ) ) );
146
113
 
147
- // utils
114
+ } );
148
115
 
149
- // Trowbridge-Reitz distribution to Mip level, following the logic of http://casual-effects.blogspot.ca/2011/08/plausible-environment-lighting-in-two.html
150
- export const getSpecularMIPLevel = new FunctionNode( `
151
- float ( const in float roughness, const in float maxMIPLevelScalar ) {
116
+ export const PhysicalLightingModel = new ShaderNode( ( inputs/*, builder*/ ) => {
152
117
 
153
- float sigma = PI * roughness * roughness / ( 1.0 + roughness );
154
- float desiredMIPLevel = maxMIPLevelScalar + log2( sigma );
118
+ // PHYSICALLY_CORRECT_LIGHTS <-> builder.renderer.physicallyCorrectLights === true
155
119
 
156
- // clamp to allowable LOD ranges.
157
- return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );
120
+ RE_Direct_Physical( inputs );
158
121
 
159
- }` );
122
+ } );
@@ -0,0 +1,25 @@
1
+ import InputNode from '../core/InputNode.js';
2
+
3
+ class BufferNode extends InputNode {
4
+
5
+ constructor( value, bufferType, bufferCount = 0 ) {
6
+
7
+ super( 'buffer' );
8
+
9
+ this.value = value;
10
+ this.bufferType = bufferType;
11
+ this.bufferCount = bufferCount;
12
+
13
+ }
14
+
15
+ getNodeType( /* builder */ ) {
16
+
17
+ return this.bufferType;
18
+
19
+ }
20
+
21
+ }
22
+
23
+ BufferNode.prototype.isBufferNode = true;
24
+
25
+ export default BufferNode;
@@ -0,0 +1,17 @@
1
+ import InputNode from '../core/InputNode.js';
2
+
3
+ class IntNode extends InputNode {
4
+
5
+ constructor( value = 0 ) {
6
+
7
+ super( 'int' );
8
+
9
+ this.value = value;
10
+
11
+ }
12
+
13
+ }
14
+
15
+ IntNode.prototype.isIntNode = true;
16
+
17
+ export default IntNode;
@@ -17,6 +17,14 @@ class TextureNode extends InputNode {
17
17
 
18
18
  generate( builder, output ) {
19
19
 
20
+ const texture = this.value;
21
+
22
+ if ( ! texture || texture.isTexture !== true ) {
23
+
24
+ throw new Error( `TextureNode: Need a three.js texture.` );
25
+
26
+ }
27
+
20
28
  const type = this.getNodeType( builder );
21
29
 
22
30
  const textureProperty = super.generate( builder, type );
@@ -51,8 +59,8 @@ class TextureNode extends InputNode {
51
59
  const textureCallSnippet = builder.getTexture( textureProperty, uvSnippet, biasSnippet );
52
60
 
53
61
  colorSpace = new ColorSpaceNode();
54
- colorSpace.input = new ExpressionNode( textureCallSnippet, 'vec4' );
55
- colorSpace.fromDecoding( builder.getTextureEncodingFromMap( this.value ) );
62
+ colorSpace.node = new ExpressionNode( textureCallSnippet, 'vec4' );
63
+ colorSpace.fromDecoding( builder.getTextureEncodingFromMap( texture ) );
56
64
 
57
65
  nodeData.colorSpace = colorSpace;
58
66
 
@@ -1,23 +1,24 @@
1
1
  import ContextNode from '../core/ContextNode.js';
2
- import StructNode from '../core/StructNode.js';
2
+ import VarNode from '../core/VarNode.js';
3
+ import Vector3Node from '../inputs/Vector3Node.js';
4
+ import OperatorNode from '../math/OperatorNode.js';
3
5
  import { PhysicalLightingModel } from '../functions/BSDFs.js';
4
6
 
5
- const reflectedLightStruct = new StructNode( {
6
- directDiffuse: 'vec3',
7
- directSpecular: 'vec3'
8
- }, 'ReflectedLight' );
9
-
10
7
  class LightContextNode extends ContextNode {
11
8
 
12
9
  constructor( node ) {
13
10
 
14
- super( node, 'vec3' );
11
+ super( node );
15
12
 
16
13
  }
17
14
 
18
- generate( builder ) {
15
+ getNodeType( /*builder*/ ) {
19
16
 
20
- const type = this.getNodeType( builder );
17
+ return 'vec3';
18
+
19
+ }
20
+
21
+ generate( builder ) {
21
22
 
22
23
  const material = builder.material;
23
24
 
@@ -29,22 +30,27 @@ class LightContextNode extends ContextNode {
29
30
 
30
31
  }
31
32
 
32
- const reflectedLightNode = reflectedLightStruct.create();
33
- const reflectedLight = reflectedLightNode.build( builder, 'var' );
33
+ const directDiffuse = new VarNode( new Vector3Node(), 'DirectDiffuse', 'vec3' );
34
+ const directSpecular = new VarNode( new Vector3Node(), 'DirectSpecular', 'vec3' );
34
35
 
35
- this.setContextValue( 'reflectedLight', reflectedLightNode );
36
+ this.context.directDiffuse = directDiffuse;
37
+ this.context.directSpecular = directSpecular;
36
38
 
37
39
  if ( lightingModel !== null ) {
38
40
 
39
- this.setContextValue( 'lightingModel', lightingModel );
41
+ this.context.lightingModel = lightingModel;
40
42
 
41
43
  }
42
44
 
43
45
  // add code
44
46
 
47
+ const type = this.getNodeType( builder );
48
+
45
49
  super.generate( builder, type );
46
50
 
47
- return `( ${reflectedLight}.directDiffuse + ${reflectedLight}.directSpecular )`;
51
+ const totalLight = new OperatorNode( '+', directDiffuse, directSpecular );
52
+
53
+ return totalLight.build( builder, type );
48
54
 
49
55
  }
50
56
 
@@ -20,61 +20,57 @@ class LightNode extends Node {
20
20
 
21
21
  this.light = light;
22
22
 
23
- this.color = new ColorNode( new Color() );
23
+ this.colorNode = new ColorNode( new Color() );
24
24
 
25
- this.lightCutoffDistance = new FloatNode( 0 );
26
- this.lightDecayExponent = new FloatNode( 0 );
27
-
28
- this.lightPositionView = new Object3DNode( Object3DNode.VIEW_POSITION );
29
- this.positionView = new PositionNode( PositionNode.VIEW );
30
-
31
- this.lVector = new OperatorNode( '-', this.lightPositionView, this.positionView );
32
-
33
- this.lightDirection = new MathNode( MathNode.NORMALIZE, this.lVector );
34
-
35
- this.lightDistance = new MathNode( MathNode.LENGTH, this.lVector );
36
-
37
- this.lightAttenuation = getDistanceAttenuation.call( {
38
- lightDistance: this.lightDistance,
39
- cutoffDistance: this.lightCutoffDistance,
40
- decayExponent: this.lightDecayExponent
41
- } );
42
-
43
- this.lightColor = new OperatorNode( '*', this.color, this.lightAttenuation );
25
+ this.lightCutoffDistanceNode = new FloatNode( 0 );
26
+ this.lightDecayExponentNode = new FloatNode( 0 );
44
27
 
45
28
  }
46
29
 
47
30
  update( /* frame */ ) {
48
31
 
49
- this.color.value.copy( this.light.color ).multiplyScalar( this.light.intensity );
50
- this.lightCutoffDistance.value = this.light.distance;
51
- this.lightDecayExponent.value = this.light.decay;
32
+ this.colorNode.value.copy( this.light.color ).multiplyScalar( this.light.intensity );
33
+ this.lightCutoffDistanceNode.value = this.light.distance;
34
+ this.lightDecayExponentNode.value = this.light.decay;
52
35
 
53
36
  }
54
37
 
55
38
  generate( builder ) {
56
39
 
57
- const type = this.getNodeType( builder );
40
+ const lightPositionView = new Object3DNode( Object3DNode.VIEW_POSITION );
41
+ const positionView = new PositionNode( PositionNode.VIEW );
58
42
 
59
- this.lightPositionView.object3d = this.light;
43
+ const lVector = new OperatorNode( '-', lightPositionView, positionView );
60
44
 
61
- const lightingModelFunctionNode = builder.getContextValue( 'lightingModel' );
45
+ const lightDirection = new MathNode( MathNode.NORMALIZE, lVector );
62
46
 
63
- if ( lightingModelFunctionNode !== undefined ) {
47
+ const lightDistance = new MathNode( MathNode.LENGTH, lVector );
64
48
 
65
- const reflectedLightStructNode = builder.getContextValue( 'reflectedLight' );
49
+ const lightAttenuation = getDistanceAttenuation( {
50
+ lightDistance,
51
+ cutoffDistance: this.lightCutoffDistanceNode,
52
+ decayExponent: this.lightDecayExponentNode
53
+ } );
66
54
 
67
- const lightingModelCallNode = lightingModelFunctionNode.call( {
68
- lightDirection: this.lightDirection,
69
- lightColor: this.lightColor,
70
- reflectedLight: reflectedLightStructNode
71
- } );
55
+ const lightColor = new OperatorNode( '*', this.colorNode, lightAttenuation );
72
56
 
73
- builder.addFlowCode( lightingModelCallNode.build( builder ) );
57
+ lightPositionView.object3d = this.light;
74
58
 
75
- }
59
+ const lightingModelFunction = builder.context.lightingModel;
60
+
61
+ if ( lightingModelFunction !== undefined ) {
76
62
 
77
- return this.color.build( builder, type );
63
+ const directDiffuse = builder.context.directDiffuse;
64
+ const directSpecular = builder.context.directSpecular;
65
+
66
+ lightingModelFunction( {
67
+ lightDirection,
68
+ lightColor,
69
+ directDiffuse,
70
+ directSpecular
71
+ }, builder );
72
+
73
+ }
78
74
 
79
75
  }
80
76
 
@@ -0,0 +1,60 @@
1
+ import Node from '../core/Node.js';
2
+ import PropertyNode from '../core/PropertyNode.js';
3
+ import ContextNode from '../core/ContextNode.js';
4
+
5
+ class CondNode extends Node {
6
+
7
+ constructor( node, ifNode, elseNode ) {
8
+
9
+ super();
10
+
11
+ this.node = node;
12
+
13
+ this.ifNode = ifNode;
14
+ this.elseNode = elseNode;
15
+
16
+ }
17
+
18
+ getNodeType( builder ) {
19
+
20
+ const ifType = this.ifNode.getNodeType( builder );
21
+ const elseType = this.elseNode.getNodeType( builder );
22
+
23
+ if ( builder.getTypeLength( elseType ) > builder.getTypeLength( ifType ) ) {
24
+
25
+ return elseType;
26
+
27
+ }
28
+
29
+ return ifType;
30
+
31
+ }
32
+
33
+ generate( builder ) {
34
+
35
+ const type = this.getNodeType( builder );
36
+
37
+ const context = { temp: false };
38
+ const nodeProperty = new PropertyNode( null, type ).build( builder );
39
+
40
+ const nodeSnippet = new ContextNode( this.node/*, context*/ ).build( builder, 'bool' ),
41
+ ifSnippet = new ContextNode( this.ifNode, context ).build( builder, type ),
42
+ elseSnippet = new ContextNode( this.elseNode, context ).build( builder, type );
43
+
44
+ builder.addFlowCode( `if ( ${nodeSnippet} ) {
45
+
46
+ \t\t${nodeProperty} = ${ifSnippet};
47
+
48
+ \t} else {
49
+
50
+ \t\t${nodeProperty} = ${elseSnippet};
51
+
52
+ \t}` );
53
+
54
+ return nodeProperty;
55
+
56
+ }
57
+
58
+ }
59
+
60
+ export default CondNode;