super-three 0.169.1 → 0.170.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 +24628 -24228
- package/build/three.core.js +37002 -0
- package/build/three.core.min.js +6 -0
- package/build/three.module.js +10519 -47108
- package/build/three.module.min.js +1 -1
- package/build/three.tsl.js +533 -0
- package/build/three.tsl.min.js +6 -0
- package/build/three.webgpu.js +17071 -53583
- package/build/three.webgpu.min.js +1 -1
- package/build/three.webgpu.nodes.js +17134 -53623
- package/build/three.webgpu.nodes.min.js +1 -1
- package/examples/jsm/Addons.js +3 -3
- package/examples/jsm/animation/MMDAnimationHelper.js +2 -0
- package/examples/jsm/animation/MMDPhysics.js +2 -0
- package/examples/jsm/capabilities/WebGPU.js +1 -10
- package/examples/jsm/controls/ArcballControls.js +25 -21
- package/examples/jsm/controls/OrbitControls.js +41 -9
- package/examples/jsm/controls/PointerLockControls.js +2 -5
- package/examples/jsm/controls/TransformControls.js +22 -6
- package/examples/jsm/csm/CSM.js +2 -2
- package/examples/jsm/csm/CSMFrustum.js +7 -4
- package/examples/jsm/csm/CSMHelper.js +2 -0
- package/examples/jsm/csm/CSMShadowNode.js +437 -0
- package/examples/jsm/curves/NURBSCurve.js +34 -3
- package/examples/jsm/exporters/GLTFExporter.js +138 -71
- package/examples/jsm/exporters/KTX2Exporter.js +35 -12
- package/examples/jsm/exporters/MMDExporter.js +6 -0
- package/examples/jsm/exporters/USDZExporter.js +21 -3
- package/examples/jsm/geometries/DecalGeometry.js +70 -21
- package/examples/jsm/geometries/InstancedPointsGeometry.js +2 -0
- package/examples/jsm/helpers/TextureHelperGPU.js +175 -0
- package/examples/jsm/interactive/HTMLMesh.js +1 -0
- package/examples/jsm/lighting/TiledLighting.js +18 -0
- package/examples/jsm/lights/RectAreaLightTexturesLib.js +1 -1
- package/examples/jsm/lines/LineGeometry.js +25 -0
- package/examples/jsm/lines/LineMaterial.js +0 -1
- package/examples/jsm/lines/LineSegmentsGeometry.js +2 -0
- package/examples/jsm/lines/webgpu/Line2.js +2 -1
- package/examples/jsm/lines/webgpu/LineSegments2.js +2 -16
- package/examples/jsm/lines/webgpu/Wireframe.js +57 -0
- package/examples/jsm/loaders/3DMLoader.js +1 -0
- package/examples/jsm/loaders/3MFLoader.js +91 -0
- package/examples/jsm/loaders/FBXLoader.js +12 -2
- package/examples/jsm/loaders/GLTFLoader.js +2 -0
- package/examples/jsm/loaders/KTX2Loader.js +143 -49
- package/examples/jsm/loaders/LDrawLoader.js +22 -136
- package/examples/jsm/loaders/LottieLoader.js +1 -0
- package/examples/jsm/loaders/MMDLoader.js +3 -0
- package/examples/jsm/loaders/MaterialXLoader.js +2 -2
- package/examples/jsm/materials/LDrawConditionalLineMaterial.js +143 -0
- package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +114 -0
- package/examples/jsm/math/ColorSpaces.js +76 -0
- package/examples/jsm/misc/ProgressiveLightMap.js +52 -40
- package/examples/jsm/misc/ProgressiveLightMapGPU.js +293 -0
- package/examples/jsm/misc/VolumeSlice.js +1 -0
- package/examples/jsm/objects/InstancedPoints.js +2 -4
- package/examples/jsm/objects/LensflareMesh.js +4 -2
- package/examples/jsm/objects/SkyMesh.js +5 -3
- package/examples/jsm/objects/Water2Mesh.js +7 -3
- package/examples/jsm/objects/WaterMesh.js +12 -10
- package/examples/jsm/postprocessing/AfterimagePass.js +14 -3
- package/examples/jsm/postprocessing/SSRPass.js +6 -0
- package/examples/jsm/renderers/CSS2DRenderer.js +6 -3
- package/examples/jsm/renderers/CSS3DRenderer.js +7 -4
- package/examples/jsm/shaders/FXAAShader.js +225 -224
- package/examples/jsm/transpiler/AST.js +2 -2
- package/examples/jsm/transpiler/GLSLDecoder.js +57 -25
- package/examples/jsm/transpiler/ShaderToyDecoder.js +1 -1
- package/examples/jsm/transpiler/TSLEncoder.js +11 -6
- package/{src/nodes → examples/jsm/tsl}/display/AfterImageNode.js +18 -21
- package/{src/nodes → examples/jsm/tsl}/display/AnaglyphPassNode.js +2 -6
- package/{src/nodes → examples/jsm/tsl}/display/AnamorphicNode.js +12 -18
- package/{src/nodes → examples/jsm/tsl}/display/BleachBypass.js +1 -3
- package/{src/nodes → examples/jsm/tsl}/display/BloomNode.js +12 -41
- package/{src/nodes → examples/jsm/tsl}/display/DenoiseNode.js +60 -47
- package/{src/nodes → examples/jsm/tsl}/display/DepthOfFieldNode.js +4 -9
- package/{src/nodes → examples/jsm/tsl}/display/DotScreenNode.js +2 -9
- package/examples/jsm/tsl/display/FXAANode.js +316 -0
- package/{src/nodes → examples/jsm/tsl}/display/FilmNode.js +4 -7
- package/{src/nodes → examples/jsm/tsl}/display/GTAONode.js +73 -78
- package/{src/nodes → examples/jsm/tsl}/display/GaussianBlurNode.js +78 -42
- package/examples/jsm/tsl/display/LensflareNode.js +161 -0
- package/{src/nodes → examples/jsm/tsl}/display/Lut3DNode.js +3 -5
- package/{src/nodes → examples/jsm/tsl}/display/MotionBlur.js +2 -3
- package/examples/jsm/tsl/display/OutlineNode.js +434 -0
- package/{src/nodes → examples/jsm/tsl}/display/ParallaxBarrierPassNode.js +2 -5
- package/{src/nodes → examples/jsm/tsl}/display/PixelationPassNode.js +5 -17
- package/{src/nodes → examples/jsm/tsl}/display/RGBShiftNode.js +2 -6
- package/examples/jsm/tsl/display/SMAANode.js +620 -0
- package/{src/nodes → examples/jsm/tsl}/display/SSAAPassNode.js +10 -25
- package/examples/jsm/tsl/display/SSRNode.js +366 -0
- package/{src/nodes → examples/jsm/tsl}/display/Sepia.js +1 -2
- package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +4 -12
- package/{src/nodes → examples/jsm/tsl}/display/StereoCompositePassNode.js +9 -11
- package/{src/nodes → examples/jsm/tsl}/display/StereoPassNode.js +10 -11
- package/examples/jsm/tsl/display/TRAAPassNode.js +355 -0
- package/{src/nodes → examples/jsm/tsl}/display/TransitionNode.js +3 -7
- package/examples/jsm/tsl/display/hashBlur.js +24 -0
- package/examples/jsm/tsl/lighting/TiledLightsNode.js +389 -0
- package/examples/jsm/utils/SceneOptimizer.js +410 -0
- package/examples/jsm/utils/UVsDebug.js +1 -1
- package/examples/jsm/utils/{TextureUtilsGPU.js → WebGPUTextureUtils.js} +2 -1
- package/examples/jsm/webxr/OculusHandPointerModel.js +21 -21
- package/examples/jsm/webxr/Text2D.js +6 -6
- package/package.json +4 -4
- package/src/Three.Core.js +178 -0
- package/src/Three.TSL.js +526 -0
- package/src/Three.WebGPU.Nodes.js +9 -186
- package/src/Three.WebGPU.js +8 -186
- package/src/Three.js +1 -177
- package/src/animation/AnimationClip.js +2 -2
- package/src/animation/AnimationObjectGroup.js +2 -2
- package/src/audio/Audio.js +38 -0
- package/src/cameras/PerspectiveCamera.js +6 -6
- package/src/cameras/StereoCamera.js +2 -2
- package/src/constants.js +1 -6
- package/src/core/BufferGeometry.js +48 -8
- package/src/core/InterleavedBuffer.js +4 -4
- package/src/core/Object3D.js +2 -2
- package/src/extras/core/Curve.js +3 -3
- package/src/extras/core/Shape.js +2 -2
- package/src/geometries/CylinderGeometry.js +2 -2
- package/src/geometries/EdgesGeometry.js +2 -2
- package/src/geometries/LatheGeometry.js +2 -2
- package/src/lights/SpotLightShadow.js +2 -2
- package/src/materials/LineDashedMaterial.js +0 -1
- package/src/materials/Material.js +2 -2
- package/src/materials/MeshPhongMaterial.js +1 -1
- package/src/materials/MeshPhysicalMaterial.js +2 -2
- package/src/materials/MeshStandardMaterial.js +2 -2
- package/src/materials/nodes/Line2NodeMaterial.js +32 -13
- package/src/materials/nodes/LineDashedNodeMaterial.js +4 -2
- package/src/materials/nodes/NodeMaterial.js +93 -23
- package/src/materials/nodes/SpriteNodeMaterial.js +11 -2
- package/src/materials/nodes/manager/NodeMaterialObserver.js +119 -7
- package/src/math/ColorManagement.js +143 -102
- package/src/math/Line3.js +2 -2
- package/src/math/Quaternion.js +2 -2
- package/src/math/Spherical.js +3 -3
- package/src/math/Vector2.js +7 -7
- package/src/math/Vector3.js +9 -9
- package/src/math/Vector4.js +22 -9
- package/src/nodes/Nodes.js +2 -21
- package/src/nodes/TSL.js +9 -25
- package/src/nodes/accessors/Arrays.js +27 -0
- package/src/nodes/accessors/BuiltinNode.js +26 -0
- package/src/nodes/accessors/Camera.js +0 -1
- package/src/nodes/accessors/ClippingNode.js +76 -42
- package/src/nodes/accessors/InstanceNode.js +17 -20
- package/src/nodes/accessors/InstancedMeshNode.js +26 -0
- package/src/nodes/accessors/Lights.js +32 -0
- package/src/nodes/accessors/SceneNode.js +35 -1
- package/src/nodes/accessors/StorageBufferNode.js +61 -19
- package/src/nodes/accessors/StorageTextureNode.js +10 -4
- package/src/nodes/accessors/TextureNode.js +1 -1
- package/src/nodes/accessors/VelocityNode.js +13 -3
- package/src/nodes/code/FunctionCallNode.js +16 -5
- package/src/nodes/code/ScriptableNode.js +4 -4
- package/src/nodes/core/Node.js +1 -0
- package/src/nodes/core/NodeBuilder.js +31 -14
- package/src/nodes/core/NodeUtils.js +28 -0
- package/src/nodes/core/VarNode.js +15 -3
- package/src/nodes/core/constants.js +6 -0
- package/src/nodes/display/BlendModes.js +99 -0
- package/src/nodes/display/ColorAdjustment.js +53 -4
- package/src/nodes/display/ColorSpaceFunctions.js +5 -5
- package/src/nodes/display/ColorSpaceNode.js +27 -39
- package/src/nodes/display/PassNode.js +6 -4
- package/src/nodes/display/ToneMappingNode.js +1 -1
- package/src/nodes/display/ToonOutlinePassNode.js +3 -3
- package/src/nodes/display/ViewportDepthNode.js +48 -1
- package/src/nodes/functions/PhysicalLightingModel.js +21 -15
- package/src/nodes/functions/material/getAlphaHashThreshold.js +70 -0
- package/src/nodes/functions/material/getGeometryRoughness.js +8 -2
- package/src/nodes/functions/material/getParallaxCorrectNormal.js +22 -0
- package/src/nodes/gpgpu/ComputeNode.js +9 -1
- package/src/nodes/lighting/AnalyticLightNode.js +23 -419
- package/src/nodes/lighting/LightsNode.js +24 -12
- package/src/nodes/lighting/PointLightNode.js +41 -22
- package/src/nodes/lighting/PointShadowNode.js +254 -0
- package/src/nodes/lighting/RectAreaLightNode.js +3 -0
- package/src/nodes/lighting/ShadowNode.js +593 -0
- package/src/nodes/lighting/SpotLightNode.js +14 -2
- package/src/nodes/utils/LoopNode.js +2 -2
- package/src/nodes/utils/Oscillators.js +6 -0
- package/src/nodes/utils/PostProcessingUtils.js +89 -0
- package/src/nodes/utils/RTTNode.js +9 -1
- package/src/nodes/utils/ReflectorNode.js +101 -15
- package/src/nodes/utils/StorageArrayElementNode.js +2 -2
- package/src/nodes/utils/Timer.js +29 -0
- package/src/objects/BatchedMesh.js +472 -296
- package/src/objects/ClippingGroup.js +19 -0
- package/src/objects/Skeleton.js +2 -2
- package/src/renderers/WebGLRenderer.js +183 -109
- package/src/renderers/common/Animation.js +23 -11
- package/src/renderers/common/Attributes.js +4 -0
- package/src/renderers/common/Backend.js +2 -0
- package/src/renderers/common/Background.js +15 -5
- package/src/renderers/common/Bindings.js +23 -6
- package/src/renderers/common/ClippingContext.js +77 -85
- package/src/renderers/common/Constants.js +2 -1
- package/src/renderers/common/Geometries.js +20 -0
- package/src/renderers/common/IndirectStorageBufferAttribute.js +15 -0
- package/src/renderers/common/Lighting.js +45 -0
- package/src/renderers/common/PostProcessingUtils.js +86 -0
- package/src/renderers/common/RenderList.js +48 -17
- package/src/renderers/common/RenderLists.js +4 -2
- package/src/renderers/common/RenderObject.js +45 -28
- package/src/renderers/common/RenderObjects.js +12 -6
- package/src/renderers/common/Renderer.js +222 -77
- package/src/renderers/common/Textures.js +41 -17
- package/src/renderers/common/UniformsGroup.js +16 -4
- package/src/renderers/common/extras/PMREMGenerator.js +89 -13
- package/src/renderers/common/nodes/NodeLibrary.js +2 -15
- package/src/renderers/common/nodes/NodeStorageBuffer.js +2 -3
- package/src/renderers/common/nodes/NodeUniform.js +42 -0
- package/src/renderers/common/nodes/Nodes.js +2 -2
- package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
- package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
- package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -2
- package/src/renderers/webgl/WebGLBackground.js +20 -1
- package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
- package/src/renderers/webgl/WebGLCapabilities.js +0 -7
- package/src/renderers/webgl/WebGLGeometries.js +0 -28
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
- package/src/renderers/webgl/WebGLProgram.js +24 -28
- package/src/renderers/webgl/WebGLPrograms.js +5 -2
- package/src/renderers/webgl/WebGLState.js +37 -1
- package/src/renderers/webgl/WebGLTextures.js +29 -12
- package/src/renderers/webgl-fallback/WebGLBackend.js +111 -37
- package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +2 -7
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +43 -12
- package/src/renderers/webgl-fallback/utils/WebGLState.js +26 -1
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +37 -9
- package/src/renderers/webgpu/WebGPUBackend.js +152 -56
- package/src/renderers/webgpu/WebGPURenderer.Nodes.js +1 -1
- package/src/renderers/webgpu/WebGPURenderer.js +1 -1
- package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +0 -8
- package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +13 -34
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +192 -92
- package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +12 -4
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +15 -2
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +72 -7
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +29 -9
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +29 -7
- package/src/renderers/webgpu/utils/WebGPUUtils.js +0 -1
- package/src/renderers/webxr/WebXRManager.js +4 -4
- package/src/textures/Source.js +2 -2
- package/src/textures/Texture.js +2 -2
- package/examples/jsm/cameras/CinematicCamera.js +0 -208
- package/src/nodes/display/BlendMode.js +0 -54
- package/src/nodes/display/FXAANode.js +0 -332
- package/src/nodes/utils/OscNode.js +0 -85
- package/src/nodes/utils/TimerNode.js +0 -97
- /package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Node from '../core/Node.js';
|
|
2
|
-
import { nodeImmutable, nodeProxy } from '../tsl/TSLBase.js';
|
|
2
|
+
import { float, log, log2, nodeImmutable, nodeProxy } from '../tsl/TSLBase.js';
|
|
3
3
|
import { cameraNear, cameraFar } from '../accessors/Camera.js';
|
|
4
4
|
import { positionView } from '../accessors/Position.js';
|
|
5
5
|
import { viewportDepthTexture } from './ViewportDepthTextureNode.js';
|
|
@@ -116,6 +116,53 @@ export const viewZToPerspectiveDepth = ( viewZ, near, far ) => near.add( viewZ )
|
|
|
116
116
|
// maps perspective depth in [ 0, 1 ] to viewZ
|
|
117
117
|
export const perspectiveDepthToViewZ = ( depth, near, far ) => near.mul( far ).div( far.sub( near ).mul( depth ).sub( far ) );
|
|
118
118
|
|
|
119
|
+
// -near maps to 0; -far maps to 1
|
|
120
|
+
export const viewZToLogarithmicDepth = ( viewZ, near, far ) => {
|
|
121
|
+
|
|
122
|
+
// NOTE: viewZ must be negative--see explanation at the end of this comment block.
|
|
123
|
+
// The final logarithmic depth formula used here is adapted from one described in an
|
|
124
|
+
// article by Thatcher Ulrich (see http://tulrich.com/geekstuff/log_depth_buffer.txt),
|
|
125
|
+
// which was an improvement upon an earlier formula one described in an
|
|
126
|
+
// Outerra article (https://outerra.blogspot.com/2009/08/logarithmic-z-buffer.html).
|
|
127
|
+
// Ulrich's formula is the following:
|
|
128
|
+
// z = K * log( w / cameraNear ) / log( cameraFar / cameraNear )
|
|
129
|
+
// where K = 2^k - 1, and k is the number of bits in the depth buffer.
|
|
130
|
+
// The Outerra variant ignored the camera near plane (it assumed it was 0) and instead
|
|
131
|
+
// opted for a "C-constant" for resolution adjustment of objects near the camera.
|
|
132
|
+
// Outerra states: "Notice that the 'C' variant doesn’t use a near plane distance, it has it
|
|
133
|
+
// set at 0" (quote from https://outerra.blogspot.com/2012/11/maximizing-depth-buffer-range-and.html).
|
|
134
|
+
// Ulrich's variant has the benefit of constant relative precision over the whole near-far range.
|
|
135
|
+
// It was debated here whether Outerra's "C-constant" or Ulrich's "near plane" variant should
|
|
136
|
+
// be used, and ultimately Ulrich's "near plane" version was chosen.
|
|
137
|
+
// Outerra eventually made another improvement to their original "C-constant" variant,
|
|
138
|
+
// but it still does not incorporate the camera near plane (for this version,
|
|
139
|
+
// see https://outerra.blogspot.com/2013/07/logarithmic-depth-buffer-optimizations.html).
|
|
140
|
+
// Here we make 4 changes to Ulrich's formula:
|
|
141
|
+
// 1. Clamp the camera near plane so we don't divide by 0.
|
|
142
|
+
// 2. Use log2 instead of log to avoid an extra multiply (shaders implement log using log2).
|
|
143
|
+
// 3. Assume K is 1 (K = maximum value in depth buffer; see Ulrich's formula above).
|
|
144
|
+
// 4. To maintain consistency with the functions "viewZToOrthographicDepth" and "viewZToPerspectiveDepth",
|
|
145
|
+
// we modify the formula here to use 'viewZ' instead of 'w'. The other functions expect a negative viewZ,
|
|
146
|
+
// so we do the same here, hence the 'viewZ.negate()' call.
|
|
147
|
+
// For visual representation of this depth curve, see https://www.desmos.com/calculator/uyqk0vex1u
|
|
148
|
+
near = near.max( 1e-6 ).toVar();
|
|
149
|
+
const numerator = log2( viewZ.negate().div( near ) );
|
|
150
|
+
const denominator = log2( far.div( near ) );
|
|
151
|
+
return numerator.div( denominator );
|
|
152
|
+
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// maps logarithmic depth in [ 0, 1 ] to viewZ
|
|
156
|
+
export const logarithmicDepthToViewZ = ( depth, near, far ) => {
|
|
157
|
+
|
|
158
|
+
// NOTE: we add a 'negate()' call to the return value here to maintain consistency with
|
|
159
|
+
// the functions "orthographicDepthToViewZ" and "perspectiveDepthToViewZ" (they return
|
|
160
|
+
// a negative viewZ).
|
|
161
|
+
const exponent = depth.mul( log( far.div( near ) ) );
|
|
162
|
+
return float( Math.E ).pow( exponent ).mul( near ).negate();
|
|
163
|
+
|
|
164
|
+
};
|
|
165
|
+
|
|
119
166
|
const depthBase = /*@__PURE__*/ nodeProxy( ViewportDepthNode, ViewportDepthNode.DEPTH_BASE );
|
|
120
167
|
|
|
121
168
|
export const depth = /*@__PURE__*/ nodeImmutable( ViewportDepthNode, ViewportDepthNode.DEPTH );
|
|
@@ -20,6 +20,7 @@ import { screenSize } from '../display/ScreenNode.js';
|
|
|
20
20
|
import { viewportMipTexture } from '../display/ViewportTextureNode.js';
|
|
21
21
|
import { textureBicubic } from '../accessors/TextureBicubic.js';
|
|
22
22
|
import { Loop } from '../utils/LoopNode.js';
|
|
23
|
+
import { BackSide } from '../../constants.js';
|
|
23
24
|
|
|
24
25
|
//
|
|
25
26
|
// Transmission
|
|
@@ -67,14 +68,17 @@ const applyIorToRoughness = /*@__PURE__*/ Fn( ( [ roughness, ior ] ) => {
|
|
|
67
68
|
]
|
|
68
69
|
} );
|
|
69
70
|
|
|
70
|
-
const
|
|
71
|
+
const viewportBackSideTexture = /*@__PURE__*/ viewportMipTexture();
|
|
72
|
+
const viewportFrontSideTexture = /*@__PURE__*/ viewportMipTexture();
|
|
71
73
|
|
|
72
|
-
const getTransmissionSample = /*@__PURE__*/ Fn( ( [ fragCoord, roughness, ior ] ) => {
|
|
74
|
+
const getTransmissionSample = /*@__PURE__*/ Fn( ( [ fragCoord, roughness, ior ], { material } ) => {
|
|
73
75
|
|
|
74
|
-
const
|
|
76
|
+
const vTexture = material.side == BackSide ? viewportBackSideTexture : viewportFrontSideTexture;
|
|
77
|
+
|
|
78
|
+
const transmissionSample = vTexture.uv( fragCoord );
|
|
75
79
|
//const transmissionSample = viewportMipTexture( fragCoord );
|
|
76
80
|
|
|
77
|
-
const lod = log2(
|
|
81
|
+
const lod = log2( screenSize.x ).mul( applyIorToRoughness( roughness, ior ) );
|
|
78
82
|
|
|
79
83
|
return textureBicubic( transmissionSample, lod );
|
|
80
84
|
|
|
@@ -233,15 +237,16 @@ const evalIridescence = /*@__PURE__*/ Fn( ( { outsideIOR, eta2, cosTheta1, thinF
|
|
|
233
237
|
// Force iridescenceIOR -> outsideIOR when thinFilmThickness -> 0.0
|
|
234
238
|
const iridescenceIOR = mix( outsideIOR, eta2, smoothstep( 0.0, 0.03, thinFilmThickness ) );
|
|
235
239
|
// Evaluate the cosTheta on the base layer (Snell law)
|
|
236
|
-
const sinTheta2Sq = outsideIOR.div( iridescenceIOR ).pow2().mul(
|
|
240
|
+
const sinTheta2Sq = outsideIOR.div( iridescenceIOR ).pow2().mul( cosTheta1.pow2().oneMinus() );
|
|
237
241
|
|
|
238
242
|
// Handle TIR:
|
|
239
|
-
const cosTheta2Sq =
|
|
240
|
-
|
|
243
|
+
const cosTheta2Sq = sinTheta2Sq.oneMinus();
|
|
244
|
+
|
|
245
|
+
If( cosTheta2Sq.lessThan( 0 ), () => {
|
|
241
246
|
|
|
242
|
-
|
|
247
|
+
return vec3( 1.0 );
|
|
243
248
|
|
|
244
|
-
}
|
|
249
|
+
} );
|
|
245
250
|
|
|
246
251
|
const cosTheta2 = cosTheta2Sq.sqrt();
|
|
247
252
|
|
|
@@ -274,17 +279,18 @@ const evalIridescence = /*@__PURE__*/ Fn( ( { outsideIOR, eta2, cosTheta1, thinF
|
|
|
274
279
|
|
|
275
280
|
// Reflectance term for m = 0 (DC term amplitude)
|
|
276
281
|
const C0 = R12.add( Rs );
|
|
277
|
-
|
|
282
|
+
const I = C0.toVar();
|
|
278
283
|
|
|
279
284
|
// Reflectance term for m > 0 (pairs of diracs)
|
|
280
|
-
|
|
281
|
-
for ( let m = 1; m <= 2; ++ m ) {
|
|
285
|
+
const Cm = Rs.sub( T121 ).toVar();
|
|
282
286
|
|
|
283
|
-
|
|
287
|
+
Loop( { start: 1, end: 2, condition: '<=', name: 'm' }, ( { m } ) => {
|
|
288
|
+
|
|
289
|
+
Cm.mulAssign( r123 );
|
|
284
290
|
const Sm = evalSensitivity( float( m ).mul( OPD ), float( m ).mul( phi ) ).mul( 2.0 );
|
|
285
|
-
I
|
|
291
|
+
I.addAssign( Cm.mul( Sm ) );
|
|
286
292
|
|
|
287
|
-
}
|
|
293
|
+
} );
|
|
288
294
|
|
|
289
295
|
// Since out of gamut colors might be produced, negative color values are clamped to 0.
|
|
290
296
|
return I.max( vec3( 0.0 ) );
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { abs, add, ceil, clamp, dFdx, dFdy, exp2, float, floor, Fn, fract, length, log2, max, min, mul, sin, sub, vec2, vec3 } from '../../tsl/TSLBase.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* See: https://casual-effects.com/research/Wyman2017Hashed/index.html
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const ALPHA_HASH_SCALE = 0.05; // Derived from trials only, and may be changed.
|
|
8
|
+
|
|
9
|
+
const hash2D = /*@__PURE__*/ Fn( ( [ value ] ) => {
|
|
10
|
+
|
|
11
|
+
return fract( mul( 1.0e4, sin( mul( 17.0, value.x ).add( mul( 0.1, value.y ) ) ) ).mul( add( 0.1, abs( sin( mul( 13.0, value.y ).add( value.x ) ) ) ) ) );
|
|
12
|
+
|
|
13
|
+
} );
|
|
14
|
+
|
|
15
|
+
const hash3D = /*@__PURE__*/ Fn( ( [ value ] ) => {
|
|
16
|
+
|
|
17
|
+
return hash2D( vec2( hash2D( value.xy ), value.z ) );
|
|
18
|
+
|
|
19
|
+
} );
|
|
20
|
+
|
|
21
|
+
const getAlphaHashThreshold = /*@__PURE__*/ Fn( ( [ position ] ) => {
|
|
22
|
+
|
|
23
|
+
// Find the discretized derivatives of our coordinates
|
|
24
|
+
const maxDeriv = max(
|
|
25
|
+
length( dFdx( position.xyz ) ),
|
|
26
|
+
length( dFdy( position.xyz ) )
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const pixScale = float( 1 ).div( float( ALPHA_HASH_SCALE ).mul( maxDeriv ) ).toVar( 'pixScale' );
|
|
30
|
+
|
|
31
|
+
// Find two nearest log-discretized noise scales
|
|
32
|
+
const pixScales = vec2(
|
|
33
|
+
exp2( floor( log2( pixScale ) ) ),
|
|
34
|
+
exp2( ceil( log2( pixScale ) ) )
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
// Compute alpha thresholds at our two noise scales
|
|
38
|
+
const alpha = vec2(
|
|
39
|
+
hash3D( floor( pixScales.x.mul( position.xyz ) ) ),
|
|
40
|
+
hash3D( floor( pixScales.y.mul( position.xyz ) ) ),
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
// Factor to interpolate lerp with
|
|
44
|
+
const lerpFactor = fract( log2( pixScale ) );
|
|
45
|
+
|
|
46
|
+
// Interpolate alpha threshold from noise at two scales
|
|
47
|
+
const x = add( mul( lerpFactor.oneMinus(), alpha.x ), mul( lerpFactor, alpha.y ) );
|
|
48
|
+
|
|
49
|
+
// Pass into CDF to compute uniformly distrib threshold
|
|
50
|
+
const a = min( lerpFactor, lerpFactor.oneMinus() );
|
|
51
|
+
const cases = vec3(
|
|
52
|
+
x.mul( x ).div( mul( 2.0, a ).mul( sub( 1.0, a ) ) ),
|
|
53
|
+
x.sub( mul( 0.5, a ) ).div( sub( 1.0, a ) ),
|
|
54
|
+
sub( 1.0, sub( 1.0, x ).mul( sub( 1.0, x ) ).div( mul( 2.0, a ).mul( sub( 1.0, a ) ) ) ) );
|
|
55
|
+
|
|
56
|
+
// Find our final, uniformly distributed alpha threshold (ατ)
|
|
57
|
+
const threshold = x.lessThan( a.oneMinus() ).select( x.lessThan( a ).select( cases.x, cases.y ), cases.z );
|
|
58
|
+
|
|
59
|
+
// Avoids ατ == 0. Could also do ατ =1-ατ
|
|
60
|
+
return clamp( threshold, 1.0e-6, 1.0 );
|
|
61
|
+
|
|
62
|
+
} ).setLayout( {
|
|
63
|
+
name: 'getAlphaHashThreshold',
|
|
64
|
+
type: 'float',
|
|
65
|
+
inputs: [
|
|
66
|
+
{ name: 'position', type: 'vec3' }
|
|
67
|
+
]
|
|
68
|
+
} );
|
|
69
|
+
|
|
70
|
+
export default getAlphaHashThreshold;
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { normalView } from '../../accessors/Normal.js';
|
|
2
|
-
import { Fn } from '../../tsl/TSLBase.js';
|
|
2
|
+
import { float, Fn } from '../../tsl/TSLBase.js';
|
|
3
3
|
|
|
4
|
-
const getGeometryRoughness = /*@__PURE__*/ Fn( () => {
|
|
4
|
+
const getGeometryRoughness = /*@__PURE__*/ Fn( ( builder ) => {
|
|
5
|
+
|
|
6
|
+
if ( builder.geometry.hasAttribute( 'normal' ) === false ) {
|
|
7
|
+
|
|
8
|
+
return float( 0 );
|
|
9
|
+
|
|
10
|
+
}
|
|
5
11
|
|
|
6
12
|
const dxy = normalView.dFdx().abs().max( normalView.dFdy().abs() );
|
|
7
13
|
const geometryRoughness = dxy.x.max( dxy.y ).max( dxy.z );
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { positionWorld } from '../../accessors/Position.js';
|
|
2
|
+
import { float, Fn, min, normalize, sub, vec3 } from '../../tsl/TSLBase.js';
|
|
3
|
+
|
|
4
|
+
// https://devlog-martinsh.blogspot.com/2011/09/box-projected-cube-environment-mapping.html
|
|
5
|
+
|
|
6
|
+
const getParallaxCorrectNormal = /*@__PURE__*/ Fn( ( [ normal, cubeSize, cubePos ] ) => {
|
|
7
|
+
|
|
8
|
+
const nDir = normalize( normal ).toVar( 'nDir' );
|
|
9
|
+
const rbmax = sub( float( 0.5 ).mul( cubeSize.sub( cubePos ) ), positionWorld ).div( nDir ).toVar( 'rbmax' );
|
|
10
|
+
const rbmin = sub( float( - 0.5 ).mul( cubeSize.sub( cubePos ) ), positionWorld ).div( nDir ).toVar( 'rbmin' );
|
|
11
|
+
const rbminmax = vec3().toVar( 'rbminmax' );
|
|
12
|
+
rbminmax.x = nDir.x.greaterThan( float( 0 ) ).select( rbmax.x, rbmin.x );
|
|
13
|
+
rbminmax.y = nDir.y.greaterThan( float( 0 ) ).select( rbmax.y, rbmin.y );
|
|
14
|
+
rbminmax.z = nDir.z.greaterThan( float( 0 ) ).select( rbmax.z, rbmin.z );
|
|
15
|
+
|
|
16
|
+
const correction = min( min( rbminmax.x, rbminmax.y ), rbminmax.z ).toVar( 'correction' );
|
|
17
|
+
const boxIntersection = positionWorld.add( nDir.mul( correction ) ).toVar( 'boxIntersection' );
|
|
18
|
+
return boxIntersection.sub( cubePos );
|
|
19
|
+
|
|
20
|
+
} );
|
|
21
|
+
|
|
22
|
+
export default getParallaxCorrectNormal;
|
|
@@ -25,6 +25,8 @@ class ComputeNode extends Node {
|
|
|
25
25
|
this.version = 1;
|
|
26
26
|
this.updateBeforeType = NodeUpdateType.OBJECT;
|
|
27
27
|
|
|
28
|
+
this.onInitFunction = null;
|
|
29
|
+
|
|
28
30
|
this.updateDispatchCount();
|
|
29
31
|
|
|
30
32
|
}
|
|
@@ -54,7 +56,13 @@ class ComputeNode extends Node {
|
|
|
54
56
|
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
onInit() {
|
|
59
|
+
onInit( callback ) {
|
|
60
|
+
|
|
61
|
+
this.onInitFunction = callback;
|
|
62
|
+
|
|
63
|
+
return this;
|
|
64
|
+
|
|
65
|
+
}
|
|
58
66
|
|
|
59
67
|
updateBefore( { renderer } ) {
|
|
60
68
|
|