super-three 0.135.0 → 0.136.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/build/three.js +527 -332
- package/build/three.min.js +1 -1
- package/build/three.module.js +752 -370
- package/examples/fonts/tabler-icons/fonts/tabler-icons.svg +3966 -0
- package/examples/js/animation/CCDIKSolver.js +0 -1
- package/examples/js/animation/MMDPhysics.js +1 -3
- package/examples/js/controls/ArcballControls.js +38 -52
- package/examples/js/controls/TransformControls.js +24 -1
- package/examples/js/curves/CurveExtras.js +0 -2
- package/examples/js/effects/AsciiEffect.js +2 -9
- package/examples/js/exporters/GLTFExporter.js +1 -1
- package/examples/js/geometries/TeapotGeometry.js +0 -1
- package/examples/js/interactive/SelectionBox.js +2 -0
- package/examples/js/interactive/SelectionHelper.js +22 -7
- package/examples/js/lights/RectAreaLightUniformsLib.js +4 -0
- package/examples/js/loaders/AMFLoader.js +0 -2
- package/examples/js/loaders/ColladaLoader.js +1 -2
- package/examples/js/loaders/EXRLoader.js +185 -262
- package/examples/js/loaders/FBXLoader.js +3 -4
- package/examples/js/loaders/GLTFLoader.js +2 -2
- package/examples/js/loaders/HDRCubeTextureLoader.js +0 -8
- package/examples/js/loaders/KTX2Loader.js +11 -2
- package/examples/js/loaders/KTXLoader.js +1 -1
- package/examples/js/loaders/LDrawLoader.js +26 -30
- package/examples/js/loaders/LUT3dlLoader.js +2 -0
- package/examples/js/loaders/LUTCubeLoader.js +2 -0
- package/examples/js/loaders/MMDLoader.js +0 -1
- package/examples/js/loaders/NRRDLoader.js +9 -2
- package/examples/js/loaders/OBJLoader.js +0 -2
- package/examples/js/loaders/PLYLoader.js +1 -1
- package/examples/js/loaders/RGBELoader.js +0 -15
- package/examples/js/loaders/RGBMLoader.js +55 -5
- package/examples/js/loaders/SVGLoader.js +2 -2
- package/examples/js/loaders/VOXLoader.js +1 -0
- package/examples/js/loaders/VRMLLoader.js +2 -1
- package/examples/js/math/ImprovedNoise.js +1 -1
- package/examples/js/misc/GPUComputationRenderer.js +3 -1
- package/examples/js/objects/Lensflare.js +2 -10
- package/examples/js/objects/Reflector.js +7 -0
- package/examples/js/objects/Refractor.js +7 -0
- package/examples/js/objects/Sky.js +1 -1
- package/examples/js/objects/Water.js +2 -2
- package/examples/js/objects/Water2.js +4 -7
- package/examples/js/postprocessing/GlitchPass.js +3 -1
- package/examples/js/postprocessing/SSAOPass.js +1 -0
- package/examples/js/shaders/ConvolutionShader.js +0 -1
- package/examples/js/shaders/FXAAShader.js +1 -1
- package/examples/js/shaders/FilmShader.js +1 -1
- package/examples/js/shaders/GammaCorrectionShader.js +1 -1
- package/examples/js/shaders/HorizontalBlurShader.js +1 -2
- package/examples/js/shaders/SSRShader.js +1 -1
- package/examples/js/shaders/SSRrShader.js +1 -1
- package/examples/js/shaders/VerticalBlurShader.js +1 -2
- package/examples/js/utils/GeometryUtils.js +1 -1
- package/examples/js/utils/RoughnessMipmapper.js +18 -29
- package/examples/jsm/animation/CCDIKSolver.js +0 -1
- package/examples/jsm/animation/MMDPhysics.js +0 -2
- package/examples/jsm/controls/ArcballControls.js +27 -56
- package/examples/jsm/controls/TransformControls.js +24 -1
- package/examples/jsm/curves/CurveExtras.js +0 -2
- package/examples/jsm/effects/AsciiEffect.js +2 -9
- package/examples/jsm/exporters/GLTFExporter.js +1 -1
- package/examples/jsm/geometries/TeapotGeometry.js +0 -1
- package/examples/jsm/interactive/SelectionBox.js +1 -0
- package/examples/jsm/interactive/SelectionHelper.js +19 -7
- package/examples/jsm/libs/flow.module.js +256 -136
- package/examples/jsm/lights/RectAreaLightUniformsLib.js +7 -0
- package/examples/jsm/loaders/AMFLoader.js +0 -2
- package/examples/jsm/loaders/ColladaLoader.js +1 -2
- package/examples/jsm/loaders/EXRLoader.js +184 -293
- package/examples/jsm/loaders/FBXLoader.js +3 -4
- package/examples/jsm/loaders/GLTFLoader.js +2 -2
- package/examples/jsm/loaders/HDRCubeTextureLoader.js +1 -14
- package/examples/jsm/loaders/KTX2Loader.js +13 -4
- package/examples/jsm/loaders/KTXLoader.js +1 -1
- package/examples/jsm/loaders/LDrawLoader.js +23 -24
- package/examples/jsm/loaders/LUT3dlLoader.js +2 -0
- package/examples/jsm/loaders/LUTCubeLoader.js +2 -0
- package/examples/jsm/loaders/MMDLoader.js +0 -1
- package/examples/jsm/loaders/NRRDLoader.js +10 -2
- package/examples/jsm/loaders/OBJLoader.js +0 -2
- package/examples/jsm/loaders/PLYLoader.js +1 -1
- package/examples/jsm/loaders/RGBELoader.js +0 -20
- package/examples/jsm/loaders/RGBMLoader.js +61 -7
- package/examples/jsm/loaders/SVGLoader.js +2 -2
- package/examples/jsm/loaders/TDSLoader.js +30 -9
- package/examples/jsm/loaders/VOXLoader.js +1 -0
- package/examples/jsm/loaders/VRMLLoader.js +2 -1
- package/examples/jsm/math/ImprovedNoise.js +1 -1
- package/examples/jsm/misc/GPUComputationRenderer.js +3 -1
- package/examples/jsm/node-editor/NodeEditor.js +23 -22
- package/examples/jsm/node-editor/examples/rim.json +1 -1
- package/examples/jsm/node-editor/materials/StandardMaterialEditor.js +48 -9
- package/examples/jsm/node-editor/utils/OscillatorEditor.js +1 -1
- package/examples/jsm/nodes/core/NodeBuilder.js +2 -2
- package/examples/jsm/nodes/materials/nodes/StandardNode.js +1 -0
- package/examples/jsm/nodes/math/MathNode.js +12 -0
- package/examples/jsm/nodes/misc/BumpMapNode.js +1 -1
- package/examples/jsm/nodes/misc/TextureCubeUVNode.js +1 -4
- package/examples/jsm/nodes/utils/ColorSpaceNode.js +1 -116
- package/examples/jsm/objects/Lensflare.js +3 -14
- package/examples/jsm/objects/Reflector.js +7 -0
- package/examples/jsm/objects/Refractor.js +7 -0
- package/examples/jsm/objects/Sky.js +1 -1
- package/examples/jsm/objects/Water.js +2 -2
- package/examples/jsm/objects/Water2.js +4 -8
- package/examples/jsm/postprocessing/GlitchPass.js +3 -1
- package/examples/jsm/postprocessing/SAOPass.js +1 -1
- package/examples/jsm/postprocessing/SSAOPass.js +1 -0
- package/examples/jsm/renderers/nodes/Nodes.js +1 -0
- package/examples/jsm/renderers/nodes/ShaderNode.js +7 -6
- package/examples/jsm/renderers/nodes/core/InputNode.js +1 -1
- package/examples/jsm/renderers/nodes/core/NodeBuilder.js +1 -1
- package/examples/jsm/renderers/nodes/display/ColorSpaceNode.js +26 -31
- package/examples/jsm/renderers/nodes/functions/BSDFs.js +2 -2
- package/examples/jsm/renderers/nodes/functions/PhysicalMaterialFunctions.js +27 -0
- package/examples/jsm/renderers/nodes/inputs/TextureNode.js +1 -1
- package/examples/jsm/renderers/nodes/math/MathNode.js +5 -3
- package/examples/jsm/renderers/nodes/math/OperatorNode.js +2 -2
- package/examples/jsm/renderers/nodes/utils/TimerNode.js +1 -1
- package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +14 -14
- package/examples/jsm/renderers/webgpu/WebGPUBindings.js +7 -6
- package/examples/jsm/renderers/webgpu/WebGPURenderPipeline.js +1 -1
- package/examples/jsm/renderers/webgpu/WebGPURenderPipelines.js +42 -61
- package/examples/jsm/renderers/webgpu/WebGPURenderer.js +2 -2
- package/examples/jsm/renderers/webgpu/WebGPUTextureUtils.js +0 -1
- package/examples/jsm/renderers/webgpu/nodes/WebGPUNodeBuilder.js +30 -4
- package/examples/jsm/shaders/ConvolutionShader.js +0 -1
- package/examples/jsm/shaders/FXAAShader.js +1 -1
- package/examples/jsm/shaders/FilmShader.js +1 -1
- package/examples/jsm/shaders/GammaCorrectionShader.js +1 -1
- package/examples/jsm/shaders/HorizontalBlurShader.js +1 -2
- package/examples/jsm/shaders/SSRShader.js +1 -1
- package/examples/jsm/shaders/SSRrShader.js +1 -1
- package/examples/jsm/shaders/VerticalBlurShader.js +1 -2
- package/examples/jsm/utils/GeometryUtils.js +1 -1
- package/examples/jsm/utils/RoughnessMipmapper.js +19 -32
- package/examples/jsm/utils/WorkerPool.js +11 -11
- package/package.json +15 -9
- package/src/Three.Legacy.js +12 -0
- package/src/Three.js +1 -2
- package/src/constants.js +1 -7
- package/src/core/Object3D.js +1 -1
- package/src/extras/PMREMGenerator.js +19 -110
- package/src/extras/core/Interpolations.js +1 -1
- package/src/geometries/LatheGeometry.js +70 -47
- package/src/helpers/CameraHelper.js +1 -1
- package/src/loaders/FileLoader.js +23 -6
- package/src/math/Color.js +0 -38
- package/src/math/Ray.js +2 -2
- package/src/math/Sphere.js +10 -1
- package/src/objects/Skeleton.js +1 -0
- package/src/renderers/WebGLRenderer.js +23 -16
- package/src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/cube_uv_reflection_fragment.glsl.js +2 -24
- package/src/renderers/shaders/ShaderChunk/encodings_pars_fragment.glsl.js +0 -47
- package/src/renderers/shaders/ShaderChunk/gradientmap_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +27 -1
- package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +10 -0
- package/src/renderers/webgl/WebGLCapabilities.js +0 -2
- package/src/renderers/webgl/WebGLMorphtargets.js +1 -0
- package/src/renderers/webgl/WebGLProgram.js +2 -19
- package/src/renderers/webgl/WebGLPrograms.js +191 -35
- package/src/renderers/webgl/WebGLRenderLists.js +4 -14
- package/src/renderers/webgl/WebGLShaderCache.js +120 -0
- package/src/renderers/webgl/WebGLState.js +45 -0
- package/src/renderers/webgl/WebGLTextures.js +195 -26
- package/src/renderers/webxr/WebXRManager.js +10 -3
- package/src/scenes/Scene.js +1 -1
- package/src/textures/DataTexture.js +0 -2
- package/src/textures/DataTexture2DArray.js +0 -2
- package/src/textures/DataTexture3D.js +0 -2
- package/src/textures/FramebufferTexture.js +25 -0
- package/src/utils.js +1 -37
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import TempNode from '../core/Node.js';
|
|
2
|
-
import { ShaderNode,
|
|
2
|
+
import { ShaderNode,
|
|
3
|
+
vec3,
|
|
4
|
+
pow, mul, add, sub, mix, join,
|
|
5
|
+
lessThanEqual } from '../ShaderNode.js';
|
|
3
6
|
|
|
4
|
-
import { LinearEncoding,
|
|
5
|
-
sRGBEncoding/*, RGBEEncoding, RGBM7Encoding, RGBM16Encoding,
|
|
6
|
-
RGBDEncoding, GammaEncoding*/ } from 'three';
|
|
7
|
+
import { LinearEncoding, sRGBEncoding } from 'three';
|
|
7
8
|
|
|
8
9
|
export const LinearToLinear = new ShaderNode( ( inputs ) => {
|
|
9
10
|
|
|
@@ -27,12 +28,29 @@ export const sRGBToLinear = new ShaderNode( ( inputs ) => {
|
|
|
27
28
|
|
|
28
29
|
} );
|
|
29
30
|
|
|
31
|
+
export const LinearTosRGB = new ShaderNode( ( inputs ) => {
|
|
32
|
+
|
|
33
|
+
const { value } = inputs;
|
|
34
|
+
|
|
35
|
+
const rgb = value.rgb;
|
|
36
|
+
|
|
37
|
+
const a = sub( mul( pow( value.rgb, vec3( 0.41666 ) ), 1.055 ), vec3( 0.055 ) );
|
|
38
|
+
const b = mul( rgb, 12.92 );
|
|
39
|
+
const factor = vec3( lessThanEqual( rgb, vec3( 0.0031308 ) ) );
|
|
40
|
+
|
|
41
|
+
const rgbResult = mix( a, b, factor );
|
|
42
|
+
|
|
43
|
+
return join( rgbResult.r, rgbResult.g, rgbResult.b, value.a );
|
|
44
|
+
|
|
45
|
+
} );
|
|
46
|
+
|
|
30
47
|
const EncodingLib = {
|
|
31
48
|
LinearToLinear,
|
|
32
|
-
sRGBToLinear
|
|
49
|
+
sRGBToLinear,
|
|
50
|
+
LinearTosRGB
|
|
33
51
|
};
|
|
34
52
|
|
|
35
|
-
function getEncodingComponents
|
|
53
|
+
function getEncodingComponents( encoding ) {
|
|
36
54
|
|
|
37
55
|
switch ( encoding ) {
|
|
38
56
|
|
|
@@ -40,18 +58,7 @@ function getEncodingComponents ( encoding ) {
|
|
|
40
58
|
return [ 'Linear' ];
|
|
41
59
|
case sRGBEncoding:
|
|
42
60
|
return [ 'sRGB' ];
|
|
43
|
-
|
|
44
|
-
case RGBEEncoding:
|
|
45
|
-
return [ 'RGBE' ];
|
|
46
|
-
case RGBM7Encoding:
|
|
47
|
-
return [ 'RGBM', new FloatNode( 7.0 ).setConst( true ) ];
|
|
48
|
-
case RGBM16Encoding:
|
|
49
|
-
return [ 'RGBM', new FloatNode( 16.0 ).setConst( true ) ];
|
|
50
|
-
case RGBDEncoding:
|
|
51
|
-
return [ 'RGBD', new FloatNode( 256.0 ).setConst( true ) ];
|
|
52
|
-
case GammaEncoding:
|
|
53
|
-
return [ 'Gamma', new CodeNode( 'float( GAMMA_FACTOR )' ) ];
|
|
54
|
-
*/
|
|
61
|
+
|
|
55
62
|
}
|
|
56
63
|
|
|
57
64
|
}
|
|
@@ -62,19 +69,7 @@ class ColorSpaceNode extends TempNode {
|
|
|
62
69
|
|
|
63
70
|
static SRGB_TO_LINEAR = 'sRGBToLinear';
|
|
64
71
|
static LINEAR_TO_SRGB = 'LinearTosRGB';
|
|
65
|
-
/*
|
|
66
|
-
static GAMMA_TO_LINEAR = 'GammaToLinear';
|
|
67
|
-
static LINEAR_TO_GAMMA = 'LinearToGamma';
|
|
68
|
-
|
|
69
|
-
static RGBE_TO_LINEAR = 'RGBEToLinear';
|
|
70
|
-
static LINEAR_TO_RGBE = 'LinearToRGBE';
|
|
71
|
-
|
|
72
|
-
static RGBM_TO_LINEAR = 'RGBMToLinear';
|
|
73
|
-
static LINEAR_TO_RGBM = 'LinearToRGBM';
|
|
74
72
|
|
|
75
|
-
static RGBD_TO_LINEAR = 'RGBDToLinear';
|
|
76
|
-
static LINEAR_TO_RGBD = 'LinearToRGBD';
|
|
77
|
-
*/
|
|
78
73
|
constructor( method, node ) {
|
|
79
74
|
|
|
80
75
|
super( 'vec4' );
|
|
@@ -117,7 +112,7 @@ class ColorSpaceNode extends TempNode {
|
|
|
117
112
|
|
|
118
113
|
if ( method !== ColorSpaceNode.LINEAR_TO_LINEAR ) {
|
|
119
114
|
|
|
120
|
-
const encodingFunctionNode = EncodingLib[ method ];
|
|
115
|
+
const encodingFunctionNode = EncodingLib[ method ];
|
|
121
116
|
const factor = this.factor;
|
|
122
117
|
|
|
123
118
|
return encodingFunctionNode( {
|
|
@@ -75,7 +75,7 @@ export const D_GGX = new ShaderNode( ( inputs ) => {
|
|
|
75
75
|
|
|
76
76
|
|
|
77
77
|
// GGX Distribution, Schlick Fresnel, GGX_SmithCorrelated Visibility
|
|
78
|
-
export const
|
|
78
|
+
export const BRDF_GGX = new ShaderNode( ( inputs ) => {
|
|
79
79
|
|
|
80
80
|
const { lightDirection, f0, f90, roughness } = inputs;
|
|
81
81
|
|
|
@@ -109,7 +109,7 @@ export const RE_Direct_Physical = new ShaderNode( ( inputs ) => {
|
|
|
109
109
|
|
|
110
110
|
addTo( directDiffuse, mul( irradiance, BRDF_Lambert( { diffuseColor } ) ) );
|
|
111
111
|
|
|
112
|
-
addTo( directSpecular, mul( irradiance,
|
|
112
|
+
addTo( directSpecular, mul( irradiance, BRDF_GGX( { lightDirection, f0: specularColor, f90: 1, roughness } ) ) );
|
|
113
113
|
|
|
114
114
|
} );
|
|
115
115
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ShaderNode,
|
|
2
|
+
add, max, min, abs, dFdx, dFdy,
|
|
3
|
+
normalGeometry
|
|
4
|
+
} from '../ShaderNode.js';
|
|
5
|
+
|
|
6
|
+
export const getGeometryRoughness = new ShaderNode( () => {
|
|
7
|
+
|
|
8
|
+
const dxy = max( abs( dFdx( normalGeometry ) ), abs( dFdy( normalGeometry ) ) );
|
|
9
|
+
const geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );
|
|
10
|
+
|
|
11
|
+
return geometryRoughness;
|
|
12
|
+
|
|
13
|
+
} );
|
|
14
|
+
|
|
15
|
+
export const getRoughness = new ShaderNode( ( inputs ) => {
|
|
16
|
+
|
|
17
|
+
const { roughness } = inputs;
|
|
18
|
+
|
|
19
|
+
const geometryRoughness = getGeometryRoughness();
|
|
20
|
+
|
|
21
|
+
let roughnessFactor = max( roughness, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.
|
|
22
|
+
roughnessFactor = add( roughnessFactor, geometryRoughness );
|
|
23
|
+
roughnessFactor = min( roughnessFactor, 1.0 );
|
|
24
|
+
|
|
25
|
+
return roughnessFactor;
|
|
26
|
+
|
|
27
|
+
} );
|
|
@@ -127,7 +127,9 @@ class MathNode extends TempNode {
|
|
|
127
127
|
const b = this.bNode;
|
|
128
128
|
const c = this.cNode;
|
|
129
129
|
|
|
130
|
-
|
|
130
|
+
const isWebGL = builder.renderer.isWebGLRenderer === true;
|
|
131
|
+
|
|
132
|
+
if ( isWebGL && ( method === MathNode.DFDX || method === MathNode.DFDY ) && output === 'vec3' ) {
|
|
131
133
|
|
|
132
134
|
// Workaround for Adreno 3XX dFd*( vec3 ) bug. See #9988
|
|
133
135
|
|
|
@@ -185,11 +187,11 @@ class MathNode extends TempNode {
|
|
|
185
187
|
} else if ( method === MathNode.STEP ) {
|
|
186
188
|
|
|
187
189
|
params.push(
|
|
188
|
-
|
|
190
|
+
a.build( builder, builder.getTypeLength( a.getNodeType( builder ) ) === 1 ? 'float' : inputType ),
|
|
189
191
|
b.build( builder, inputType )
|
|
190
192
|
);
|
|
191
193
|
|
|
192
|
-
} else if ( method === MathNode.MIN || method === MathNode.MAX || method === MathNode.MOD ) {
|
|
194
|
+
} else if ( ( isWebGL && ( method === MathNode.MIN || method === MathNode.MAX ) ) || method === MathNode.MOD ) {
|
|
193
195
|
|
|
194
196
|
params.push(
|
|
195
197
|
a.build( builder, inputType ),
|
|
@@ -149,11 +149,11 @@ class OperatorNode extends TempNode {
|
|
|
149
149
|
|
|
150
150
|
} else if ( op === '>' && outputLength > 1 ) {
|
|
151
151
|
|
|
152
|
-
return
|
|
152
|
+
return `${ builder.getMethod( 'greaterThan' ) }( ${a}, ${b} )`;
|
|
153
153
|
|
|
154
154
|
} else if ( op === '<=' && outputLength > 1 ) {
|
|
155
155
|
|
|
156
|
-
return
|
|
156
|
+
return `${ builder.getMethod( 'lessThanEqual' ) }( ${a}, ${b} )`;
|
|
157
157
|
|
|
158
158
|
} else {
|
|
159
159
|
|
|
@@ -116,15 +116,15 @@ class WebGLNodeBuilder extends NodeBuilder {
|
|
|
116
116
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
if ( material.
|
|
119
|
+
if ( material.positionNode && material.positionNode.isNode ) {
|
|
120
120
|
|
|
121
|
-
this.addSlot( 'vertex', new SlotNode( material.
|
|
121
|
+
this.addSlot( 'vertex', new SlotNode( material.positionNode, 'POSITION', 'vec3' ) );
|
|
122
122
|
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
if ( material.
|
|
125
|
+
if ( material.sizeNode && material.sizeNode.isNode ) {
|
|
126
126
|
|
|
127
|
-
this.addSlot( 'vertex', new SlotNode( material.
|
|
127
|
+
this.addSlot( 'vertex', new SlotNode( material.sizeNode, 'SIZE', 'float' ) );
|
|
128
128
|
|
|
129
129
|
}
|
|
130
130
|
|
|
@@ -216,7 +216,7 @@ class WebGLNodeBuilder extends NodeBuilder {
|
|
|
216
216
|
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
getVarys( shaderStage ) {
|
|
219
|
+
getVarys( /* shaderStage */ ) {
|
|
220
220
|
|
|
221
221
|
let snippet = '';
|
|
222
222
|
|
|
@@ -285,7 +285,7 @@ class WebGLNodeBuilder extends NodeBuilder {
|
|
|
285
285
|
}
|
|
286
286
|
|
|
287
287
|
getTextureEncodingFromMap( map ) {
|
|
288
|
-
|
|
288
|
+
|
|
289
289
|
const isWebGL2 = this.renderer.capabilities.isWebGL2;
|
|
290
290
|
|
|
291
291
|
if ( isWebGL2 && map && map.isTexture && map.format === RGBAFormat && map.type === UnsignedByteType && map.encoding === sRGBEncoding ) {
|
|
@@ -293,7 +293,7 @@ class WebGLNodeBuilder extends NodeBuilder {
|
|
|
293
293
|
return LinearEncoding; // disable inline decode for sRGB textures in WebGL 2
|
|
294
294
|
|
|
295
295
|
}
|
|
296
|
-
|
|
296
|
+
|
|
297
297
|
return super.getTextureEncodingFromMap( map );
|
|
298
298
|
|
|
299
299
|
}
|
|
@@ -376,8 +376,8 @@ ${this.shader[ getShaderStageProperty( shaderStage ) ]}
|
|
|
376
376
|
this.parseInclude( 'fragment', 'lights_physical_fragment' );
|
|
377
377
|
|
|
378
378
|
const colorSlot = this.getSlot( 'fragment', 'COLOR' );
|
|
379
|
-
const normalSlot = this.getSlot( 'fragment', 'NORMAL' );
|
|
380
379
|
const opacityNode = this.getSlot( 'fragment', 'OPACITY' );
|
|
380
|
+
const normalSlot = this.getSlot( 'fragment', 'NORMAL' );
|
|
381
381
|
const emissiveNode = this.getSlot( 'fragment', 'EMISSIVE' );
|
|
382
382
|
const roughnessNode = this.getSlot( 'fragment', 'ROUGHNESS' );
|
|
383
383
|
const metalnessNode = this.getSlot( 'fragment', 'METALNESS' );
|
|
@@ -397,22 +397,22 @@ ${this.shader[ getShaderStageProperty( shaderStage ) ]}
|
|
|
397
397
|
|
|
398
398
|
}
|
|
399
399
|
|
|
400
|
-
if (
|
|
400
|
+
if ( opacityNode !== undefined ) {
|
|
401
401
|
|
|
402
402
|
this.addCodeAfterInclude(
|
|
403
403
|
'fragment',
|
|
404
|
-
'
|
|
405
|
-
`${
|
|
404
|
+
'alphatest_fragment',
|
|
405
|
+
`${opacityNode.code}\n\tdiffuseColor.a = ${opacityNode.result};`
|
|
406
406
|
);
|
|
407
407
|
|
|
408
408
|
}
|
|
409
409
|
|
|
410
|
-
if (
|
|
410
|
+
if ( normalSlot !== undefined ) {
|
|
411
411
|
|
|
412
412
|
this.addCodeAfterInclude(
|
|
413
413
|
'fragment',
|
|
414
|
-
'
|
|
415
|
-
`${
|
|
414
|
+
'normal_fragment_begin',
|
|
415
|
+
`${normalSlot.code}\n\tnormal = ${normalSlot.result};`
|
|
416
416
|
);
|
|
417
417
|
|
|
418
418
|
}
|
|
@@ -49,6 +49,12 @@ class WebGPUBindings {
|
|
|
49
49
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
remove( object ) {
|
|
53
|
+
|
|
54
|
+
this.uniformsData.delete( object );
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
52
58
|
getForCompute( param ) {
|
|
53
59
|
|
|
54
60
|
let data = this.uniformsData.get( param );
|
|
@@ -108,12 +114,7 @@ class WebGPUBindings {
|
|
|
108
114
|
|
|
109
115
|
if ( needsBufferWrite === true ) {
|
|
110
116
|
|
|
111
|
-
this.device.queue.writeBuffer(
|
|
112
|
-
bufferGPU,
|
|
113
|
-
0,
|
|
114
|
-
buffer,
|
|
115
|
-
0
|
|
116
|
-
);
|
|
117
|
+
this.device.queue.writeBuffer( bufferGPU, 0, buffer, 0 );
|
|
117
118
|
|
|
118
119
|
}
|
|
119
120
|
|
|
@@ -706,7 +706,7 @@ class WebGPURenderPipeline {
|
|
|
706
706
|
const nodeAttributes = nodeBuilder.attributes;
|
|
707
707
|
const attributes = [];
|
|
708
708
|
|
|
709
|
-
for ( let slot = 0; slot < nodeAttributes.length; slot++ ) {
|
|
709
|
+
for ( let slot = 0; slot < nodeAttributes.length; slot ++ ) {
|
|
710
710
|
|
|
711
711
|
const nodeAttribute = nodeAttributes[ slot ];
|
|
712
712
|
|
|
@@ -3,13 +3,13 @@ import WebGPUProgrammableStage from './WebGPUProgrammableStage.js';
|
|
|
3
3
|
|
|
4
4
|
class WebGPURenderPipelines {
|
|
5
5
|
|
|
6
|
-
constructor( renderer,
|
|
6
|
+
constructor( renderer, device, sampleCount, nodes, bindings = null ) {
|
|
7
7
|
|
|
8
8
|
this.renderer = renderer;
|
|
9
|
-
this.properties = properties;
|
|
10
9
|
this.device = device;
|
|
11
10
|
this.sampleCount = sampleCount;
|
|
12
11
|
this.nodes = nodes;
|
|
12
|
+
this.bindings = bindings;
|
|
13
13
|
|
|
14
14
|
this.pipelines = [];
|
|
15
15
|
this.objectCache = new WeakMap();
|
|
@@ -24,10 +24,7 @@ class WebGPURenderPipelines {
|
|
|
24
24
|
get( object ) {
|
|
25
25
|
|
|
26
26
|
const device = this.device;
|
|
27
|
-
const properties = this.properties;
|
|
28
|
-
|
|
29
27
|
const material = object.material;
|
|
30
|
-
const materialProperties = properties.get( material );
|
|
31
28
|
|
|
32
29
|
const cache = this._getCache( object );
|
|
33
30
|
|
|
@@ -35,6 +32,14 @@ class WebGPURenderPipelines {
|
|
|
35
32
|
|
|
36
33
|
if ( this._needsUpdate( object, cache ) ) {
|
|
37
34
|
|
|
35
|
+
// release previous cache
|
|
36
|
+
|
|
37
|
+
if ( cache.currentPipeline !== undefined ) {
|
|
38
|
+
|
|
39
|
+
this._releaseObject( object );
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
38
43
|
// get shader
|
|
39
44
|
|
|
40
45
|
const nodeBuilder = this.nodes.get( object );
|
|
@@ -64,37 +69,15 @@ class WebGPURenderPipelines {
|
|
|
64
69
|
currentPipeline = this._acquirePipeline( stageVertex, stageFragment, object, nodeBuilder );
|
|
65
70
|
cache.currentPipeline = currentPipeline;
|
|
66
71
|
|
|
67
|
-
// keep track of all
|
|
68
|
-
|
|
69
|
-
let materialPipelines = materialProperties.pipelines;
|
|
70
|
-
|
|
71
|
-
if ( materialPipelines === undefined ) {
|
|
72
|
-
|
|
73
|
-
materialPipelines = new Set();
|
|
74
|
-
materialProperties.pipelines = materialPipelines;
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if ( materialPipelines.has( currentPipeline ) === false ) {
|
|
72
|
+
// keep track of all used times
|
|
79
73
|
|
|
80
|
-
|
|
74
|
+
currentPipeline.usedTimes ++;
|
|
75
|
+
stageVertex.usedTimes ++;
|
|
76
|
+
stageFragment.usedTimes ++;
|
|
81
77
|
|
|
82
|
-
|
|
83
|
-
stageVertex.usedTimes ++;
|
|
84
|
-
stageFragment.usedTimes ++;
|
|
78
|
+
// events
|
|
85
79
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
// dispose
|
|
89
|
-
|
|
90
|
-
if ( materialProperties.disposeCallback === undefined ) {
|
|
91
|
-
|
|
92
|
-
const disposeCallback = onMaterialDispose.bind( this );
|
|
93
|
-
materialProperties.disposeCallback = disposeCallback;
|
|
94
|
-
|
|
95
|
-
material.addEventListener( 'dispose', disposeCallback );
|
|
96
|
-
|
|
97
|
-
}
|
|
80
|
+
material.addEventListener( 'dispose', cache.dispose );
|
|
98
81
|
|
|
99
82
|
} else {
|
|
100
83
|
|
|
@@ -182,7 +165,20 @@ class WebGPURenderPipelines {
|
|
|
182
165
|
|
|
183
166
|
if ( cache === undefined ) {
|
|
184
167
|
|
|
185
|
-
cache = {
|
|
168
|
+
cache = {
|
|
169
|
+
|
|
170
|
+
dispose: () => {
|
|
171
|
+
|
|
172
|
+
this._releaseObject( object );
|
|
173
|
+
|
|
174
|
+
this.objectCache.delete( object );
|
|
175
|
+
|
|
176
|
+
object.material.removeEventListener( 'dispose', cache.dispose );
|
|
177
|
+
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
};
|
|
181
|
+
|
|
186
182
|
this.objectCache.set( object, cache );
|
|
187
183
|
|
|
188
184
|
}
|
|
@@ -191,6 +187,18 @@ class WebGPURenderPipelines {
|
|
|
191
187
|
|
|
192
188
|
}
|
|
193
189
|
|
|
190
|
+
_releaseObject( object ) {
|
|
191
|
+
|
|
192
|
+
const cache = this.objectCache.get( object );
|
|
193
|
+
|
|
194
|
+
this._releasePipeline( cache.currentPipeline );
|
|
195
|
+
delete cache.currentPipeline;
|
|
196
|
+
|
|
197
|
+
this.nodes.remove( object );
|
|
198
|
+
this.bindings.remove( object );
|
|
199
|
+
|
|
200
|
+
}
|
|
201
|
+
|
|
194
202
|
_releasePipeline( pipeline ) {
|
|
195
203
|
|
|
196
204
|
if ( -- pipeline.usedTimes === 0 ) {
|
|
@@ -282,31 +290,4 @@ class WebGPURenderPipelines {
|
|
|
282
290
|
|
|
283
291
|
}
|
|
284
292
|
|
|
285
|
-
function onMaterialDispose( event ) {
|
|
286
|
-
|
|
287
|
-
const properties = this.properties;
|
|
288
|
-
|
|
289
|
-
const material = event.target;
|
|
290
|
-
const materialProperties = properties.get( material );
|
|
291
|
-
|
|
292
|
-
material.removeEventListener( 'dispose', materialProperties.disposeCallback );
|
|
293
|
-
|
|
294
|
-
properties.remove( material );
|
|
295
|
-
|
|
296
|
-
// remove references to pipelines
|
|
297
|
-
|
|
298
|
-
const pipelines = materialProperties.pipelines;
|
|
299
|
-
|
|
300
|
-
if ( pipelines !== undefined ) {
|
|
301
|
-
|
|
302
|
-
for ( const pipeline of pipelines ) {
|
|
303
|
-
|
|
304
|
-
this._releasePipeline( pipeline );
|
|
305
|
-
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
}
|
|
311
|
-
|
|
312
293
|
export default WebGPURenderPipelines;
|
|
@@ -183,9 +183,9 @@ class WebGPURenderer {
|
|
|
183
183
|
this._textures = new WebGPUTextures( device, this._properties, this._info );
|
|
184
184
|
this._objects = new WebGPUObjects( this._geometries, this._info );
|
|
185
185
|
this._nodes = new WebGPUNodes( this );
|
|
186
|
-
this._renderPipelines = new WebGPURenderPipelines( this, this._properties, device, parameters.sampleCount, this._nodes );
|
|
187
186
|
this._computePipelines = new WebGPUComputePipelines( device );
|
|
188
|
-
this.
|
|
187
|
+
this._renderPipelines = new WebGPURenderPipelines( this, device, parameters.sampleCount, this._nodes );
|
|
188
|
+
this._bindings = this._renderPipelines.bindings = new WebGPUBindings( device, this._info, this._properties, this._textures, this._renderPipelines, this._computePipelines, this._attributes, this._nodes );
|
|
189
189
|
this._renderLists = new WebGPURenderLists();
|
|
190
190
|
this._background = new WebGPUBackground( this );
|
|
191
191
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { LinearEncoding } from 'three';
|
|
2
|
+
|
|
1
3
|
import WebGPUNodeUniformsGroup from './WebGPUNodeUniformsGroup.js';
|
|
2
4
|
import {
|
|
3
5
|
FloatNodeUniform, Vector2NodeUniform, Vector3NodeUniform, Vector4NodeUniform,
|
|
@@ -19,9 +21,12 @@ import PositionNode from '../../nodes/accessors/PositionNode.js';
|
|
|
19
21
|
import NormalNode from '../../nodes/accessors/NormalNode.js';
|
|
20
22
|
import ModelViewProjectionNode from '../../nodes/accessors/ModelViewProjectionNode.js';
|
|
21
23
|
import SkinningNode from '../../nodes/accessors/SkinningNode.js';
|
|
24
|
+
import ColorSpaceNode from '../../nodes/display/ColorSpaceNode.js';
|
|
22
25
|
import LightContextNode from '../../nodes/lights/LightContextNode.js';
|
|
23
26
|
import OperatorNode from '../../nodes/math/OperatorNode.js';
|
|
24
27
|
import WGSLNodeParser from '../../nodes/parsers/WGSLNodeParser.js';
|
|
28
|
+
import { vec4 } from '../../nodes/ShaderNode.js';
|
|
29
|
+
import { getRoughness } from '../../nodes/functions/PhysicalMaterialFunctions.js';
|
|
25
30
|
|
|
26
31
|
const wgslTypeLib = {
|
|
27
32
|
float: 'f32',
|
|
@@ -30,6 +35,7 @@ const wgslTypeLib = {
|
|
|
30
35
|
vec3: 'vec3<f32>',
|
|
31
36
|
vec4: 'vec4<f32>',
|
|
32
37
|
uvec4: 'vec4<u32>',
|
|
38
|
+
bvec3: 'vec3<bool>',
|
|
33
39
|
mat3: 'mat3x3<f32>',
|
|
34
40
|
mat4: 'mat4x4<f32>'
|
|
35
41
|
};
|
|
@@ -40,6 +46,13 @@ const wgslMethods = {
|
|
|
40
46
|
};
|
|
41
47
|
|
|
42
48
|
const wgslPolyfill = {
|
|
49
|
+
lessThanEqual: new CodeNode( `
|
|
50
|
+
fn lessThanEqual( a : vec3<f32>, b : vec3<f32> ) -> vec3<bool> {
|
|
51
|
+
|
|
52
|
+
return vec3<bool>( a.x <= b.x, a.y <= b.y, a.z <= b.z );
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
` ),
|
|
43
56
|
mod: new CodeNode( `
|
|
44
57
|
fn mod( x : f32, y : f32 ) -> f32 {
|
|
45
58
|
|
|
@@ -135,7 +148,9 @@ class WebGPUNodeBuilder extends NodeBuilder {
|
|
|
135
148
|
|
|
136
149
|
}
|
|
137
150
|
|
|
138
|
-
colorNode = this.addFlow( 'fragment', new VarNode( colorNode, '
|
|
151
|
+
colorNode = this.addFlow( 'fragment', new VarNode( colorNode, 'Color', 'vec4' ) );
|
|
152
|
+
|
|
153
|
+
this.addFlow( 'fragment', new VarNode( colorNode, 'DiffuseColor', 'vec4' ) );
|
|
139
154
|
|
|
140
155
|
// OPACITY
|
|
141
156
|
|
|
@@ -211,11 +226,13 @@ class WebGPUNodeBuilder extends NodeBuilder {
|
|
|
211
226
|
|
|
212
227
|
}
|
|
213
228
|
|
|
229
|
+
roughnessNode = getRoughness( { roughness: roughnessNode } );
|
|
230
|
+
|
|
214
231
|
this.addFlow( 'fragment', new VarNode( roughnessNode, 'Roughness', 'float' ) );
|
|
215
232
|
|
|
216
233
|
// SPECULAR_TINT
|
|
217
234
|
|
|
218
|
-
this.addFlow( 'fragment', new VarNode( new ExpressionNode( 'mix( vec3<f32>( 0.04 ),
|
|
235
|
+
this.addFlow( 'fragment', new VarNode( new ExpressionNode( 'mix( vec3<f32>( 0.04 ), Color.rgb, Metalness )', 'vec3' ), 'SpecularColor', 'color' ) );
|
|
219
236
|
|
|
220
237
|
// NORMAL_VIEW
|
|
221
238
|
|
|
@@ -249,6 +266,15 @@ class WebGPUNodeBuilder extends NodeBuilder {
|
|
|
249
266
|
|
|
250
267
|
// RESULT
|
|
251
268
|
|
|
269
|
+
const outputEncoding = this.renderer.outputEncoding;
|
|
270
|
+
|
|
271
|
+
if ( outputEncoding !== LinearEncoding ) {
|
|
272
|
+
|
|
273
|
+
outputNode = new ColorSpaceNode( ColorSpaceNode.LINEAR_TO_LINEAR, vec4( outputNode ) );
|
|
274
|
+
outputNode.fromEncoding( outputEncoding );
|
|
275
|
+
|
|
276
|
+
}
|
|
277
|
+
|
|
252
278
|
this.addFlow( 'fragment', new VarNode( outputNode, 'Output', 'vec4' ) );
|
|
253
279
|
|
|
254
280
|
}
|
|
@@ -267,7 +293,7 @@ class WebGPUNodeBuilder extends NodeBuilder {
|
|
|
267
293
|
|
|
268
294
|
}
|
|
269
295
|
|
|
270
|
-
getTexture( textureProperty, uvSnippet, biasSnippet
|
|
296
|
+
getTexture( textureProperty, uvSnippet, biasSnippet, shaderStage = this.shaderStage ) {
|
|
271
297
|
|
|
272
298
|
if ( shaderStage === 'fragment' ) {
|
|
273
299
|
|
|
@@ -757,7 +783,7 @@ fn main( ${shaderData.varys} ) -> [[ location( 0 ) ]] vec4<f32> {
|
|
|
757
783
|
|
|
758
784
|
_getWGSLStruct( name, vars ) {
|
|
759
785
|
|
|
760
|
-
return `
|
|
786
|
+
return `
|
|
761
787
|
struct ${name} {
|
|
762
788
|
\n${vars}
|
|
763
789
|
};`;
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* NVIDIA FXAA by Timothy Lottes
|
|
7
|
-
*
|
|
7
|
+
* https://developer.download.nvidia.com/assets/gamedev/files/sdk/11/FXAA_WhitePaper.pdf
|
|
8
8
|
* - WebGL port by @supereggbert
|
|
9
9
|
* http://www.glge.org/demos/fxaa/
|
|
10
10
|
*/
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Film grain & scanlines shader
|
|
3
3
|
*
|
|
4
4
|
* - ported from HLSL to WebGL / GLSL
|
|
5
|
-
* http://www.truevision3d.com/forums/showcase/staticnoise_colorblackwhite_scanline_shaders-t18698.0.html
|
|
5
|
+
* https://web.archive.org/web/20210226214859/http://www.truevision3d.com/forums/showcase/staticnoise_colorblackwhite_scanline_shaders-t18698.0.html
|
|
6
6
|
*
|
|
7
7
|
* Screen Space Static Postprocessor
|
|
8
8
|
*
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Two pass Gaussian blur filter (horizontal and vertical blur shaders)
|
|
3
|
-
* -
|
|
4
|
-
* and used in http://www.cake23.de/traveling-wavefronts-lit-up.html
|
|
3
|
+
* - see http://www.cake23.de/traveling-wavefronts-lit-up.html
|
|
5
4
|
*
|
|
6
5
|
* - 9 samples per pass
|
|
7
6
|
* - standard deviation 2.7
|
|
@@ -175,7 +175,7 @@ var SSRShader = {
|
|
|
175
175
|
vec3 vP=getViewPosition( uv, d, cW );
|
|
176
176
|
|
|
177
177
|
#ifdef PERSPECTIVE_CAMERA
|
|
178
|
-
// https://
|
|
178
|
+
// https://comp.nus.edu.sg/~lowkl/publications/lowk_persp_interp_techrep.pdf
|
|
179
179
|
float recipVPZ=1./viewPosition.z;
|
|
180
180
|
float viewReflectRayZ=1./(recipVPZ+s*(1./d1viewPosition.z-recipVPZ));
|
|
181
181
|
#else
|
|
@@ -190,7 +190,7 @@ const SSRrShader = {
|
|
|
190
190
|
vec3 vP=getViewPosition( uv, d, cW );
|
|
191
191
|
|
|
192
192
|
#ifdef PERSPECTIVE_CAMERA
|
|
193
|
-
// https://
|
|
193
|
+
// https://comp.nus.edu.sg/~lowkl/publications/lowk_persp_interp_techrep.pdf
|
|
194
194
|
float recipVPZ=1./viewPosition.z;
|
|
195
195
|
float viewRefractRayZ=1./(recipVPZ+s*(1./d1viewPosition.z-recipVPZ));
|
|
196
196
|
float sD=surfDist*cW;
|