@plastic-software/three 0.182.0 → 0.183.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.
- package/LICENSE +1 -1
- package/build/three.cjs +11520 -10877
- package/build/three.core.js +11732 -11340
- package/build/three.core.min.js +2 -2
- package/build/three.module.js +509 -262
- package/build/three.module.min.js +2 -2
- package/build/three.tsl.js +7 -11
- package/build/three.tsl.min.js +2 -2
- package/build/three.webgpu.js +3072 -2607
- package/build/three.webgpu.min.js +2 -2
- package/build/three.webgpu.nodes.js +3071 -2607
- package/build/three.webgpu.nodes.min.js +2 -2
- package/examples/jsm/Addons.js +0 -3
- package/examples/jsm/animation/CCDIKSolver.js +2 -2
- package/examples/jsm/controls/ArcballControls.js +3 -3
- package/examples/jsm/controls/OrbitControls.js +103 -0
- package/examples/jsm/effects/AnaglyphEffect.js +102 -7
- package/examples/jsm/environments/ColorEnvironment.js +59 -0
- package/examples/jsm/environments/RoomEnvironment.js +1 -0
- package/examples/jsm/exporters/EXRExporter.js +1 -1
- package/examples/jsm/exporters/GLTFExporter.js +131 -4
- package/examples/jsm/exporters/USDZExporter.js +22 -3
- package/examples/jsm/helpers/AnimationPathHelper.js +302 -0
- package/examples/jsm/helpers/ViewHelper.js +67 -8
- package/examples/jsm/inspector/Inspector.js +21 -5
- package/examples/jsm/inspector/tabs/Console.js +39 -5
- package/examples/jsm/inspector/tabs/Parameters.js +16 -0
- package/examples/jsm/inspector/ui/Style.js +25 -1
- package/examples/jsm/libs/meshopt_decoder.module.js +6 -5
- package/examples/jsm/lines/LineMaterial.js +6 -0
- package/examples/jsm/loaders/3MFLoader.js +2 -2
- package/examples/jsm/loaders/AMFLoader.js +2 -2
- package/examples/jsm/loaders/ColladaLoader.js +24 -4026
- package/examples/jsm/loaders/EXRLoader.js +5 -5
- package/examples/jsm/loaders/FBXLoader.js +2 -2
- package/examples/jsm/loaders/GCodeLoader.js +34 -8
- package/examples/jsm/loaders/GLTFLoader.js +122 -171
- package/examples/jsm/loaders/KMZLoader.js +5 -5
- package/examples/jsm/loaders/KTX2Loader.js +5 -5
- package/examples/jsm/loaders/LWOLoader.js +7 -39
- package/examples/jsm/loaders/NRRDLoader.js +2 -2
- package/examples/jsm/loaders/PCDLoader.js +3 -2
- package/examples/jsm/loaders/USDLoader.js +100 -40
- package/examples/jsm/loaders/UltraHDRLoader.js +182 -30
- package/examples/jsm/loaders/VRMLLoader.js +77 -0
- package/examples/jsm/loaders/VTKLoader.js +37 -24
- package/examples/jsm/loaders/collada/ColladaComposer.js +2950 -0
- package/examples/jsm/loaders/collada/ColladaParser.js +1962 -0
- package/examples/jsm/loaders/usd/USDAParser.js +447 -366
- package/examples/jsm/loaders/usd/USDCParser.js +1841 -6
- package/examples/jsm/loaders/usd/USDComposer.js +4041 -0
- package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +2 -2
- package/examples/jsm/objects/LensflareMesh.js +1 -1
- package/examples/jsm/objects/Sky.js +76 -4
- package/examples/jsm/objects/SkyMesh.js +114 -7
- package/examples/jsm/objects/Water.js +4 -3
- package/examples/jsm/objects/Water2.js +5 -3
- package/examples/jsm/objects/WaterMesh.js +5 -7
- package/examples/jsm/physics/JoltPhysics.js +7 -5
- package/examples/jsm/physics/RapierPhysics.js +6 -4
- package/examples/jsm/postprocessing/EffectComposer.js +7 -5
- package/examples/jsm/postprocessing/RenderTransitionPass.js +1 -1
- package/examples/jsm/renderers/CSS3DRenderer.js +1 -1
- package/examples/jsm/renderers/SVGRenderer.js +2 -2
- package/examples/jsm/shaders/GTAOShader.js +19 -6
- package/examples/jsm/shaders/HalftoneShader.js +12 -1
- package/examples/jsm/shaders/PoissonDenoiseShader.js +6 -2
- package/examples/jsm/shaders/SAOShader.js +17 -4
- package/examples/jsm/shaders/SSAOShader.js +11 -1
- package/examples/jsm/shaders/SSRShader.js +6 -5
- package/examples/jsm/shaders/VignetteShader.js +1 -1
- package/examples/jsm/tsl/display/AfterImageNode.js +1 -1
- package/examples/jsm/tsl/display/AnaglyphPassNode.js +456 -16
- package/examples/jsm/tsl/display/AnamorphicNode.js +1 -1
- package/examples/jsm/tsl/display/BilateralBlurNode.js +364 -0
- package/examples/jsm/tsl/display/BloomNode.js +5 -5
- package/examples/jsm/tsl/display/CRT.js +150 -0
- package/examples/jsm/tsl/display/DenoiseNode.js +1 -1
- package/examples/jsm/tsl/display/DepthOfFieldNode.js +1 -1
- package/examples/jsm/tsl/display/DotScreenNode.js +1 -1
- package/examples/jsm/tsl/display/FXAANode.js +2 -2
- package/examples/jsm/tsl/display/GTAONode.js +2 -2
- package/examples/jsm/tsl/display/GaussianBlurNode.js +11 -2
- package/examples/jsm/tsl/display/GodraysNode.js +624 -0
- package/examples/jsm/tsl/display/LensflareNode.js +1 -1
- package/examples/jsm/tsl/display/Lut3DNode.js +1 -1
- package/examples/jsm/tsl/display/OutlineNode.js +3 -3
- package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +2 -2
- package/examples/jsm/tsl/display/PixelationPassNode.js +5 -5
- package/examples/jsm/tsl/display/RGBShiftNode.js +2 -2
- package/examples/jsm/tsl/display/RetroPassNode.js +263 -0
- package/examples/jsm/tsl/display/SMAANode.js +2 -2
- package/examples/jsm/tsl/display/SSAAPassNode.js +2 -2
- package/examples/jsm/tsl/display/SSGINode.js +2 -2
- package/examples/jsm/tsl/display/SSRNode.js +7 -7
- package/examples/jsm/tsl/display/SSSNode.js +2 -2
- package/examples/jsm/tsl/display/Shape.js +29 -0
- package/examples/jsm/tsl/display/SobelOperatorNode.js +2 -2
- package/examples/jsm/tsl/display/StereoPassNode.js +1 -2
- package/examples/jsm/tsl/display/TRAANode.js +9 -12
- package/examples/jsm/tsl/display/TransitionNode.js +1 -1
- package/examples/jsm/tsl/display/depthAwareBlend.js +80 -0
- package/examples/jsm/tsl/math/Bayer.js +40 -1
- package/examples/jsm/utils/LDrawUtils.js +1 -1
- package/package.json +11 -19
- package/src/Three.Core.js +1 -1
- package/src/Three.TSL.js +5 -9
- package/src/Three.WebGPU.Nodes.js +2 -0
- package/src/Three.WebGPU.js +3 -0
- package/src/Three.js +1 -0
- package/src/animation/AnimationAction.js +1 -1
- package/src/animation/AnimationClip.js +1 -1
- package/src/animation/AnimationMixer.js +6 -0
- package/src/animation/KeyframeTrack.js +46 -7
- package/src/animation/PropertyMixer.js +4 -4
- package/src/audio/Audio.js +1 -1
- package/src/audio/AudioListener.js +5 -3
- package/src/cameras/Camera.js +32 -2
- package/src/cameras/CubeCamera.js +20 -0
- package/src/constants.js +30 -1
- package/src/core/Clock.js +7 -0
- package/src/core/Object3D.js +56 -4
- package/src/core/RenderTarget.js +3 -4
- package/src/extras/PMREMGenerator.js +4 -8
- package/src/geometries/TorusGeometry.js +8 -3
- package/src/helpers/CameraHelper.js +3 -0
- package/src/helpers/DirectionalLightHelper.js +4 -1
- package/src/helpers/HemisphereLightHelper.js +3 -0
- package/src/helpers/PointLightHelper.js +0 -24
- package/src/helpers/SpotLightHelper.js +3 -0
- package/src/lights/LightShadow.js +15 -3
- package/src/lights/webgpu/IESSpotLight.js +2 -1
- package/src/loaders/Cache.js +28 -0
- package/src/loaders/FileLoader.js +1 -1
- package/src/loaders/ImageBitmapLoader.js +8 -3
- package/src/loaders/Loader.js +6 -0
- package/src/loaders/ObjectLoader.js +18 -1
- package/src/materials/MeshLambertMaterial.js +9 -0
- package/src/materials/MeshPhongMaterial.js +9 -0
- package/src/materials/nodes/Line2NodeMaterial.js +5 -5
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +2 -0
- package/src/materials/nodes/NodeMaterial.js +15 -24
- package/src/materials/nodes/manager/NodeMaterialObserver.js +9 -3
- package/src/math/Line3.js +3 -5
- package/src/math/MathUtils.js +10 -10
- package/src/math/Matrix4.js +35 -26
- package/src/math/Quaternion.js +3 -29
- package/src/math/Vector3.js +3 -3
- package/src/math/interpolants/BezierInterpolant.js +108 -0
- package/src/nodes/Nodes.js +87 -68
- package/src/nodes/TSL.js +2 -5
- package/src/nodes/accessors/Arrays.js +1 -1
- package/src/nodes/accessors/Bitangent.js +5 -5
- package/src/nodes/accessors/BufferAttributeNode.js +1 -1
- package/src/nodes/accessors/Camera.js +149 -28
- package/src/nodes/accessors/InstanceNode.js +105 -40
- package/src/nodes/accessors/Normal.js +9 -9
- package/src/nodes/accessors/Position.js +34 -2
- package/src/nodes/accessors/SceneProperties.js +53 -0
- package/src/nodes/accessors/SkinningNode.js +12 -24
- package/src/nodes/accessors/StorageBufferNode.js +0 -19
- package/src/nodes/accessors/StorageTextureNode.js +37 -1
- package/src/nodes/accessors/Tangent.js +3 -3
- package/src/nodes/accessors/Texture3DNode.js +6 -34
- package/src/nodes/accessors/TextureNode.js +58 -22
- package/src/nodes/accessors/UniformArrayNode.js +2 -0
- package/src/nodes/core/MRTNode.js +48 -2
- package/src/nodes/core/Node.js +29 -3
- package/src/nodes/core/NodeBuilder.js +115 -40
- package/src/nodes/core/NodeError.js +28 -0
- package/src/nodes/core/NodeUtils.js +5 -3
- package/src/nodes/core/OutputStructNode.js +12 -10
- package/src/nodes/core/ParameterNode.js +2 -1
- package/src/nodes/core/StackNode.js +9 -8
- package/src/nodes/core/StackTrace.js +139 -0
- package/src/nodes/core/StructNode.js +15 -0
- package/src/nodes/core/SubBuildNode.js +1 -1
- package/src/nodes/core/UniformNode.js +2 -1
- package/src/nodes/core/VarNode.js +1 -1
- package/src/nodes/core/VaryingNode.js +1 -18
- package/src/nodes/display/BlendModes.js +0 -64
- package/src/nodes/display/ColorAdjustment.js +17 -0
- package/src/nodes/display/ColorSpaceNode.js +3 -3
- package/src/nodes/display/NormalMapNode.js +2 -2
- package/src/nodes/display/PassNode.js +21 -2
- package/src/nodes/display/RenderOutputNode.js +3 -3
- package/src/nodes/display/ScreenNode.js +2 -1
- package/src/nodes/display/ToneMappingNode.js +1 -1
- package/src/nodes/display/ToonOutlinePassNode.js +2 -2
- package/src/nodes/display/ViewportDepthNode.js +52 -4
- package/src/nodes/display/ViewportTextureNode.js +21 -4
- package/src/nodes/fog/Fog.js +18 -35
- package/src/nodes/functions/PhysicalLightingModel.js +25 -3
- package/src/nodes/geometry/RangeNode.js +4 -2
- package/src/nodes/gpgpu/ComputeNode.js +5 -4
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +2 -1
- package/src/nodes/lighting/EnvironmentNode.js +28 -3
- package/src/nodes/lighting/PointShadowNode.js +24 -12
- package/src/nodes/lighting/ShadowFilterNode.js +15 -43
- package/src/nodes/lighting/ShadowNode.js +54 -32
- package/src/nodes/math/ConditionalNode.js +2 -2
- package/src/nodes/math/MathNode.js +3 -40
- package/src/nodes/math/OperatorNode.js +2 -1
- package/src/nodes/pmrem/PMREMUtils.js +9 -15
- package/src/nodes/tsl/TSLCore.js +13 -10
- package/src/nodes/utils/DebugNode.js +11 -11
- package/src/nodes/utils/JoinNode.js +2 -2
- package/src/nodes/utils/LoopNode.js +1 -1
- package/src/nodes/utils/MemberNode.js +1 -1
- package/src/nodes/utils/RTTNode.js +1 -1
- package/src/nodes/utils/ReflectorNode.js +2 -3
- package/src/nodes/utils/SpriteSheetUV.js +35 -0
- package/src/nodes/utils/UVUtils.js +4 -2
- package/src/objects/BatchedMesh.js +22 -12
- package/src/objects/InstancedMesh.js +11 -0
- package/src/renderers/WebGLRenderer.js +34 -60
- package/src/renderers/common/Backend.js +21 -0
- package/src/renderers/common/Background.js +7 -4
- package/src/renderers/common/BindGroup.js +1 -9
- package/src/renderers/common/Bindings.js +20 -5
- package/src/renderers/common/BlendMode.js +143 -0
- package/src/renderers/common/BundleGroup.js +1 -1
- package/src/renderers/common/CubeRenderTarget.js +50 -6
- package/src/renderers/common/Geometries.js +17 -3
- package/src/renderers/common/Lighting.js +5 -21
- package/src/renderers/common/Pipelines.js +4 -4
- package/src/renderers/common/PostProcessing.js +8 -206
- package/src/renderers/common/RenderBundles.js +2 -1
- package/src/renderers/common/RenderContext.js +16 -0
- package/src/renderers/common/RenderContexts.js +33 -56
- package/src/renderers/common/RenderLists.js +2 -1
- package/src/renderers/common/RenderObject.js +2 -3
- package/src/renderers/common/RenderObjectPipeline.js +40 -0
- package/src/renderers/common/RenderObjects.js +18 -2
- package/src/renderers/common/RenderPipeline.js +203 -17
- package/src/renderers/common/Renderer.js +207 -40
- package/src/renderers/common/Sampler.js +4 -4
- package/src/renderers/common/StorageBuffer.js +13 -1
- package/src/renderers/common/Textures.js +16 -0
- package/src/renderers/common/TimestampQueryPool.js +5 -3
- package/src/renderers/common/Uniform.js +8 -0
- package/src/renderers/common/UniformsGroup.js +60 -0
- package/src/renderers/common/XRManager.js +2 -2
- package/src/renderers/common/nodes/NodeBuilderState.js +1 -1
- package/src/renderers/common/nodes/{Nodes.js → NodeManager.js} +18 -6
- package/src/renderers/common/nodes/NodeStorageBuffer.js +13 -2
- package/src/renderers/shaders/ShaderChunk/batching_pars_vertex.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/color_fragment.glsl.js +1 -5
- package/src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl.js +1 -5
- package/src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl.js +1 -5
- package/src/renderers/shaders/ShaderChunk/color_vertex.glsl.js +8 -10
- package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +7 -11
- package/src/renderers/shaders/ShaderChunk/lights_fragment_end.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +6 -2
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +23 -1
- package/src/renderers/shaders/ShaderChunk/packing.glsl.js +20 -4
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +55 -24
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/shadow.glsl.js +1 -0
- package/src/renderers/shaders/ShaderLib.js +4 -2
- package/src/renderers/shaders/UniformsLib.js +0 -3
- package/src/renderers/webgl/WebGLBackground.js +2 -2
- package/src/renderers/webgl/WebGLBindingStates.js +99 -27
- package/src/renderers/webgl/WebGLEnvironments.js +228 -0
- package/src/renderers/webgl/WebGLGeometries.js +10 -7
- package/src/renderers/webgl/WebGLMaterials.js +12 -0
- package/src/renderers/webgl/WebGLObjects.js +3 -1
- package/src/renderers/webgl/WebGLProgram.js +2 -2
- package/src/renderers/webgl/WebGLPrograms.js +10 -4
- package/src/renderers/webgl/WebGLRenderLists.js +15 -0
- package/src/renderers/webgl/WebGLShadowMap.js +5 -4
- package/src/renderers/webgl/WebGLState.js +12 -17
- package/src/renderers/webgl-fallback/WebGLBackend.js +71 -7
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +98 -29
- package/src/renderers/webgl-fallback/utils/WebGLState.js +168 -7
- package/src/renderers/webgpu/WebGPUBackend.js +58 -9
- package/src/renderers/webgpu/WebGPURenderer.js +1 -0
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +257 -45
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +8 -19
- package/src/renderers/webgpu/utils/WebGPUConstants.js +1 -1
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +56 -31
- package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +152 -200
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +25 -25
- package/src/renderers/webgpu/utils/WebGPUUtils.js +10 -6
- package/src/renderers/webxr/WebXRManager.js +2 -2
- package/src/textures/Texture.js +2 -2
- package/src/utils.js +246 -3
- package/examples/jsm/materials/MeshGouraudMaterial.js +0 -433
- package/examples/jsm/materials/MeshPostProcessingMaterial.js +0 -167
- package/examples/jsm/shaders/GodRaysShader.js +0 -333
- package/src/nodes/accessors/SceneNode.js +0 -145
- package/src/nodes/code/ScriptableNode.js +0 -726
- package/src/nodes/code/ScriptableValueNode.js +0 -253
- package/src/nodes/display/PosterizeNode.js +0 -65
- package/src/nodes/utils/SpriteSheetUVNode.js +0 -90
- package/src/renderers/webgl/WebGLCubeMaps.js +0 -99
- package/src/renderers/webgl/WebGLCubeUVMaps.js +0 -134
|
@@ -79,6 +79,16 @@ const SSAOShader = {
|
|
|
79
79
|
|
|
80
80
|
#include <packing>
|
|
81
81
|
|
|
82
|
+
#ifdef USE_REVERSED_DEPTH_BUFFER
|
|
83
|
+
|
|
84
|
+
const float depthThreshold = 0.0;
|
|
85
|
+
|
|
86
|
+
#else
|
|
87
|
+
|
|
88
|
+
const float depthThreshold = 1.0;
|
|
89
|
+
|
|
90
|
+
#endif
|
|
91
|
+
|
|
82
92
|
float getDepth( const in vec2 screenPosition ) {
|
|
83
93
|
|
|
84
94
|
return texture2D( tDepth, screenPosition ).x;
|
|
@@ -137,7 +147,7 @@ const SSAOShader = {
|
|
|
137
147
|
|
|
138
148
|
float depth = getDepth( vUv );
|
|
139
149
|
|
|
140
|
-
if ( depth ==
|
|
150
|
+
if ( depth == depthThreshold ) {
|
|
141
151
|
|
|
142
152
|
gl_FragColor = vec4( 1.0 ); // don't influence background
|
|
143
153
|
|
|
@@ -96,7 +96,7 @@ const SSRShader = {
|
|
|
96
96
|
float x0=point.x,y0=point.y,z0=point.z;
|
|
97
97
|
float x=planePoint.x,y=planePoint.y,z=planePoint.z;
|
|
98
98
|
float d=-(a*x+b*y+c*z);
|
|
99
|
-
float distance=
|
|
99
|
+
float distance=a*x0+b*y0+c*z0+d;
|
|
100
100
|
return distance;
|
|
101
101
|
}
|
|
102
102
|
float getDepth( const in vec2 uv ) {
|
|
@@ -170,17 +170,17 @@ const SSRShader = {
|
|
|
170
170
|
#endif
|
|
171
171
|
d1=viewPositionToXY(d1viewPosition);
|
|
172
172
|
|
|
173
|
-
float totalLen=length(d1-d0);
|
|
174
173
|
float xLen=d1.x-d0.x;
|
|
175
174
|
float yLen=d1.y-d0.y;
|
|
176
175
|
float totalStep=max(abs(xLen),abs(yLen));
|
|
177
176
|
float xSpan=xLen/totalStep;
|
|
178
177
|
float ySpan=yLen/totalStep;
|
|
179
|
-
|
|
178
|
+
float sStep=1./totalStep;
|
|
179
|
+
float s=sStep; // start at sStep since loop starts at i=1
|
|
180
|
+
for(float i=1.;i<float(MAX_STEP);i++){
|
|
180
181
|
if(i>=totalStep) break;
|
|
181
182
|
vec2 xy=vec2(d0.x+i*xSpan,d0.y+i*ySpan);
|
|
182
183
|
if(xy.x<0.||xy.x>resolution.x||xy.y<0.||xy.y>resolution.y) break;
|
|
183
|
-
float s=length(xy-d0)/totalLen;
|
|
184
184
|
vec2 uv=xy/resolution;
|
|
185
185
|
|
|
186
186
|
float d = getDepth(uv);
|
|
@@ -221,7 +221,7 @@ const SSRShader = {
|
|
|
221
221
|
|
|
222
222
|
if(hit){
|
|
223
223
|
vec3 vN=getViewNormal( uv );
|
|
224
|
-
if(dot(viewReflectDir,vN)>=0.)
|
|
224
|
+
if(dot(viewReflectDir,vN)>=0.) break; // treat backfaces as opaque
|
|
225
225
|
float distance=pointPlaneDistance(vP,viewPosition,viewNormal);
|
|
226
226
|
if(distance>maxDistance) break;
|
|
227
227
|
float op=opacity;
|
|
@@ -240,6 +240,7 @@ const SSRShader = {
|
|
|
240
240
|
break;
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
|
+
s+=sStep;
|
|
243
244
|
}
|
|
244
245
|
}
|
|
245
246
|
`
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Based on [PaintEffect postprocess from ro.me](
|
|
7
|
+
* Based on [PaintEffect postprocess from ro.me](https://github.com/dataarts/3-dreams-of-black/blob/master/deploy/js/effects/PaintEffect.js).
|
|
8
8
|
*
|
|
9
9
|
* @constant
|
|
10
10
|
* @type {ShaderMaterial~Shader}
|
|
@@ -239,6 +239,6 @@ class AfterImageNode extends TempNode {
|
|
|
239
239
|
* @param {(Node<float>|number)} [damp=0.96] - The damping intensity. A higher value means a stronger after image effect.
|
|
240
240
|
* @returns {AfterImageNode}
|
|
241
241
|
*/
|
|
242
|
-
export const afterImage = ( node, damp ) =>
|
|
242
|
+
export const afterImage = ( node, damp ) => new AfterImageNode( convertToTexture( node ), nodeObject( damp ) );
|
|
243
243
|
|
|
244
244
|
export default AfterImageNode;
|
|
@@ -1,12 +1,284 @@
|
|
|
1
|
-
import { Matrix3, NodeMaterial } from 'three/webgpu';
|
|
2
|
-
import { clamp,
|
|
1
|
+
import { Matrix3, NodeMaterial, Vector3 } from 'three/webgpu';
|
|
2
|
+
import { clamp, Fn, vec4, uv, uniform, max } from 'three/tsl';
|
|
3
3
|
import StereoCompositePassNode from './StereoCompositePassNode.js';
|
|
4
|
+
import { frameCorners } from '../../utils/CameraUtils.js';
|
|
5
|
+
|
|
6
|
+
const _eyeL = /*@__PURE__*/ new Vector3();
|
|
7
|
+
const _eyeR = /*@__PURE__*/ new Vector3();
|
|
8
|
+
const _screenBottomLeft = /*@__PURE__*/ new Vector3();
|
|
9
|
+
const _screenBottomRight = /*@__PURE__*/ new Vector3();
|
|
10
|
+
const _screenTopLeft = /*@__PURE__*/ new Vector3();
|
|
11
|
+
const _right = /*@__PURE__*/ new Vector3();
|
|
12
|
+
const _up = /*@__PURE__*/ new Vector3();
|
|
13
|
+
const _forward = /*@__PURE__*/ new Vector3();
|
|
14
|
+
const _screenCenter = /*@__PURE__*/ new Vector3();
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Anaglyph algorithm types.
|
|
18
|
+
* @readonly
|
|
19
|
+
* @enum {string}
|
|
20
|
+
*/
|
|
21
|
+
const AnaglyphAlgorithm = {
|
|
22
|
+
TRUE: 'true',
|
|
23
|
+
GREY: 'grey',
|
|
24
|
+
COLOUR: 'colour',
|
|
25
|
+
HALF_COLOUR: 'halfColour',
|
|
26
|
+
DUBOIS: 'dubois',
|
|
27
|
+
OPTIMISED: 'optimised',
|
|
28
|
+
COMPROMISE: 'compromise'
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Anaglyph color modes.
|
|
33
|
+
* @readonly
|
|
34
|
+
* @enum {string}
|
|
35
|
+
*/
|
|
36
|
+
const AnaglyphColorMode = {
|
|
37
|
+
RED_CYAN: 'redCyan',
|
|
38
|
+
MAGENTA_CYAN: 'magentaCyan',
|
|
39
|
+
MAGENTA_GREEN: 'magentaGreen'
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Standard luminance coefficients (ITU-R BT.601).
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
46
|
+
const LUMINANCE = { R: 0.299, G: 0.587, B: 0.114 };
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Creates an anaglyph matrix pair from left and right channel specifications.
|
|
50
|
+
* This provides a more intuitive way to define how source RGB channels map to output RGB channels.
|
|
51
|
+
*
|
|
52
|
+
* Each specification object has keys 'r', 'g', 'b' for output channels.
|
|
53
|
+
* Each output channel value is [rCoef, gCoef, bCoef] defining how much of each input channel contributes.
|
|
54
|
+
*
|
|
55
|
+
* @private
|
|
56
|
+
* @param {Object} leftSpec - Specification for left eye contribution
|
|
57
|
+
* @param {Object} rightSpec - Specification for right eye contribution
|
|
58
|
+
* @returns {{left: number[], right: number[]}} Column-major arrays for Matrix3
|
|
59
|
+
*/
|
|
60
|
+
function createMatrixPair( leftSpec, rightSpec ) {
|
|
61
|
+
|
|
62
|
+
// Convert row-major specification to column-major array for Matrix3
|
|
63
|
+
// Matrix3.fromArray expects [col0row0, col0row1, col0row2, col1row0, col1row1, col1row2, col2row0, col2row1, col2row2]
|
|
64
|
+
// Which represents:
|
|
65
|
+
// | col0row0 col1row0 col2row0 | | m[0] m[3] m[6] |
|
|
66
|
+
// | col0row1 col1row1 col2row1 | = | m[1] m[4] m[7] |
|
|
67
|
+
// | col0row2 col1row2 col2row2 | | m[2] m[5] m[8] |
|
|
68
|
+
|
|
69
|
+
function specToColumnMajor( spec ) {
|
|
70
|
+
|
|
71
|
+
const r = spec.r || [ 0, 0, 0 ]; // Output red channel coefficients [fromR, fromG, fromB]
|
|
72
|
+
const g = spec.g || [ 0, 0, 0 ]; // Output green channel coefficients
|
|
73
|
+
const b = spec.b || [ 0, 0, 0 ]; // Output blue channel coefficients
|
|
74
|
+
|
|
75
|
+
// Row-major matrix would be:
|
|
76
|
+
// | r[0] r[1] r[2] | (how input RGB maps to output R)
|
|
77
|
+
// | g[0] g[1] g[2] | (how input RGB maps to output G)
|
|
78
|
+
// | b[0] b[1] b[2] | (how input RGB maps to output B)
|
|
79
|
+
|
|
80
|
+
// Column-major for Matrix3:
|
|
81
|
+
return [
|
|
82
|
+
r[ 0 ], g[ 0 ], b[ 0 ], // Column 0: coefficients for input R
|
|
83
|
+
r[ 1 ], g[ 1 ], b[ 1 ], // Column 1: coefficients for input G
|
|
84
|
+
r[ 2 ], g[ 2 ], b[ 2 ] // Column 2: coefficients for input B
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
left: specToColumnMajor( leftSpec ),
|
|
91
|
+
right: specToColumnMajor( rightSpec )
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Shorthand for luminance coefficients.
|
|
98
|
+
* @private
|
|
99
|
+
*/
|
|
100
|
+
const LUM = [ LUMINANCE.R, LUMINANCE.G, LUMINANCE.B ];
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Conversion matrices for different anaglyph algorithms.
|
|
104
|
+
* Based on research from "Introducing a New Anaglyph Method: Compromise Anaglyph" by Jure Ahtik
|
|
105
|
+
* and various other sources.
|
|
106
|
+
*
|
|
107
|
+
* Matrices are defined using createMatrixPair for clarity:
|
|
108
|
+
* - Each spec object defines how input RGB maps to output RGB
|
|
109
|
+
* - Keys 'r', 'g', 'b' represent output channels
|
|
110
|
+
* - Values are [rCoef, gCoef, bCoef] for input channel contribution
|
|
111
|
+
*
|
|
112
|
+
* @private
|
|
113
|
+
*/
|
|
114
|
+
const ANAGLYPH_MATRICES = {
|
|
115
|
+
|
|
116
|
+
// True Anaglyph - Red channel from left, luminance to cyan channel for right
|
|
117
|
+
// Paper: Left=[R,0,0], Right=[0,0,Lum]
|
|
118
|
+
[ AnaglyphAlgorithm.TRUE ]: {
|
|
119
|
+
[ AnaglyphColorMode.RED_CYAN ]: createMatrixPair(
|
|
120
|
+
{ r: [ 1, 0, 0 ] }, // Left: R -> outR
|
|
121
|
+
{ g: LUM, b: LUM } // Right: Lum -> outG, Lum -> outB
|
|
122
|
+
),
|
|
123
|
+
[ AnaglyphColorMode.MAGENTA_CYAN ]: createMatrixPair(
|
|
124
|
+
{ r: [ 1, 0, 0 ], b: [ 0, 0, 0.5 ] }, // Left: R -> outR, partial B -> outB
|
|
125
|
+
{ g: LUM, b: [ 0, 0, 0.5 ] } // Right: Lum -> outG, partial B
|
|
126
|
+
),
|
|
127
|
+
[ AnaglyphColorMode.MAGENTA_GREEN ]: createMatrixPair(
|
|
128
|
+
{ r: [ 1, 0, 0 ], b: LUM }, // Left: R -> outR, Lum -> outB
|
|
129
|
+
{ g: LUM } // Right: Lum -> outG
|
|
130
|
+
)
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
// Grey Anaglyph - Luminance-based, no color, minimal ghosting
|
|
134
|
+
// Paper: Left=[Lum,0,0], Right=[0,0,Lum]
|
|
135
|
+
[ AnaglyphAlgorithm.GREY ]: {
|
|
136
|
+
[ AnaglyphColorMode.RED_CYAN ]: createMatrixPair(
|
|
137
|
+
{ r: LUM }, // Left: Lum -> outR
|
|
138
|
+
{ g: LUM, b: LUM } // Right: Lum -> outG, Lum -> outB
|
|
139
|
+
),
|
|
140
|
+
[ AnaglyphColorMode.MAGENTA_CYAN ]: createMatrixPair(
|
|
141
|
+
{ r: LUM, b: [ 0.15, 0.29, 0.06 ] }, // Left: Lum -> outR, half-Lum -> outB
|
|
142
|
+
{ g: LUM, b: [ 0.15, 0.29, 0.06 ] } // Right: Lum -> outG, half-Lum -> outB
|
|
143
|
+
),
|
|
144
|
+
[ AnaglyphColorMode.MAGENTA_GREEN ]: createMatrixPair(
|
|
145
|
+
{ r: LUM, b: LUM }, // Left: Lum -> outR, Lum -> outB
|
|
146
|
+
{ g: LUM } // Right: Lum -> outG
|
|
147
|
+
)
|
|
148
|
+
},
|
|
149
|
+
|
|
150
|
+
// Colour Anaglyph - Full color, high retinal rivalry
|
|
151
|
+
// Paper: Left=[R,0,0], Right=[0,G,B]
|
|
152
|
+
[ AnaglyphAlgorithm.COLOUR ]: {
|
|
153
|
+
[ AnaglyphColorMode.RED_CYAN ]: createMatrixPair(
|
|
154
|
+
{ r: [ 1, 0, 0 ] }, // Left: R -> outR
|
|
155
|
+
{ g: [ 0, 1, 0 ], b: [ 0, 0, 1 ] } // Right: G -> outG, B -> outB
|
|
156
|
+
),
|
|
157
|
+
[ AnaglyphColorMode.MAGENTA_CYAN ]: createMatrixPair(
|
|
158
|
+
{ r: [ 1, 0, 0 ], b: [ 0, 0, 0.5 ] }, // Left: R -> outR, partial B -> outB
|
|
159
|
+
{ g: [ 0, 1, 0 ], b: [ 0, 0, 0.5 ] } // Right: G -> outG, partial B -> outB
|
|
160
|
+
),
|
|
161
|
+
[ AnaglyphColorMode.MAGENTA_GREEN ]: createMatrixPair(
|
|
162
|
+
{ r: [ 1, 0, 0 ], b: [ 0, 0, 1 ] }, // Left: R -> outR, B -> outB
|
|
163
|
+
{ g: [ 0, 1, 0 ] } // Right: G -> outG
|
|
164
|
+
)
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
// Half-Colour Anaglyph - Luminance for left red, full color for right cyan
|
|
168
|
+
// Paper: Left=[Lum,0,0], Right=[0,G,B]
|
|
169
|
+
[ AnaglyphAlgorithm.HALF_COLOUR ]: {
|
|
170
|
+
[ AnaglyphColorMode.RED_CYAN ]: createMatrixPair(
|
|
171
|
+
{ r: LUM }, // Left: Lum -> outR
|
|
172
|
+
{ g: [ 0, 1, 0 ], b: [ 0, 0, 1 ] } // Right: G -> outG, B -> outB
|
|
173
|
+
),
|
|
174
|
+
[ AnaglyphColorMode.MAGENTA_CYAN ]: createMatrixPair(
|
|
175
|
+
{ r: LUM, b: [ 0.15, 0.29, 0.06 ] }, // Left: Lum -> outR, half-Lum -> outB
|
|
176
|
+
{ g: [ 0, 1, 0 ], b: [ 0.15, 0.29, 0.06 ] } // Right: G -> outG, half-Lum -> outB
|
|
177
|
+
),
|
|
178
|
+
[ AnaglyphColorMode.MAGENTA_GREEN ]: createMatrixPair(
|
|
179
|
+
{ r: LUM, b: LUM }, // Left: Lum -> outR, Lum -> outB
|
|
180
|
+
{ g: [ 0, 1, 0 ] } // Right: G -> outG
|
|
181
|
+
)
|
|
182
|
+
},
|
|
183
|
+
|
|
184
|
+
// Dubois Anaglyph - Least-squares optimized for specific glasses
|
|
185
|
+
// From https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.7.6968&rep=rep1&type=pdf
|
|
186
|
+
[ AnaglyphAlgorithm.DUBOIS ]: {
|
|
187
|
+
[ AnaglyphColorMode.RED_CYAN ]: createMatrixPair(
|
|
188
|
+
{
|
|
189
|
+
r: [ 0.4561, 0.500484, 0.176381 ],
|
|
190
|
+
g: [ - 0.0400822, - 0.0378246, - 0.0157589 ],
|
|
191
|
+
b: [ - 0.0152161, - 0.0205971, - 0.00546856 ]
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
r: [ - 0.0434706, - 0.0879388, - 0.00155529 ],
|
|
195
|
+
g: [ 0.378476, 0.73364, - 0.0184503 ],
|
|
196
|
+
b: [ - 0.0721527, - 0.112961, 1.2264 ]
|
|
197
|
+
}
|
|
198
|
+
),
|
|
199
|
+
[ AnaglyphColorMode.MAGENTA_CYAN ]: createMatrixPair(
|
|
200
|
+
{
|
|
201
|
+
r: [ 0.4561, 0.500484, 0.176381 ],
|
|
202
|
+
g: [ - 0.0400822, - 0.0378246, - 0.0157589 ],
|
|
203
|
+
b: [ 0.088, 0.088, - 0.003 ]
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
r: [ - 0.0434706, - 0.0879388, - 0.00155529 ],
|
|
207
|
+
g: [ 0.378476, 0.73364, - 0.0184503 ],
|
|
208
|
+
b: [ 0.088, 0.088, 0.613 ]
|
|
209
|
+
}
|
|
210
|
+
),
|
|
211
|
+
[ AnaglyphColorMode.MAGENTA_GREEN ]: createMatrixPair(
|
|
212
|
+
{
|
|
213
|
+
r: [ 0.4561, 0.500484, 0.176381 ],
|
|
214
|
+
b: [ - 0.0434706, - 0.0879388, - 0.00155529 ]
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
g: [ 0.378476 + 0.4561, 0.73364 + 0.500484, - 0.0184503 + 0.176381 ]
|
|
218
|
+
}
|
|
219
|
+
)
|
|
220
|
+
},
|
|
221
|
+
|
|
222
|
+
// Optimised Anaglyph - Improved color with reduced retinal rivalry
|
|
223
|
+
// Paper: Left=[0,0.7G+0.3B,0,0], Right=[0,G,B]
|
|
224
|
+
[ AnaglyphAlgorithm.OPTIMISED ]: {
|
|
225
|
+
[ AnaglyphColorMode.RED_CYAN ]: createMatrixPair(
|
|
226
|
+
{ r: [ 0, 0.7, 0.3 ] }, // Left: 0.7G+0.3B -> outR
|
|
227
|
+
{ g: [ 0, 1, 0 ], b: [ 0, 0, 1 ] } // Right: G -> outG, B -> outB
|
|
228
|
+
),
|
|
229
|
+
[ AnaglyphColorMode.MAGENTA_CYAN ]: createMatrixPair(
|
|
230
|
+
{ r: [ 0, 0.7, 0.3 ], b: [ 0, 0, 0.5 ] }, // Left: 0.7G+0.3B -> outR, partial B
|
|
231
|
+
{ g: [ 0, 1, 0 ], b: [ 0, 0, 0.5 ] } // Right: G -> outG, partial B
|
|
232
|
+
),
|
|
233
|
+
[ AnaglyphColorMode.MAGENTA_GREEN ]: createMatrixPair(
|
|
234
|
+
{ r: [ 0, 0.7, 0.3 ], b: [ 0, 0, 1 ] }, // Left: 0.7G+0.3B -> outR, B -> outB
|
|
235
|
+
{ g: [ 0, 1, 0 ] } // Right: G -> outG
|
|
236
|
+
)
|
|
237
|
+
},
|
|
238
|
+
|
|
239
|
+
// Compromise Anaglyph - Best balance of color and stereo effect
|
|
240
|
+
// From Ahtik, J., "Techniques of Rendering Anaglyphs for Use in Art"
|
|
241
|
+
// Paper matrix [8]: Left=[0.439R+0.447G+0.148B, 0, 0], Right=[0, 0.095R+0.934G+0.005B, 0.018R+0.028G+1.057B]
|
|
242
|
+
[ AnaglyphAlgorithm.COMPROMISE ]: {
|
|
243
|
+
[ AnaglyphColorMode.RED_CYAN ]: createMatrixPair(
|
|
244
|
+
{ r: [ 0.439, 0.447, 0.148 ] }, // Left: weighted RGB -> outR
|
|
245
|
+
{
|
|
246
|
+
g: [ 0.095, 0.934, 0.005 ], // Right: weighted RGB -> outG
|
|
247
|
+
b: [ 0.018, 0.028, 1.057 ] // Right: weighted RGB -> outB
|
|
248
|
+
}
|
|
249
|
+
),
|
|
250
|
+
[ AnaglyphColorMode.MAGENTA_CYAN ]: createMatrixPair(
|
|
251
|
+
{
|
|
252
|
+
r: [ 0.439, 0.447, 0.148 ],
|
|
253
|
+
b: [ 0.009, 0.014, 0.074 ] // Partial blue from left
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
g: [ 0.095, 0.934, 0.005 ],
|
|
257
|
+
b: [ 0.009, 0.014, 0.528 ] // Partial blue from right
|
|
258
|
+
}
|
|
259
|
+
),
|
|
260
|
+
[ AnaglyphColorMode.MAGENTA_GREEN ]: createMatrixPair(
|
|
261
|
+
{
|
|
262
|
+
r: [ 0.439, 0.447, 0.148 ],
|
|
263
|
+
b: [ 0.018, 0.028, 1.057 ]
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
g: [ 0.095 + 0.439, 0.934 + 0.447, 0.005 + 0.148 ]
|
|
267
|
+
}
|
|
268
|
+
)
|
|
269
|
+
}
|
|
270
|
+
};
|
|
4
271
|
|
|
5
272
|
/**
|
|
6
|
-
* A render pass node that creates an anaglyph effect
|
|
273
|
+
* A render pass node that creates an anaglyph effect using physically-correct
|
|
274
|
+
* off-axis stereo projection.
|
|
275
|
+
*
|
|
276
|
+
* This implementation uses CameraUtils.frameCorners() to align stereo
|
|
277
|
+
* camera frustums to a virtual screen plane, providing accurate depth
|
|
278
|
+
* perception with zero parallax at the plane distance.
|
|
7
279
|
*
|
|
8
280
|
* @augments StereoCompositePassNode
|
|
9
|
-
* @three_import import { anaglyphPass } from 'three/addons/tsl/display/AnaglyphPassNode.js';
|
|
281
|
+
* @three_import import { anaglyphPass, AnaglyphAlgorithm, AnaglyphColorMode } from 'three/addons/tsl/display/AnaglyphPassNode.js';
|
|
10
282
|
*/
|
|
11
283
|
class AnaglyphPassNode extends StereoCompositePassNode {
|
|
12
284
|
|
|
@@ -35,7 +307,47 @@ class AnaglyphPassNode extends StereoCompositePassNode {
|
|
|
35
307
|
*/
|
|
36
308
|
this.isAnaglyphPassNode = true;
|
|
37
309
|
|
|
38
|
-
|
|
310
|
+
/**
|
|
311
|
+
* The interpupillary distance (eye separation) in world units.
|
|
312
|
+
* Typical human IPD is 0.064 meters (64mm).
|
|
313
|
+
*
|
|
314
|
+
* @type {number}
|
|
315
|
+
* @default 0.064
|
|
316
|
+
*/
|
|
317
|
+
this.eyeSep = 0.064;
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* The distance in world units from the viewer to the virtual
|
|
321
|
+
* screen plane where zero parallax (screen depth) occurs.
|
|
322
|
+
* Objects at this distance appear at the screen surface.
|
|
323
|
+
* Objects closer appear in front of the screen (negative parallax).
|
|
324
|
+
* Objects further appear behind the screen (positive parallax).
|
|
325
|
+
*
|
|
326
|
+
* The screen dimensions are derived from the camera's FOV and aspect ratio
|
|
327
|
+
* at this distance, ensuring the stereo view matches the camera's field of view.
|
|
328
|
+
*
|
|
329
|
+
* @type {number}
|
|
330
|
+
* @default 0.5
|
|
331
|
+
*/
|
|
332
|
+
this.planeDistance = 0.5;
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* The current anaglyph algorithm.
|
|
336
|
+
*
|
|
337
|
+
* @private
|
|
338
|
+
* @type {string}
|
|
339
|
+
* @default 'dubois'
|
|
340
|
+
*/
|
|
341
|
+
this._algorithm = AnaglyphAlgorithm.DUBOIS;
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* The current color mode.
|
|
345
|
+
*
|
|
346
|
+
* @private
|
|
347
|
+
* @type {string}
|
|
348
|
+
* @default 'redCyan'
|
|
349
|
+
*/
|
|
350
|
+
this._colorMode = AnaglyphColorMode.RED_CYAN;
|
|
39
351
|
|
|
40
352
|
/**
|
|
41
353
|
* Color matrix node for the left eye.
|
|
@@ -43,11 +355,7 @@ class AnaglyphPassNode extends StereoCompositePassNode {
|
|
|
43
355
|
* @private
|
|
44
356
|
* @type {UniformNode<mat3>}
|
|
45
357
|
*/
|
|
46
|
-
this._colorMatrixLeft = uniform( new Matrix3()
|
|
47
|
-
0.456100, - 0.0400822, - 0.0152161,
|
|
48
|
-
0.500484, - 0.0378246, - 0.0205971,
|
|
49
|
-
0.176381, - 0.0157589, - 0.00546856
|
|
50
|
-
] ) );
|
|
358
|
+
this._colorMatrixLeft = uniform( new Matrix3() );
|
|
51
359
|
|
|
52
360
|
/**
|
|
53
361
|
* Color matrix node for the right eye.
|
|
@@ -55,11 +363,141 @@ class AnaglyphPassNode extends StereoCompositePassNode {
|
|
|
55
363
|
* @private
|
|
56
364
|
* @type {UniformNode<mat3>}
|
|
57
365
|
*/
|
|
58
|
-
this._colorMatrixRight = uniform( new Matrix3()
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
366
|
+
this._colorMatrixRight = uniform( new Matrix3() );
|
|
367
|
+
|
|
368
|
+
// Initialize with default matrices
|
|
369
|
+
this._updateMatrices();
|
|
370
|
+
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Gets the current anaglyph algorithm.
|
|
375
|
+
*
|
|
376
|
+
* @type {string}
|
|
377
|
+
*/
|
|
378
|
+
get algorithm() {
|
|
379
|
+
|
|
380
|
+
return this._algorithm;
|
|
381
|
+
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Sets the anaglyph algorithm.
|
|
386
|
+
*
|
|
387
|
+
* @type {string}
|
|
388
|
+
*/
|
|
389
|
+
set algorithm( value ) {
|
|
390
|
+
|
|
391
|
+
if ( this._algorithm !== value ) {
|
|
392
|
+
|
|
393
|
+
this._algorithm = value;
|
|
394
|
+
this._updateMatrices();
|
|
395
|
+
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Gets the current color mode.
|
|
402
|
+
*
|
|
403
|
+
* @type {string}
|
|
404
|
+
*/
|
|
405
|
+
get colorMode() {
|
|
406
|
+
|
|
407
|
+
return this._colorMode;
|
|
408
|
+
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Sets the color mode.
|
|
413
|
+
*
|
|
414
|
+
* @type {string}
|
|
415
|
+
*/
|
|
416
|
+
set colorMode( value ) {
|
|
417
|
+
|
|
418
|
+
if ( this._colorMode !== value ) {
|
|
419
|
+
|
|
420
|
+
this._colorMode = value;
|
|
421
|
+
this._updateMatrices();
|
|
422
|
+
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Updates the color matrices based on current algorithm and color mode.
|
|
429
|
+
*
|
|
430
|
+
* @private
|
|
431
|
+
*/
|
|
432
|
+
_updateMatrices() {
|
|
433
|
+
|
|
434
|
+
const matrices = ANAGLYPH_MATRICES[ this._algorithm ][ this._colorMode ];
|
|
435
|
+
|
|
436
|
+
this._colorMatrixLeft.value.fromArray( matrices.left );
|
|
437
|
+
this._colorMatrixRight.value.fromArray( matrices.right );
|
|
438
|
+
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Updates the internal stereo camera using frameCorners for
|
|
443
|
+
* physically-correct off-axis projection.
|
|
444
|
+
*
|
|
445
|
+
* @param {number} coordinateSystem - The current coordinate system.
|
|
446
|
+
*/
|
|
447
|
+
updateStereoCamera( coordinateSystem ) {
|
|
448
|
+
|
|
449
|
+
const { stereo, camera } = this;
|
|
450
|
+
|
|
451
|
+
stereo.cameraL.coordinateSystem = coordinateSystem;
|
|
452
|
+
stereo.cameraR.coordinateSystem = coordinateSystem;
|
|
453
|
+
|
|
454
|
+
// Get the camera's local coordinate axes from its world matrix
|
|
455
|
+
camera.matrixWorld.extractBasis( _right, _up, _forward );
|
|
456
|
+
_right.normalize();
|
|
457
|
+
_up.normalize();
|
|
458
|
+
_forward.normalize();
|
|
459
|
+
|
|
460
|
+
// Calculate eye positions
|
|
461
|
+
const halfSep = this.eyeSep / 2;
|
|
462
|
+
_eyeL.copy( camera.position ).addScaledVector( _right, - halfSep );
|
|
463
|
+
_eyeR.copy( camera.position ).addScaledVector( _right, halfSep );
|
|
464
|
+
|
|
465
|
+
// Calculate screen center (at planeDistance in front of the camera center)
|
|
466
|
+
_screenCenter.copy( camera.position ).addScaledVector( _forward, - this.planeDistance );
|
|
467
|
+
|
|
468
|
+
// Calculate screen dimensions from camera FOV and aspect ratio
|
|
469
|
+
const DEG2RAD = Math.PI / 180;
|
|
470
|
+
const halfHeight = this.planeDistance * Math.tan( DEG2RAD * camera.fov / 2 );
|
|
471
|
+
const halfWidth = halfHeight * camera.aspect;
|
|
472
|
+
|
|
473
|
+
// Calculate screen corners
|
|
474
|
+
_screenBottomLeft.copy( _screenCenter )
|
|
475
|
+
.addScaledVector( _right, - halfWidth )
|
|
476
|
+
.addScaledVector( _up, - halfHeight );
|
|
477
|
+
|
|
478
|
+
_screenBottomRight.copy( _screenCenter )
|
|
479
|
+
.addScaledVector( _right, halfWidth )
|
|
480
|
+
.addScaledVector( _up, - halfHeight );
|
|
481
|
+
|
|
482
|
+
_screenTopLeft.copy( _screenCenter )
|
|
483
|
+
.addScaledVector( _right, - halfWidth )
|
|
484
|
+
.addScaledVector( _up, halfHeight );
|
|
485
|
+
|
|
486
|
+
// Set up left eye camera
|
|
487
|
+
stereo.cameraL.position.copy( _eyeL );
|
|
488
|
+
stereo.cameraL.near = camera.near;
|
|
489
|
+
stereo.cameraL.far = camera.far;
|
|
490
|
+
frameCorners( stereo.cameraL, _screenBottomLeft, _screenBottomRight, _screenTopLeft, true );
|
|
491
|
+
stereo.cameraL.matrixWorld.compose( stereo.cameraL.position, stereo.cameraL.quaternion, stereo.cameraL.scale );
|
|
492
|
+
stereo.cameraL.matrixWorldInverse.copy( stereo.cameraL.matrixWorld ).invert();
|
|
493
|
+
|
|
494
|
+
// Set up right eye camera
|
|
495
|
+
stereo.cameraR.position.copy( _eyeR );
|
|
496
|
+
stereo.cameraR.near = camera.near;
|
|
497
|
+
stereo.cameraR.far = camera.far;
|
|
498
|
+
frameCorners( stereo.cameraR, _screenBottomLeft, _screenBottomRight, _screenTopLeft, true );
|
|
499
|
+
stereo.cameraR.matrixWorld.compose( stereo.cameraR.position, stereo.cameraR.quaternion, stereo.cameraR.scale );
|
|
500
|
+
stereo.cameraR.matrixWorldInverse.copy( stereo.cameraR.matrixWorld ).invert();
|
|
63
501
|
|
|
64
502
|
}
|
|
65
503
|
|
|
@@ -97,6 +535,8 @@ class AnaglyphPassNode extends StereoCompositePassNode {
|
|
|
97
535
|
|
|
98
536
|
export default AnaglyphPassNode;
|
|
99
537
|
|
|
538
|
+
export { AnaglyphAlgorithm, AnaglyphColorMode };
|
|
539
|
+
|
|
100
540
|
/**
|
|
101
541
|
* TSL function for creating an anaglyph pass node.
|
|
102
542
|
*
|
|
@@ -106,4 +546,4 @@ export default AnaglyphPassNode;
|
|
|
106
546
|
* @param {Camera} camera - The camera to render the scene with.
|
|
107
547
|
* @returns {AnaglyphPassNode}
|
|
108
548
|
*/
|
|
109
|
-
export const anaglyphPass = ( scene, camera ) =>
|
|
549
|
+
export const anaglyphPass = ( scene, camera ) => new AnaglyphPassNode( scene, camera );
|
|
@@ -277,6 +277,6 @@ class AnamorphicNode extends TempNode {
|
|
|
277
277
|
* @param {number} [samples=32] - More samples result in larger flares and a more expensive runtime behavior.
|
|
278
278
|
* @returns {AnamorphicNode}
|
|
279
279
|
*/
|
|
280
|
-
export const anamorphic = ( node, threshold = .9, scale = 3, samples = 32 ) =>
|
|
280
|
+
export const anamorphic = ( node, threshold = .9, scale = 3, samples = 32 ) => new AnamorphicNode( convertToTexture( node ), nodeObject( threshold ), nodeObject( scale ), samples );
|
|
281
281
|
|
|
282
282
|
export default AnamorphicNode;
|