@plastic-software/three 0.181.2 → 0.182.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/README.md +3 -4
- package/build/three.cjs +1192 -522
- package/build/three.core.js +345 -219
- package/build/three.core.min.js +1 -1
- package/build/three.module.js +864 -328
- package/build/three.module.min.js +1 -1
- package/build/three.tsl.js +15 -3
- package/build/three.tsl.min.js +1 -1
- package/build/three.webgpu.js +3660 -1545
- package/build/three.webgpu.min.js +1 -1
- package/build/three.webgpu.nodes.js +3659 -1544
- package/build/three.webgpu.nodes.min.js +1 -1
- package/examples/jsm/controls/MapControls.js +55 -1
- package/examples/jsm/controls/OrbitControls.js +6 -6
- package/examples/jsm/controls/TrackballControls.js +6 -6
- package/examples/jsm/csm/CSM.js +2 -1
- package/examples/jsm/environments/RoomEnvironment.js +2 -0
- package/examples/jsm/geometries/DecalGeometry.js +1 -1
- package/examples/jsm/helpers/LightProbeHelperGPU.js +1 -1
- package/examples/jsm/helpers/TextureHelperGPU.js +1 -1
- package/examples/jsm/inspector/Inspector.js +53 -9
- package/examples/jsm/inspector/RendererInspector.js +12 -2
- package/examples/jsm/inspector/tabs/Console.js +2 -2
- package/examples/jsm/inspector/tabs/Parameters.js +2 -2
- package/examples/jsm/inspector/tabs/Performance.js +2 -2
- package/examples/jsm/inspector/tabs/Viewer.js +4 -4
- package/examples/jsm/inspector/ui/Profiler.js +1836 -31
- package/examples/jsm/inspector/ui/Style.js +948 -13
- package/examples/jsm/inspector/ui/Tab.js +188 -1
- package/examples/jsm/inspector/ui/Values.js +17 -1
- package/examples/jsm/loaders/3DMLoader.js +5 -4
- package/examples/jsm/loaders/DRACOLoader.js +5 -5
- package/examples/jsm/loaders/FBXLoader.js +0 -2
- package/examples/jsm/loaders/HDRLoader.js +0 -1
- package/examples/jsm/loaders/KTX2Loader.js +16 -0
- package/examples/jsm/loaders/LDrawLoader.js +2 -3
- package/examples/jsm/loaders/PCDLoader.js +1 -0
- package/examples/jsm/loaders/SVGLoader.js +1 -1
- package/examples/jsm/loaders/TDSLoader.js +0 -2
- package/examples/jsm/loaders/TGALoader.js +0 -2
- package/examples/jsm/loaders/UltraHDRLoader.js +110 -137
- package/examples/jsm/loaders/VOXLoader.js +660 -117
- package/examples/jsm/loaders/VRMLLoader.js +2 -2
- package/examples/jsm/loaders/usd/USDCParser.js +1 -1
- package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +1 -1
- package/examples/jsm/materials/MeshGouraudMaterial.js +0 -1
- package/examples/jsm/materials/WoodNodeMaterial.js +11 -11
- package/examples/jsm/math/Octree.js +131 -1
- package/examples/jsm/misc/Volume.js +0 -1
- package/examples/jsm/misc/VolumeSlice.js +0 -1
- package/examples/jsm/objects/SkyMesh.js +13 -3
- package/examples/jsm/physics/AmmoPhysics.js +12 -7
- package/examples/jsm/physics/JoltPhysics.js +3 -1
- package/examples/jsm/physics/RapierPhysics.js +3 -1
- package/examples/jsm/postprocessing/OutputPass.js +9 -0
- package/examples/jsm/postprocessing/RenderPass.js +10 -0
- package/examples/jsm/postprocessing/UnrealBloomPass.js +48 -18
- package/examples/jsm/renderers/Projector.js +268 -30
- package/examples/jsm/renderers/SVGRenderer.js +191 -58
- package/examples/jsm/shaders/UnpackDepthRGBAShader.js +2 -4
- package/examples/jsm/transpiler/AST.js +44 -0
- package/examples/jsm/transpiler/GLSLDecoder.js +61 -4
- package/examples/jsm/transpiler/ShaderToyDecoder.js +2 -0
- package/examples/jsm/transpiler/TSLEncoder.js +46 -3
- package/examples/jsm/transpiler/TranspilerUtils.js +3 -3
- package/examples/jsm/transpiler/WGSLEncoder.js +27 -0
- package/examples/jsm/tsl/display/AnaglyphPassNode.js +2 -0
- package/examples/jsm/tsl/display/BloomNode.js +11 -1
- package/examples/jsm/tsl/display/GTAONode.js +3 -2
- package/examples/jsm/tsl/display/PixelationPassNode.js +2 -1
- package/examples/jsm/tsl/display/SSGINode.js +7 -19
- package/examples/jsm/tsl/display/SSRNode.js +1 -1
- package/examples/jsm/tsl/display/SSSNode.js +4 -2
- package/examples/jsm/tsl/display/StereoCompositePassNode.js +8 -1
- package/examples/jsm/tsl/display/TRAANode.js +265 -114
- package/examples/jsm/tsl/display/radialBlur.js +68 -0
- package/examples/jsm/utils/ShadowMapViewer.js +24 -10
- package/examples/jsm/utils/ShadowMapViewerGPU.js +1 -1
- package/examples/jsm/utils/WebGPUTextureUtils.js +1 -1
- package/package.json +14 -12
- package/src/Three.Core.js +1 -0
- package/src/Three.TSL.js +14 -2
- package/src/animation/AnimationUtils.js +1 -12
- package/src/animation/KeyframeTrack.js +1 -1
- package/src/animation/tracks/BooleanKeyframeTrack.js +1 -1
- package/src/animation/tracks/ColorKeyframeTrack.js +1 -1
- package/src/animation/tracks/NumberKeyframeTrack.js +1 -1
- package/src/animation/tracks/QuaternionKeyframeTrack.js +1 -1
- package/src/animation/tracks/StringKeyframeTrack.js +1 -1
- package/src/animation/tracks/VectorKeyframeTrack.js +1 -1
- package/src/constants.js +61 -5
- package/src/core/BufferGeometry.js +14 -2
- package/src/core/Raycaster.js +2 -2
- package/src/extras/PMREMGenerator.js +3 -10
- package/src/extras/TextureUtils.js +5 -1
- package/src/geometries/ExtrudeGeometry.js +2 -2
- package/src/geometries/PolyhedronGeometry.js +1 -1
- package/src/helpers/PointLightHelper.js +1 -1
- package/src/lights/DirectionalLight.js +13 -0
- package/src/lights/HemisphereLight.js +10 -0
- package/src/lights/Light.js +1 -11
- package/src/lights/LightProbe.js +0 -15
- package/src/lights/LightShadow.js +0 -3
- package/src/lights/PointLight.js +15 -0
- package/src/lights/PointLightShadow.js +0 -86
- package/src/lights/SpotLight.js +22 -1
- package/src/loaders/MaterialLoader.js +2 -1
- package/src/loaders/ObjectLoader.js +3 -1
- package/src/loaders/nodes/NodeLoader.js +2 -2
- package/src/materials/Material.js +2 -0
- package/src/materials/ShaderMaterial.js +20 -1
- package/src/materials/nodes/Line2NodeMaterial.js +2 -2
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +3 -2
- package/src/materials/nodes/MeshStandardNodeMaterial.js +5 -4
- package/src/materials/nodes/NodeMaterial.js +59 -3
- package/src/materials/nodes/manager/NodeMaterialObserver.js +1 -1
- package/src/math/Matrix4.js +40 -40
- package/src/math/Sphere.js +1 -1
- package/src/math/Vector3.js +0 -2
- package/src/nodes/TSL.js +4 -1
- package/src/nodes/accessors/BatchNode.js +10 -10
- package/src/nodes/accessors/BufferAttributeNode.js +98 -12
- package/src/nodes/accessors/BufferNode.js +29 -2
- package/src/nodes/accessors/ClippingNode.js +4 -4
- package/src/nodes/accessors/CubeTextureNode.js +20 -1
- package/src/nodes/accessors/InstanceNode.js +69 -29
- package/src/nodes/accessors/MaterialNode.js +9 -1
- package/src/nodes/accessors/MaterialReferenceNode.js +1 -2
- package/src/nodes/accessors/ModelNode.js +1 -1
- package/src/nodes/accessors/Normal.js +2 -2
- package/src/nodes/accessors/ReferenceBaseNode.js +4 -4
- package/src/nodes/accessors/ReferenceNode.js +4 -4
- package/src/nodes/accessors/RendererReferenceNode.js +1 -2
- package/src/nodes/accessors/SkinningNode.js +15 -2
- package/src/nodes/accessors/StorageBufferNode.js +4 -2
- package/src/nodes/accessors/Tangent.js +1 -11
- package/src/nodes/accessors/Texture3DNode.js +26 -1
- package/src/nodes/accessors/UniformArrayNode.js +2 -2
- package/src/nodes/accessors/UserDataNode.js +1 -2
- package/src/nodes/accessors/VertexColorNode.js +1 -2
- package/src/nodes/code/FunctionNode.js +1 -2
- package/src/nodes/core/ArrayNode.js +20 -1
- package/src/nodes/core/AssignNode.js +2 -2
- package/src/nodes/core/AttributeNode.js +2 -2
- package/src/nodes/core/ContextNode.js +103 -4
- package/src/nodes/core/NodeBuilder.js +56 -14
- package/src/nodes/core/NodeFrame.js +12 -4
- package/src/nodes/core/NodeUtils.js +5 -5
- package/src/nodes/core/ParameterNode.js +1 -2
- package/src/nodes/core/PropertyNode.js +19 -3
- package/src/nodes/core/StackNode.js +56 -8
- package/src/nodes/core/StructNode.js +1 -2
- package/src/nodes/core/StructTypeNode.js +11 -17
- package/src/nodes/core/UniformNode.js +19 -4
- package/src/nodes/core/VarNode.js +46 -21
- package/src/nodes/display/NormalMapNode.js +37 -2
- package/src/nodes/display/PassNode.js +77 -7
- package/src/nodes/display/ScreenNode.js +1 -0
- package/src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js +3 -3
- package/src/nodes/functions/BSDF/DFGLUT.js +56 -0
- package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
- package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +1 -1
- package/src/nodes/functions/PhysicalLightingModel.js +102 -43
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +1 -2
- package/src/nodes/gpgpu/SubgroupFunctionNode.js +1 -1
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +2 -3
- package/src/nodes/lighting/AnalyticLightNode.js +53 -0
- package/src/nodes/lighting/LightsNode.js +2 -2
- package/src/nodes/lighting/PointShadowNode.js +141 -140
- package/src/nodes/lighting/ShadowFilterNode.js +53 -37
- package/src/nodes/lighting/ShadowNode.js +53 -19
- package/src/nodes/math/BitcountNode.js +433 -0
- package/src/nodes/math/PackFloatNode.js +98 -0
- package/src/nodes/math/UnpackFloatNode.js +96 -0
- package/src/nodes/pmrem/PMREMNode.js +1 -1
- package/src/nodes/tsl/TSLCore.js +4 -4
- package/src/nodes/utils/ArrayElementNode.js +13 -0
- package/src/nodes/utils/EventNode.js +1 -2
- package/src/nodes/utils/Packing.js +13 -1
- package/src/nodes/utils/PostProcessingUtils.js +33 -1
- package/src/nodes/utils/ReflectorNode.js +1 -1
- package/src/nodes/utils/SampleNode.js +1 -1
- package/src/nodes/utils/UVUtils.js +26 -0
- package/src/objects/BatchedMesh.js +5 -2
- package/src/objects/Line.js +1 -1
- package/src/objects/Mesh.js +1 -1
- package/src/objects/Points.js +1 -1
- package/src/objects/Skeleton.js +9 -0
- package/src/renderers/WebGLRenderer.js +145 -33
- package/src/renderers/common/Backend.js +8 -0
- package/src/renderers/common/Background.js +19 -9
- package/src/renderers/common/Binding.js +11 -0
- package/src/renderers/common/Bindings.js +7 -7
- package/src/renderers/common/Buffer.js +40 -0
- package/src/renderers/common/ChainMap.js +30 -6
- package/src/renderers/common/Geometries.js +12 -0
- package/src/renderers/common/RenderContexts.js +8 -1
- package/src/renderers/common/RenderObject.js +14 -1
- package/src/renderers/common/Renderer.js +53 -35
- package/src/renderers/common/Textures.js +1 -1
- package/src/renderers/common/UniformsGroup.js +1 -0
- package/src/renderers/common/XRManager.js +1 -0
- package/src/renderers/common/extras/PMREMGenerator.js +2 -8
- package/src/renderers/common/nodes/NodeUniformBuffer.js +52 -0
- package/src/renderers/shaders/DFGLUTData.js +19 -34
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +5 -2
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +8 -4
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +90 -51
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +194 -186
- package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk.js +3 -3
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +3 -0
- package/src/renderers/shaders/ShaderLib/{distanceRGBA.glsl.js → distance.glsl.js} +1 -2
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +0 -1
- package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +1 -2
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +0 -1
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -9
- package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +0 -1
- package/src/renderers/shaders/ShaderLib/shadow.glsl.js +0 -1
- package/src/renderers/shaders/ShaderLib/vsm.glsl.js +4 -6
- package/src/renderers/shaders/ShaderLib.js +3 -3
- package/src/renderers/webgl/WebGLCapabilities.js +3 -4
- package/src/renderers/webgl/WebGLLights.js +18 -1
- package/src/renderers/webgl/WebGLOutput.js +267 -0
- package/src/renderers/webgl/WebGLProgram.js +43 -107
- package/src/renderers/webgl/WebGLPrograms.js +35 -45
- package/src/renderers/webgl/WebGLShadowMap.js +188 -25
- package/src/renderers/webgl/WebGLState.js +20 -20
- package/src/renderers/webgl/WebGLTextures.js +89 -28
- package/src/renderers/webgl/WebGLUniforms.js +40 -3
- package/src/renderers/webgl/WebGLUtils.js +6 -2
- package/src/renderers/webgl-fallback/WebGLBackend.js +79 -13
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +59 -7
- package/src/renderers/webgl-fallback/utils/WebGLState.js +18 -3
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +5 -3
- package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +9 -9
- package/src/renderers/webgl-fallback/utils/WebGLUtils.js +6 -2
- package/src/renderers/webgpu/WebGPUBackend.js +61 -4
- package/src/renderers/webgpu/WebGPURenderer.js +1 -1
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +65 -23
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +4 -17
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +354 -186
- package/src/renderers/webgpu/utils/WebGPUConstants.js +2 -0
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +20 -7
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +40 -17
- package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +7 -7
- package/src/renderers/webgpu/utils/WebGPUUtils.js +7 -5
- package/src/textures/CubeDepthTexture.js +76 -0
- package/src/textures/Source.js +1 -1
- package/src/textures/Texture.js +1 -1
- package/src/utils.js +13 -1
- package/src/nodes/functions/BSDF/DFGApprox.js +0 -71
|
@@ -11,8 +11,6 @@ uniform sampler2D shadow_pass;
|
|
|
11
11
|
uniform vec2 resolution;
|
|
12
12
|
uniform float radius;
|
|
13
13
|
|
|
14
|
-
#include <packing>
|
|
15
|
-
|
|
16
14
|
void main() {
|
|
17
15
|
|
|
18
16
|
const float samples = float( VSM_SAMPLES );
|
|
@@ -28,13 +26,13 @@ void main() {
|
|
|
28
26
|
|
|
29
27
|
#ifdef HORIZONTAL_PASS
|
|
30
28
|
|
|
31
|
-
vec2 distribution =
|
|
29
|
+
vec2 distribution = texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ).rg;
|
|
32
30
|
mean += distribution.x;
|
|
33
31
|
squared_mean += distribution.y * distribution.y + distribution.x * distribution.x;
|
|
34
32
|
|
|
35
33
|
#else
|
|
36
34
|
|
|
37
|
-
float depth =
|
|
35
|
+
float depth = texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ).r;
|
|
38
36
|
mean += depth;
|
|
39
37
|
squared_mean += depth * depth;
|
|
40
38
|
|
|
@@ -45,9 +43,9 @@ void main() {
|
|
|
45
43
|
mean = mean / samples;
|
|
46
44
|
squared_mean = squared_mean / samples;
|
|
47
45
|
|
|
48
|
-
float std_dev = sqrt( squared_mean - mean * mean );
|
|
46
|
+
float std_dev = sqrt( max( 0.0, squared_mean - mean * mean ) );
|
|
49
47
|
|
|
50
|
-
gl_FragColor =
|
|
48
|
+
gl_FragColor = vec4( mean, std_dev, 0.0, 1.0 );
|
|
51
49
|
|
|
52
50
|
}
|
|
53
51
|
`;
|
|
@@ -265,7 +265,7 @@ const ShaderLib = {
|
|
|
265
265
|
|
|
266
266
|
},
|
|
267
267
|
|
|
268
|
-
|
|
268
|
+
distance: {
|
|
269
269
|
|
|
270
270
|
uniforms: /*@__PURE__*/ mergeUniforms( [
|
|
271
271
|
UniformsLib.common,
|
|
@@ -277,8 +277,8 @@ const ShaderLib = {
|
|
|
277
277
|
}
|
|
278
278
|
] ),
|
|
279
279
|
|
|
280
|
-
vertexShader: ShaderChunk.
|
|
281
|
-
fragmentShader: ShaderChunk.
|
|
280
|
+
vertexShader: ShaderChunk.distance_vert,
|
|
281
|
+
fragmentShader: ShaderChunk.distance_frag
|
|
282
282
|
|
|
283
283
|
},
|
|
284
284
|
|
|
@@ -105,9 +105,8 @@ function WebGLCapabilities( gl, extensions, parameters, utils ) {
|
|
|
105
105
|
const maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
|
|
106
106
|
const maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
|
|
107
107
|
|
|
108
|
-
const vertexTextures = maxVertexTextures > 0;
|
|
109
|
-
|
|
110
108
|
const maxSamples = gl.getParameter( gl.MAX_SAMPLES );
|
|
109
|
+
const samples = gl.getParameter( gl.SAMPLES );
|
|
111
110
|
|
|
112
111
|
return {
|
|
113
112
|
|
|
@@ -133,9 +132,9 @@ function WebGLCapabilities( gl, extensions, parameters, utils ) {
|
|
|
133
132
|
maxVaryings: maxVaryings,
|
|
134
133
|
maxFragmentUniforms: maxFragmentUniforms,
|
|
135
134
|
|
|
136
|
-
|
|
135
|
+
maxSamples: maxSamples,
|
|
137
136
|
|
|
138
|
-
|
|
137
|
+
samples: samples
|
|
139
138
|
|
|
140
139
|
};
|
|
141
140
|
|
|
@@ -3,6 +3,7 @@ import { Matrix4 } from '../../math/Matrix4.js';
|
|
|
3
3
|
import { Vector2 } from '../../math/Vector2.js';
|
|
4
4
|
import { Vector3 } from '../../math/Vector3.js';
|
|
5
5
|
import { UniformsLib } from '../shaders/UniformsLib.js';
|
|
6
|
+
import { RGFormat } from '../../constants.js';
|
|
6
7
|
|
|
7
8
|
function UniformsCache() {
|
|
8
9
|
|
|
@@ -239,7 +240,23 @@ function WebGLLights( extensions ) {
|
|
|
239
240
|
const intensity = light.intensity;
|
|
240
241
|
const distance = light.distance;
|
|
241
242
|
|
|
242
|
-
|
|
243
|
+
let shadowMap = null;
|
|
244
|
+
|
|
245
|
+
if ( light.shadow && light.shadow.map ) {
|
|
246
|
+
|
|
247
|
+
if ( light.shadow.map.texture.format === RGFormat ) {
|
|
248
|
+
|
|
249
|
+
// VSM uses color texture with blurred mean/std_dev
|
|
250
|
+
shadowMap = light.shadow.map.texture;
|
|
251
|
+
|
|
252
|
+
} else {
|
|
253
|
+
|
|
254
|
+
// Other types use depth texture
|
|
255
|
+
shadowMap = light.shadow.map.depthTexture || light.shadow.map.texture;
|
|
256
|
+
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
}
|
|
243
260
|
|
|
244
261
|
if ( light.isAmbientLight ) {
|
|
245
262
|
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NoToneMapping,
|
|
3
|
+
LinearToneMapping,
|
|
4
|
+
ReinhardToneMapping,
|
|
5
|
+
CineonToneMapping,
|
|
6
|
+
ACESFilmicToneMapping,
|
|
7
|
+
AgXToneMapping,
|
|
8
|
+
NeutralToneMapping,
|
|
9
|
+
CustomToneMapping,
|
|
10
|
+
SRGBTransfer,
|
|
11
|
+
HalfFloatType
|
|
12
|
+
} from '../../constants.js';
|
|
13
|
+
import { BufferGeometry } from '../../core/BufferGeometry.js';
|
|
14
|
+
import { Float32BufferAttribute } from '../../core/BufferAttribute.js';
|
|
15
|
+
import { RawShaderMaterial } from '../../materials/RawShaderMaterial.js';
|
|
16
|
+
import { Mesh } from '../../objects/Mesh.js';
|
|
17
|
+
import { OrthographicCamera } from '../../cameras/OrthographicCamera.js';
|
|
18
|
+
import { WebGLRenderTarget } from '../WebGLRenderTarget.js';
|
|
19
|
+
import { ColorManagement } from '../../math/ColorManagement.js';
|
|
20
|
+
|
|
21
|
+
const toneMappingMap = {
|
|
22
|
+
[ LinearToneMapping ]: 'LINEAR_TONE_MAPPING',
|
|
23
|
+
[ ReinhardToneMapping ]: 'REINHARD_TONE_MAPPING',
|
|
24
|
+
[ CineonToneMapping ]: 'CINEON_TONE_MAPPING',
|
|
25
|
+
[ ACESFilmicToneMapping ]: 'ACES_FILMIC_TONE_MAPPING',
|
|
26
|
+
[ AgXToneMapping ]: 'AGX_TONE_MAPPING',
|
|
27
|
+
[ NeutralToneMapping ]: 'NEUTRAL_TONE_MAPPING',
|
|
28
|
+
[ CustomToneMapping ]: 'CUSTOM_TONE_MAPPING'
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
function WebGLOutput( type, width, height, depth, stencil ) {
|
|
32
|
+
|
|
33
|
+
// render targets for scene and post-processing
|
|
34
|
+
const targetA = new WebGLRenderTarget( width, height, {
|
|
35
|
+
type: type,
|
|
36
|
+
depthBuffer: depth,
|
|
37
|
+
stencilBuffer: stencil
|
|
38
|
+
} );
|
|
39
|
+
|
|
40
|
+
const targetB = new WebGLRenderTarget( width, height, {
|
|
41
|
+
type: HalfFloatType,
|
|
42
|
+
depthBuffer: false,
|
|
43
|
+
stencilBuffer: false
|
|
44
|
+
} );
|
|
45
|
+
|
|
46
|
+
// create fullscreen triangle geometry
|
|
47
|
+
const geometry = new BufferGeometry();
|
|
48
|
+
geometry.setAttribute( 'position', new Float32BufferAttribute( [ - 1, 3, 0, - 1, - 1, 0, 3, - 1, 0 ], 3 ) );
|
|
49
|
+
geometry.setAttribute( 'uv', new Float32BufferAttribute( [ 0, 2, 0, 0, 2, 0 ], 2 ) );
|
|
50
|
+
|
|
51
|
+
// create output material with tone mapping support
|
|
52
|
+
const material = new RawShaderMaterial( {
|
|
53
|
+
uniforms: {
|
|
54
|
+
tDiffuse: { value: null }
|
|
55
|
+
},
|
|
56
|
+
vertexShader: /* glsl */`
|
|
57
|
+
precision highp float;
|
|
58
|
+
|
|
59
|
+
uniform mat4 modelViewMatrix;
|
|
60
|
+
uniform mat4 projectionMatrix;
|
|
61
|
+
|
|
62
|
+
attribute vec3 position;
|
|
63
|
+
attribute vec2 uv;
|
|
64
|
+
|
|
65
|
+
varying vec2 vUv;
|
|
66
|
+
|
|
67
|
+
void main() {
|
|
68
|
+
vUv = uv;
|
|
69
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
70
|
+
}`,
|
|
71
|
+
fragmentShader: /* glsl */`
|
|
72
|
+
precision highp float;
|
|
73
|
+
|
|
74
|
+
uniform sampler2D tDiffuse;
|
|
75
|
+
|
|
76
|
+
varying vec2 vUv;
|
|
77
|
+
|
|
78
|
+
#include <tonemapping_pars_fragment>
|
|
79
|
+
#include <colorspace_pars_fragment>
|
|
80
|
+
|
|
81
|
+
void main() {
|
|
82
|
+
gl_FragColor = texture2D( tDiffuse, vUv );
|
|
83
|
+
|
|
84
|
+
#ifdef LINEAR_TONE_MAPPING
|
|
85
|
+
gl_FragColor.rgb = LinearToneMapping( gl_FragColor.rgb );
|
|
86
|
+
#elif defined( REINHARD_TONE_MAPPING )
|
|
87
|
+
gl_FragColor.rgb = ReinhardToneMapping( gl_FragColor.rgb );
|
|
88
|
+
#elif defined( CINEON_TONE_MAPPING )
|
|
89
|
+
gl_FragColor.rgb = CineonToneMapping( gl_FragColor.rgb );
|
|
90
|
+
#elif defined( ACES_FILMIC_TONE_MAPPING )
|
|
91
|
+
gl_FragColor.rgb = ACESFilmicToneMapping( gl_FragColor.rgb );
|
|
92
|
+
#elif defined( AGX_TONE_MAPPING )
|
|
93
|
+
gl_FragColor.rgb = AgXToneMapping( gl_FragColor.rgb );
|
|
94
|
+
#elif defined( NEUTRAL_TONE_MAPPING )
|
|
95
|
+
gl_FragColor.rgb = NeutralToneMapping( gl_FragColor.rgb );
|
|
96
|
+
#elif defined( CUSTOM_TONE_MAPPING )
|
|
97
|
+
gl_FragColor.rgb = CustomToneMapping( gl_FragColor.rgb );
|
|
98
|
+
#endif
|
|
99
|
+
|
|
100
|
+
#ifdef SRGB_TRANSFER
|
|
101
|
+
gl_FragColor = sRGBTransferOETF( gl_FragColor );
|
|
102
|
+
#endif
|
|
103
|
+
}`,
|
|
104
|
+
depthTest: false,
|
|
105
|
+
depthWrite: false
|
|
106
|
+
} );
|
|
107
|
+
|
|
108
|
+
const mesh = new Mesh( geometry, material );
|
|
109
|
+
const camera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
|
|
110
|
+
|
|
111
|
+
let _outputColorSpace = null;
|
|
112
|
+
let _outputToneMapping = null;
|
|
113
|
+
let _isCompositing = false;
|
|
114
|
+
let _savedToneMapping;
|
|
115
|
+
let _savedRenderTarget = null;
|
|
116
|
+
let _effects = [];
|
|
117
|
+
let _hasRenderPass = false;
|
|
118
|
+
|
|
119
|
+
this.setSize = function ( width, height ) {
|
|
120
|
+
|
|
121
|
+
targetA.setSize( width, height );
|
|
122
|
+
targetB.setSize( width, height );
|
|
123
|
+
|
|
124
|
+
for ( let i = 0; i < _effects.length; i ++ ) {
|
|
125
|
+
|
|
126
|
+
const effect = _effects[ i ];
|
|
127
|
+
if ( effect.setSize ) effect.setSize( width, height );
|
|
128
|
+
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
this.setEffects = function ( effects ) {
|
|
134
|
+
|
|
135
|
+
_effects = effects;
|
|
136
|
+
_hasRenderPass = _effects.length > 0 && _effects[ 0 ].isRenderPass === true;
|
|
137
|
+
|
|
138
|
+
const width = targetA.width;
|
|
139
|
+
const height = targetA.height;
|
|
140
|
+
|
|
141
|
+
for ( let i = 0; i < _effects.length; i ++ ) {
|
|
142
|
+
|
|
143
|
+
const effect = _effects[ i ];
|
|
144
|
+
if ( effect.setSize ) effect.setSize( width, height );
|
|
145
|
+
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
this.begin = function ( renderer, renderTarget ) {
|
|
151
|
+
|
|
152
|
+
// Don't begin during compositing phase (post-processing effects call render())
|
|
153
|
+
if ( _isCompositing ) return false;
|
|
154
|
+
|
|
155
|
+
if ( renderer.toneMapping === NoToneMapping && _effects.length === 0 ) return false;
|
|
156
|
+
|
|
157
|
+
_savedRenderTarget = renderTarget;
|
|
158
|
+
|
|
159
|
+
// resize internal buffers to match render target (e.g. XR resolution)
|
|
160
|
+
if ( renderTarget !== null ) {
|
|
161
|
+
|
|
162
|
+
const width = renderTarget.width;
|
|
163
|
+
const height = renderTarget.height;
|
|
164
|
+
|
|
165
|
+
if ( targetA.width !== width || targetA.height !== height ) {
|
|
166
|
+
|
|
167
|
+
this.setSize( width, height );
|
|
168
|
+
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// if first effect is a RenderPass, it will set its own render target
|
|
174
|
+
if ( _hasRenderPass === false ) {
|
|
175
|
+
|
|
176
|
+
renderer.setRenderTarget( targetA );
|
|
177
|
+
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// disable tone mapping during render - it will be applied in end()
|
|
181
|
+
_savedToneMapping = renderer.toneMapping;
|
|
182
|
+
renderer.toneMapping = NoToneMapping;
|
|
183
|
+
|
|
184
|
+
return true;
|
|
185
|
+
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
this.hasRenderPass = function () {
|
|
189
|
+
|
|
190
|
+
return _hasRenderPass;
|
|
191
|
+
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
this.end = function ( renderer, deltaTime ) {
|
|
195
|
+
|
|
196
|
+
// restore tone mapping
|
|
197
|
+
renderer.toneMapping = _savedToneMapping;
|
|
198
|
+
|
|
199
|
+
_isCompositing = true;
|
|
200
|
+
|
|
201
|
+
// run post-processing effects
|
|
202
|
+
let readBuffer = targetA;
|
|
203
|
+
let writeBuffer = targetB;
|
|
204
|
+
|
|
205
|
+
for ( let i = 0; i < _effects.length; i ++ ) {
|
|
206
|
+
|
|
207
|
+
const effect = _effects[ i ];
|
|
208
|
+
|
|
209
|
+
if ( effect.enabled === false ) continue;
|
|
210
|
+
|
|
211
|
+
effect.render( renderer, writeBuffer, readBuffer, deltaTime );
|
|
212
|
+
|
|
213
|
+
if ( effect.needsSwap !== false ) {
|
|
214
|
+
|
|
215
|
+
const temp = readBuffer;
|
|
216
|
+
readBuffer = writeBuffer;
|
|
217
|
+
writeBuffer = temp;
|
|
218
|
+
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// update output material defines if settings changed
|
|
224
|
+
if ( _outputColorSpace !== renderer.outputColorSpace || _outputToneMapping !== renderer.toneMapping ) {
|
|
225
|
+
|
|
226
|
+
_outputColorSpace = renderer.outputColorSpace;
|
|
227
|
+
_outputToneMapping = renderer.toneMapping;
|
|
228
|
+
|
|
229
|
+
material.defines = {};
|
|
230
|
+
|
|
231
|
+
if ( ColorManagement.getTransfer( _outputColorSpace ) === SRGBTransfer ) material.defines.SRGB_TRANSFER = '';
|
|
232
|
+
|
|
233
|
+
const toneMapping = toneMappingMap[ _outputToneMapping ];
|
|
234
|
+
if ( toneMapping ) material.defines[ toneMapping ] = '';
|
|
235
|
+
|
|
236
|
+
material.needsUpdate = true;
|
|
237
|
+
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// final output to canvas (or XR render target)
|
|
241
|
+
material.uniforms.tDiffuse.value = readBuffer.texture;
|
|
242
|
+
renderer.setRenderTarget( _savedRenderTarget );
|
|
243
|
+
renderer.render( mesh, camera );
|
|
244
|
+
|
|
245
|
+
_savedRenderTarget = null;
|
|
246
|
+
_isCompositing = false;
|
|
247
|
+
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
this.isCompositing = function () {
|
|
251
|
+
|
|
252
|
+
return _isCompositing;
|
|
253
|
+
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
this.dispose = function () {
|
|
257
|
+
|
|
258
|
+
targetA.dispose();
|
|
259
|
+
targetB.dispose();
|
|
260
|
+
geometry.dispose();
|
|
261
|
+
material.dispose();
|
|
262
|
+
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export { WebGLOutput };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { WebGLUniforms } from './WebGLUniforms.js';
|
|
2
2
|
import { WebGLShader } from './WebGLShader.js';
|
|
3
3
|
import { ShaderChunk } from '../shaders/ShaderChunk.js';
|
|
4
|
-
import { NoToneMapping, AddOperation, MixOperation, MultiplyOperation, CubeRefractionMapping, CubeUVReflectionMapping, CubeReflectionMapping,
|
|
4
|
+
import { NoToneMapping, AddOperation, MixOperation, MultiplyOperation, CubeRefractionMapping, CubeUVReflectionMapping, CubeReflectionMapping, PCFShadowMap, VSMShadowMap, AgXToneMapping, ACESFilmicToneMapping, NeutralToneMapping, CineonToneMapping, CustomToneMapping, ReinhardToneMapping, LinearToneMapping, GLSL3, LinearTransfer, SRGBTransfer, TriPlanarMapping, UVMapping, CylindricalMapping } from '../../constants.js';
|
|
5
5
|
import { ColorManagement } from '../../math/ColorManagement.js';
|
|
6
6
|
import { Vector3 } from '../../math/Vector3.js';
|
|
7
7
|
import { Matrix3 } from '../../math/Matrix3.js';
|
|
@@ -97,43 +97,24 @@ function getTexelEncodingFunction( functionName, colorSpace ) {
|
|
|
97
97
|
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
case ReinhardToneMapping:
|
|
111
|
-
toneMappingName = 'Reinhard';
|
|
112
|
-
break;
|
|
113
|
-
|
|
114
|
-
case CineonToneMapping:
|
|
115
|
-
toneMappingName = 'Cineon';
|
|
116
|
-
break;
|
|
100
|
+
const toneMappingFunctions = {
|
|
101
|
+
[ LinearToneMapping ]: 'Linear',
|
|
102
|
+
[ ReinhardToneMapping ]: 'Reinhard',
|
|
103
|
+
[ CineonToneMapping ]: 'Cineon',
|
|
104
|
+
[ ACESFilmicToneMapping ]: 'ACESFilmic',
|
|
105
|
+
[ AgXToneMapping ]: 'AgX',
|
|
106
|
+
[ NeutralToneMapping ]: 'Neutral',
|
|
107
|
+
[ CustomToneMapping ]: 'Custom'
|
|
108
|
+
};
|
|
117
109
|
|
|
118
|
-
|
|
119
|
-
toneMappingName = 'ACESFilmic';
|
|
120
|
-
break;
|
|
121
|
-
|
|
122
|
-
case AgXToneMapping:
|
|
123
|
-
toneMappingName = 'AgX';
|
|
124
|
-
break;
|
|
110
|
+
function getToneMappingFunction( functionName, toneMapping ) {
|
|
125
111
|
|
|
126
|
-
|
|
127
|
-
toneMappingName = 'Neutral';
|
|
128
|
-
break;
|
|
112
|
+
const toneMappingName = toneMappingFunctions[ toneMapping ];
|
|
129
113
|
|
|
130
|
-
|
|
131
|
-
toneMappingName = 'Custom';
|
|
132
|
-
break;
|
|
114
|
+
if ( toneMappingName === undefined ) {
|
|
133
115
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
toneMappingName = 'Linear';
|
|
116
|
+
warn( 'WebGLProgram: Unsupported toneMapping:', toneMapping );
|
|
117
|
+
return 'vec3 ' + functionName + '( vec3 color ) { return LinearToneMapping( color ); }';
|
|
137
118
|
|
|
138
119
|
}
|
|
139
120
|
|
|
@@ -361,99 +342,54 @@ function generatePrecision( parameters ) {
|
|
|
361
342
|
|
|
362
343
|
}
|
|
363
344
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
if ( parameters.shadowMapType === PCFShadowMap ) {
|
|
345
|
+
const shadowMapTypeDefines = {
|
|
346
|
+
[ PCFShadowMap ]: 'SHADOWMAP_TYPE_PCF',
|
|
347
|
+
[ VSMShadowMap ]: 'SHADOWMAP_TYPE_VSM'
|
|
348
|
+
};
|
|
369
349
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
} else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
|
|
373
|
-
|
|
374
|
-
shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
|
|
375
|
-
|
|
376
|
-
} else if ( parameters.shadowMapType === VSMShadowMap ) {
|
|
377
|
-
|
|
378
|
-
shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
|
|
379
|
-
|
|
380
|
-
}
|
|
350
|
+
function generateShadowMapTypeDefine( parameters ) {
|
|
381
351
|
|
|
382
|
-
return
|
|
352
|
+
return shadowMapTypeDefines[ parameters.shadowMapType ] || 'SHADOWMAP_TYPE_BASIC';
|
|
383
353
|
|
|
384
354
|
}
|
|
385
355
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
switch ( parameters.envMapMode ) {
|
|
393
|
-
|
|
394
|
-
case CubeReflectionMapping:
|
|
395
|
-
case CubeRefractionMapping:
|
|
396
|
-
envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
|
|
397
|
-
break;
|
|
356
|
+
const envMapTypeDefines = {
|
|
357
|
+
[ CubeReflectionMapping ]: 'ENVMAP_TYPE_CUBE',
|
|
358
|
+
[ CubeRefractionMapping ]: 'ENVMAP_TYPE_CUBE',
|
|
359
|
+
[ CubeUVReflectionMapping ]: 'ENVMAP_TYPE_CUBE_UV'
|
|
360
|
+
};
|
|
398
361
|
|
|
399
|
-
|
|
400
|
-
envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
|
|
401
|
-
break;
|
|
402
|
-
|
|
403
|
-
}
|
|
362
|
+
function generateEnvMapTypeDefine( parameters ) {
|
|
404
363
|
|
|
405
|
-
|
|
364
|
+
if ( parameters.envMap === false ) return 'ENVMAP_TYPE_CUBE';
|
|
406
365
|
|
|
407
|
-
return
|
|
366
|
+
return envMapTypeDefines[ parameters.envMapMode ] || 'ENVMAP_TYPE_CUBE';
|
|
408
367
|
|
|
409
368
|
}
|
|
410
369
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
370
|
+
const envMapModeDefines = {
|
|
371
|
+
[ CubeRefractionMapping ]: 'ENVMAP_MODE_REFRACTION'
|
|
372
|
+
};
|
|
414
373
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
switch ( parameters.envMapMode ) {
|
|
418
|
-
|
|
419
|
-
case CubeRefractionMapping:
|
|
420
|
-
|
|
421
|
-
envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
|
|
422
|
-
break;
|
|
374
|
+
function generateEnvMapModeDefine( parameters ) {
|
|
423
375
|
|
|
424
|
-
|
|
376
|
+
if ( parameters.envMap === false ) return 'ENVMAP_MODE_REFLECTION';
|
|
425
377
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
return envMapModeDefine;
|
|
378
|
+
return envMapModeDefines[ parameters.envMapMode ] || 'ENVMAP_MODE_REFLECTION';
|
|
429
379
|
|
|
430
380
|
}
|
|
431
381
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
switch ( parameters.combine ) {
|
|
439
|
-
|
|
440
|
-
case MultiplyOperation:
|
|
441
|
-
envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
|
|
442
|
-
break;
|
|
382
|
+
const envMapBlendingDefines = {
|
|
383
|
+
[ MultiplyOperation ]: 'ENVMAP_BLENDING_MULTIPLY',
|
|
384
|
+
[ MixOperation ]: 'ENVMAP_BLENDING_MIX',
|
|
385
|
+
[ AddOperation ]: 'ENVMAP_BLENDING_ADD'
|
|
386
|
+
};
|
|
443
387
|
|
|
444
|
-
|
|
445
|
-
envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
|
|
446
|
-
break;
|
|
447
|
-
|
|
448
|
-
case AddOperation:
|
|
449
|
-
envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
|
|
450
|
-
break;
|
|
451
|
-
|
|
452
|
-
}
|
|
388
|
+
function generateEnvMapBlendingDefine( parameters ) {
|
|
453
389
|
|
|
454
|
-
|
|
390
|
+
if ( parameters.envMap === false ) return 'ENVMAP_BLENDING_NONE';
|
|
455
391
|
|
|
456
|
-
return
|
|
392
|
+
return envMapBlendingDefines[ parameters.combine ] || 'ENVMAP_BLENDING_NONE';
|
|
457
393
|
|
|
458
394
|
}
|
|
459
395
|
|