super-three 0.155.0 → 0.156.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.cjs +107 -125
- package/build/three.js +107 -125
- package/build/three.min.js +1 -1
- package/build/three.module.js +104 -126
- package/build/three.module.min.js +1 -1
- package/examples/jsm/controls/OrbitControls.js +13 -5
- package/examples/jsm/csm/CSMShader.js +35 -1
- package/examples/jsm/libs/tween.module.js +790 -735
- package/examples/jsm/libs/utif.module.js +1644 -1558
- package/examples/jsm/loaders/DDSLoader.js +46 -3
- package/examples/jsm/loaders/EXRLoader.js +4 -4
- package/examples/jsm/loaders/FBXLoader.js +2 -0
- package/examples/jsm/loaders/GLTFLoader.js +17 -7
- package/examples/jsm/loaders/KTX2Loader.js +126 -77
- package/examples/jsm/loaders/LogLuvLoader.js +2 -2
- package/examples/jsm/loaders/MMDLoader.js +10 -7
- package/examples/jsm/loaders/RGBELoader.js +48 -66
- package/examples/jsm/loaders/STLLoader.js +7 -0
- package/examples/jsm/nodes/Nodes.js +3 -0
- package/examples/jsm/nodes/accessors/BufferAttributeNode.js +28 -2
- package/examples/jsm/nodes/accessors/CubeTextureNode.js +18 -3
- package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +2 -4
- package/examples/jsm/nodes/accessors/LineMaterialNode.js +31 -0
- package/examples/jsm/nodes/accessors/MaterialNode.js +55 -33
- package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +3 -0
- package/examples/jsm/nodes/accessors/Object3DNode.js +2 -2
- package/examples/jsm/nodes/accessors/TextureNode.js +6 -2
- package/examples/jsm/nodes/accessors/TextureStoreNode.js +29 -0
- package/examples/jsm/nodes/core/AttributeNode.js +2 -2
- package/examples/jsm/nodes/core/Node.js +17 -1
- package/examples/jsm/nodes/core/NodeBuilder.js +94 -12
- package/examples/jsm/nodes/core/NodeUniform.js +1 -1
- package/examples/jsm/nodes/core/OutputStructNode.js +58 -0
- package/examples/jsm/nodes/core/PropertyNode.js +2 -0
- package/examples/jsm/nodes/core/StackNode.js +4 -4
- package/examples/jsm/nodes/core/StructTypeNode.js +24 -0
- package/examples/jsm/nodes/display/ViewportNode.js +19 -5
- package/examples/jsm/nodes/materials/LineDashedNodeMaterial.js +54 -0
- package/examples/jsm/nodes/materials/Materials.js +1 -0
- package/examples/jsm/nodes/materials/NodeMaterial.js +12 -3
- package/examples/jsm/nodes/math/HashNode.js +35 -0
- package/examples/jsm/nodes/shadernode/ShaderNode.js +4 -0
- package/examples/jsm/nodes/utils/SplitNode.js +1 -1
- package/examples/jsm/postprocessing/FilmPass.js +3 -5
- package/examples/jsm/postprocessing/RenderPass.js +30 -12
- package/examples/jsm/postprocessing/SAOPass.js +23 -98
- package/examples/jsm/postprocessing/SSAOPass.js +10 -30
- package/examples/jsm/renderers/common/Backend.js +11 -8
- package/examples/jsm/renderers/common/Binding.js +6 -0
- package/examples/jsm/renderers/common/Bindings.js +5 -4
- package/examples/jsm/renderers/common/Pipelines.js +2 -2
- package/examples/jsm/renderers/common/RenderContexts.js +26 -1
- package/examples/jsm/renderers/common/RenderList.js +12 -4
- package/examples/jsm/renderers/common/RenderObject.js +6 -2
- package/examples/jsm/renderers/common/Renderer.js +12 -3
- package/examples/jsm/renderers/common/SampledTexture.js +2 -1
- package/examples/jsm/renderers/common/Sampler.js +1 -1
- package/examples/jsm/renderers/common/StorageBuffer.js +1 -1
- package/examples/jsm/renderers/common/Textures.js +155 -15
- package/examples/jsm/renderers/common/nodes/NodeSampledTexture.js +2 -2
- package/examples/jsm/renderers/common/nodes/NodeSampler.js +1 -1
- package/examples/jsm/renderers/common/nodes/Nodes.js +43 -9
- package/examples/jsm/renderers/webgl/WebGLBackend.js +607 -0
- package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +118 -17
- package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +84 -0
- package/examples/jsm/renderers/webgl/utils/WebGLExtensions.js +26 -0
- package/examples/jsm/renderers/webgl/utils/WebGLState.js +529 -0
- package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +199 -0
- package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +242 -0
- package/examples/jsm/renderers/webgl-legacy/nodes/GLSL1NodeBuilder.js +340 -0
- package/examples/jsm/renderers/{webgl → webgl-legacy}/nodes/WebGLNodeBuilder.js +1 -1
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +279 -40
- package/examples/jsm/renderers/webgpu/WebGPURenderer.js +18 -2
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +89 -59
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeFunction.js +2 -2
- package/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +15 -2
- package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +34 -9
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +26 -135
- package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +6 -5
- package/examples/jsm/shaders/FilmShader.js +11 -54
- package/examples/jsm/shaders/SAOShader.js +0 -13
- package/examples/jsm/shaders/SSAOShader.js +33 -26
- package/package.json +1 -1
- package/src/Three.js +1 -0
- package/src/audio/Audio.js +6 -0
- package/src/constants.js +4 -1
- package/src/core/Object3D.js +1 -14
- package/src/core/UniformsGroup.js +2 -2
- package/src/loaders/DataTextureLoader.js +0 -2
- package/src/materials/Material.js +2 -2
- package/src/math/Vector2.js +2 -2
- package/src/math/Vector3.js +3 -3
- package/src/math/Vector4.js +4 -4
- package/src/objects/Line.js +1 -1
- package/src/objects/Mesh.js +1 -1
- package/src/objects/Points.js +1 -1
- package/src/renderers/WebGLRenderer.js +21 -49
- package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +11 -1
- package/src/renderers/shaders/ShaderLib/background.glsl.js +8 -0
- package/src/renderers/webgl/WebGLBackground.js +5 -14
- package/src/renderers/webgl/WebGLProgram.js +2 -0
- package/src/renderers/webgl/WebGLPrograms.js +5 -1
- package/src/renderers/webgl/WebGLTextures.js +4 -4
- package/src/renderers/webgl/WebGLUtils.js +27 -20
- package/src/textures/Texture.js +2 -2
- package/src/utils.js +9 -1
- /package/examples/jsm/renderers/{webgl → webgl-legacy}/nodes/SlotNode.js +0 -0
- /package/examples/jsm/renderers/{webgl → webgl-legacy}/nodes/WebGLNodes.js +0 -0
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CullFaceNone, CullFaceBack, CullFaceFront, DoubleSide, BackSide,
|
|
3
|
+
NormalBlending, NoBlending, CustomBlending, AddEquation,
|
|
4
|
+
AdditiveBlending, SubtractiveBlending, MultiplyBlending, SubtractEquation, ReverseSubtractEquation,
|
|
5
|
+
ZeroFactor, OneFactor, SrcColorFactor, SrcAlphaFactor, SrcAlphaSaturateFactor, DstColorFactor, DstAlphaFactor,
|
|
6
|
+
OneMinusSrcColorFactor, OneMinusSrcAlphaFactor, OneMinusDstColorFactor, OneMinusDstAlphaFactor,
|
|
7
|
+
NeverDepth, AlwaysDepth, LessDepth, LessEqualDepth, EqualDepth, GreaterEqualDepth, GreaterDepth, NotEqualDepth
|
|
8
|
+
} from 'three';
|
|
9
|
+
|
|
10
|
+
let initialized = false, equationToGL, factorToGL;
|
|
11
|
+
|
|
12
|
+
class WebGLState {
|
|
13
|
+
|
|
14
|
+
constructor( backend ) {
|
|
15
|
+
|
|
16
|
+
this.backend = backend;
|
|
17
|
+
|
|
18
|
+
this.gl = this.backend.gl;
|
|
19
|
+
|
|
20
|
+
this.enabled = {};
|
|
21
|
+
this.currentFlipSided = null;
|
|
22
|
+
this.currentCullFace = null;
|
|
23
|
+
this.currentProgram = null;
|
|
24
|
+
this.currentBlendingEnabled = null;
|
|
25
|
+
this.currentBlending = null;
|
|
26
|
+
this.currentBlendSrc = null;
|
|
27
|
+
this.currentBlendDst = null;
|
|
28
|
+
this.currentBlendSrcAlpha = null;
|
|
29
|
+
this.currentBlendDstAlpha = null;
|
|
30
|
+
this.currentPremultipledAlpha = null;
|
|
31
|
+
this.currentPolygonOffsetFactor = null;
|
|
32
|
+
this.currentPolygonOffsetUnits = null;
|
|
33
|
+
this.currentDepthFunc = null;
|
|
34
|
+
this.currentDepthMask = null;
|
|
35
|
+
this.currentStencilFunc = null;
|
|
36
|
+
this.currentStencilRef = null;
|
|
37
|
+
this.currentStencilFuncMask = null;
|
|
38
|
+
this.currentStencilFail = null;
|
|
39
|
+
this.currentStencilZFail = null;
|
|
40
|
+
this.currentStencilZPass = null;
|
|
41
|
+
this.currentStencilMask = null;
|
|
42
|
+
|
|
43
|
+
if ( initialized === false ) {
|
|
44
|
+
|
|
45
|
+
this._init( this.gl );
|
|
46
|
+
|
|
47
|
+
initialized = true;
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
_init( gl ) {
|
|
54
|
+
|
|
55
|
+
// Store only WebGL constants here.
|
|
56
|
+
|
|
57
|
+
equationToGL = {
|
|
58
|
+
[ AddEquation ]: gl.FUNC_ADD,
|
|
59
|
+
[ SubtractEquation ]: gl.FUNC_SUBTRACT,
|
|
60
|
+
[ ReverseSubtractEquation ]: gl.FUNC_REVERSE_SUBTRACT
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
factorToGL = {
|
|
64
|
+
[ ZeroFactor ]: gl.ZERO,
|
|
65
|
+
[ OneFactor ]: gl.ONE,
|
|
66
|
+
[ SrcColorFactor ]: gl.SRC_COLOR,
|
|
67
|
+
[ SrcAlphaFactor ]: gl.SRC_ALPHA,
|
|
68
|
+
[ SrcAlphaSaturateFactor ]: gl.SRC_ALPHA_SATURATE,
|
|
69
|
+
[ DstColorFactor ]: gl.DST_COLOR,
|
|
70
|
+
[ DstAlphaFactor ]: gl.DST_ALPHA,
|
|
71
|
+
[ OneMinusSrcColorFactor ]: gl.ONE_MINUS_SRC_COLOR,
|
|
72
|
+
[ OneMinusSrcAlphaFactor ]: gl.ONE_MINUS_SRC_ALPHA,
|
|
73
|
+
[ OneMinusDstColorFactor ]: gl.ONE_MINUS_DST_COLOR,
|
|
74
|
+
[ OneMinusDstAlphaFactor ]: gl.ONE_MINUS_DST_ALPHA
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
enable( id ) {
|
|
80
|
+
|
|
81
|
+
const { enabled } = this;
|
|
82
|
+
|
|
83
|
+
if ( enabled[ id ] !== true ) {
|
|
84
|
+
|
|
85
|
+
this.gl.enable( id );
|
|
86
|
+
enabled[ id ] = true;
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
disable( id ) {
|
|
93
|
+
|
|
94
|
+
const { enabled } = this;
|
|
95
|
+
|
|
96
|
+
if ( enabled[ id ] !== false ) {
|
|
97
|
+
|
|
98
|
+
this.gl.disable( id );
|
|
99
|
+
enabled[ id ] = false;
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
setFlipSided( flipSided ) {
|
|
106
|
+
|
|
107
|
+
if ( this.currentFlipSided !== flipSided ) {
|
|
108
|
+
|
|
109
|
+
const { gl } = this;
|
|
110
|
+
|
|
111
|
+
if ( flipSided ) {
|
|
112
|
+
|
|
113
|
+
gl.frontFace( gl.CW );
|
|
114
|
+
|
|
115
|
+
} else {
|
|
116
|
+
|
|
117
|
+
gl.frontFace( gl.CCW );
|
|
118
|
+
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
this.currentFlipSided = flipSided;
|
|
122
|
+
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
setCullFace( cullFace ) {
|
|
128
|
+
|
|
129
|
+
const { gl } = this;
|
|
130
|
+
|
|
131
|
+
if ( cullFace !== CullFaceNone ) {
|
|
132
|
+
|
|
133
|
+
this.enable( gl.CULL_FACE );
|
|
134
|
+
|
|
135
|
+
if ( cullFace !== this.currentCullFace ) {
|
|
136
|
+
|
|
137
|
+
if ( cullFace === CullFaceBack ) {
|
|
138
|
+
|
|
139
|
+
gl.cullFace( gl.BACK );
|
|
140
|
+
|
|
141
|
+
} else if ( cullFace === CullFaceFront ) {
|
|
142
|
+
|
|
143
|
+
gl.cullFace( gl.FRONT );
|
|
144
|
+
|
|
145
|
+
} else {
|
|
146
|
+
|
|
147
|
+
gl.cullFace( gl.FRONT_AND_BACK );
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
} else {
|
|
154
|
+
|
|
155
|
+
this.disable( gl.CULL_FACE );
|
|
156
|
+
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
this.currentCullFace = cullFace;
|
|
160
|
+
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
|
|
164
|
+
|
|
165
|
+
const { gl } = this;
|
|
166
|
+
|
|
167
|
+
if ( blending === NoBlending ) {
|
|
168
|
+
|
|
169
|
+
if ( this.currentBlendingEnabled === true ) {
|
|
170
|
+
|
|
171
|
+
this.disable( gl.BLEND );
|
|
172
|
+
this.currentBlendingEnabled = false;
|
|
173
|
+
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return;
|
|
177
|
+
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if ( this.currentBlendingEnabled === false ) {
|
|
181
|
+
|
|
182
|
+
this.enable( gl.BLEND );
|
|
183
|
+
this.currentBlendingEnabled = true;
|
|
184
|
+
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if ( blending !== CustomBlending ) {
|
|
188
|
+
|
|
189
|
+
if ( blending !== this.currentBlending || premultipliedAlpha !== this.currentPremultipledAlpha ) {
|
|
190
|
+
|
|
191
|
+
if ( this.currentBlendEquation !== AddEquation || this.currentBlendEquationAlpha !== AddEquation ) {
|
|
192
|
+
|
|
193
|
+
gl.blendEquation( gl.FUNC_ADD );
|
|
194
|
+
|
|
195
|
+
this.currentBlendEquation = AddEquation;
|
|
196
|
+
this.currentBlendEquationAlpha = AddEquation;
|
|
197
|
+
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if ( premultipliedAlpha ) {
|
|
201
|
+
|
|
202
|
+
switch ( blending ) {
|
|
203
|
+
|
|
204
|
+
case NormalBlending:
|
|
205
|
+
gl.blendFuncSeparate( gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
|
|
206
|
+
break;
|
|
207
|
+
|
|
208
|
+
case AdditiveBlending:
|
|
209
|
+
gl.blendFunc( gl.ONE, gl.ONE );
|
|
210
|
+
break;
|
|
211
|
+
|
|
212
|
+
case SubtractiveBlending:
|
|
213
|
+
gl.blendFuncSeparate( gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ZERO, gl.ONE );
|
|
214
|
+
break;
|
|
215
|
+
|
|
216
|
+
case MultiplyBlending:
|
|
217
|
+
gl.blendFuncSeparate( gl.ZERO, gl.SRC_COLOR, gl.ZERO, gl.SRC_ALPHA );
|
|
218
|
+
break;
|
|
219
|
+
|
|
220
|
+
default:
|
|
221
|
+
console.error( 'THREE.WebGLState: Invalid blending: ', blending );
|
|
222
|
+
break;
|
|
223
|
+
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
} else {
|
|
227
|
+
|
|
228
|
+
switch ( blending ) {
|
|
229
|
+
|
|
230
|
+
case NormalBlending:
|
|
231
|
+
gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
|
|
232
|
+
break;
|
|
233
|
+
|
|
234
|
+
case AdditiveBlending:
|
|
235
|
+
gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
|
|
236
|
+
break;
|
|
237
|
+
|
|
238
|
+
case SubtractiveBlending:
|
|
239
|
+
gl.blendFuncSeparate( gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ZERO, gl.ONE );
|
|
240
|
+
break;
|
|
241
|
+
|
|
242
|
+
case MultiplyBlending:
|
|
243
|
+
gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
|
|
244
|
+
break;
|
|
245
|
+
|
|
246
|
+
default:
|
|
247
|
+
console.error( 'THREE.WebGLState: Invalid blending: ', blending );
|
|
248
|
+
break;
|
|
249
|
+
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
this.currentBlendSrc = null;
|
|
255
|
+
this.currentBlendDst = null;
|
|
256
|
+
this.currentBlendSrcAlpha = null;
|
|
257
|
+
this.currentBlendDstAlpha = null;
|
|
258
|
+
|
|
259
|
+
this.currentBlending = blending;
|
|
260
|
+
this.currentPremultipledAlpha = premultipliedAlpha;
|
|
261
|
+
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return;
|
|
265
|
+
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// custom blending
|
|
269
|
+
|
|
270
|
+
blendEquationAlpha = blendEquationAlpha || blendEquation;
|
|
271
|
+
blendSrcAlpha = blendSrcAlpha || blendSrc;
|
|
272
|
+
blendDstAlpha = blendDstAlpha || blendDst;
|
|
273
|
+
|
|
274
|
+
if ( blendEquation !== this.currentBlendEquation || blendEquationAlpha !== this.currentBlendEquationAlpha ) {
|
|
275
|
+
|
|
276
|
+
gl.blendEquationSeparate( equationToGL[ blendEquation ], equationToGL[ blendEquationAlpha ] );
|
|
277
|
+
|
|
278
|
+
this.currentBlendEquation = blendEquation;
|
|
279
|
+
this.currentBlendEquationAlpha = blendEquationAlpha;
|
|
280
|
+
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if ( blendSrc !== this.currentBlendSrc || blendDst !== this.currentBlendDst || blendSrcAlpha !== this.currentBlendSrcAlpha || blendDstAlpha !== this.currentBlendDstAlpha ) {
|
|
284
|
+
|
|
285
|
+
gl.blendFuncSeparate( factorToGL[ blendSrc ], factorToGL[ blendDst ], factorToGL[ blendSrcAlpha ], factorToGL[ blendDstAlpha ] );
|
|
286
|
+
|
|
287
|
+
this.currentBlendSrc = blendSrc;
|
|
288
|
+
this.currentBlendDst = blendDst;
|
|
289
|
+
this.currentBlendSrcAlpha = blendSrcAlpha;
|
|
290
|
+
this.currentBlendDstAlpha = blendDstAlpha;
|
|
291
|
+
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
this.currentBlending = blending;
|
|
295
|
+
this.currentPremultipledAlpha = false;
|
|
296
|
+
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
setDepthTest( depthTest ) {
|
|
300
|
+
|
|
301
|
+
const { gl } = this;
|
|
302
|
+
|
|
303
|
+
if ( depthTest ) {
|
|
304
|
+
|
|
305
|
+
this.enable( gl.DEPTH_TEST );
|
|
306
|
+
|
|
307
|
+
} else {
|
|
308
|
+
|
|
309
|
+
this.disable( gl.DEPTH_TEST );
|
|
310
|
+
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
setDepthMask( depthMask ) {
|
|
316
|
+
|
|
317
|
+
if ( this.currentDepthMask !== depthMask ) {
|
|
318
|
+
|
|
319
|
+
this.gl.depthMask( depthMask );
|
|
320
|
+
this.currentDepthMask = depthMask;
|
|
321
|
+
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
setDepthFunc( depthFunc ) {
|
|
327
|
+
|
|
328
|
+
if ( this.currentDepthFunc !== depthFunc ) {
|
|
329
|
+
|
|
330
|
+
const { gl } = this;
|
|
331
|
+
|
|
332
|
+
switch ( depthFunc ) {
|
|
333
|
+
|
|
334
|
+
case NeverDepth:
|
|
335
|
+
|
|
336
|
+
gl.depthFunc( gl.NEVER );
|
|
337
|
+
break;
|
|
338
|
+
|
|
339
|
+
case AlwaysDepth:
|
|
340
|
+
|
|
341
|
+
gl.depthFunc( gl.ALWAYS );
|
|
342
|
+
break;
|
|
343
|
+
|
|
344
|
+
case LessDepth:
|
|
345
|
+
|
|
346
|
+
gl.depthFunc( gl.LESS );
|
|
347
|
+
break;
|
|
348
|
+
|
|
349
|
+
case LessEqualDepth:
|
|
350
|
+
|
|
351
|
+
gl.depthFunc( gl.LEQUAL );
|
|
352
|
+
break;
|
|
353
|
+
|
|
354
|
+
case EqualDepth:
|
|
355
|
+
|
|
356
|
+
gl.depthFunc( gl.EQUAL );
|
|
357
|
+
break;
|
|
358
|
+
|
|
359
|
+
case GreaterEqualDepth:
|
|
360
|
+
|
|
361
|
+
gl.depthFunc( gl.GEQUAL );
|
|
362
|
+
break;
|
|
363
|
+
|
|
364
|
+
case GreaterDepth:
|
|
365
|
+
|
|
366
|
+
gl.depthFunc( gl.GREATER );
|
|
367
|
+
break;
|
|
368
|
+
|
|
369
|
+
case NotEqualDepth:
|
|
370
|
+
|
|
371
|
+
gl.depthFunc( gl.NOTEQUAL );
|
|
372
|
+
break;
|
|
373
|
+
|
|
374
|
+
default:
|
|
375
|
+
|
|
376
|
+
gl.depthFunc( gl.LEQUAL );
|
|
377
|
+
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
this.currentDepthFunc = depthFunc;
|
|
381
|
+
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
setStencilTest( stencilTest ) {
|
|
387
|
+
|
|
388
|
+
const { gl } = this;
|
|
389
|
+
|
|
390
|
+
if ( stencilTest ) {
|
|
391
|
+
|
|
392
|
+
this.enable( gl.STENCIL_TEST );
|
|
393
|
+
|
|
394
|
+
} else {
|
|
395
|
+
|
|
396
|
+
this.disable( gl.STENCIL_TEST );
|
|
397
|
+
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
setStencilMask( stencilMask ) {
|
|
403
|
+
|
|
404
|
+
if ( this.currentStencilMask !== stencilMask ) {
|
|
405
|
+
|
|
406
|
+
this.gl.stencilMask( stencilMask );
|
|
407
|
+
this.currentStencilMask = stencilMask;
|
|
408
|
+
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
setStencilFunc( stencilFunc, stencilRef, stencilMask ) {
|
|
414
|
+
|
|
415
|
+
if ( this.currentStencilFunc !== stencilFunc ||
|
|
416
|
+
this.currentStencilRef !== stencilRef ||
|
|
417
|
+
this.currentStencilFuncMask !== stencilMask ) {
|
|
418
|
+
|
|
419
|
+
this.gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
|
|
420
|
+
|
|
421
|
+
this.currentStencilFunc = stencilFunc;
|
|
422
|
+
this.currentStencilRef = stencilRef;
|
|
423
|
+
this.currentStencilFuncMask = stencilMask;
|
|
424
|
+
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
setStencilOp( stencilFail, stencilZFail, stencilZPass ) {
|
|
430
|
+
|
|
431
|
+
if ( this.currentStencilFail !== stencilFail ||
|
|
432
|
+
this.currentStencilZFail !== stencilZFail ||
|
|
433
|
+
this.currentStencilZPass !== stencilZPass ) {
|
|
434
|
+
|
|
435
|
+
this.gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
|
|
436
|
+
|
|
437
|
+
this.currentStencilFail = stencilFail;
|
|
438
|
+
this.currentStencilZFail = stencilZFail;
|
|
439
|
+
this.currentStencilZPass = stencilZPass;
|
|
440
|
+
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
setMaterial( material, frontFaceCW ) {
|
|
446
|
+
|
|
447
|
+
const { gl } = this;
|
|
448
|
+
|
|
449
|
+
material.side === DoubleSide
|
|
450
|
+
? this.disable( gl.CULL_FACE )
|
|
451
|
+
: this.enable( gl.CULL_FACE );
|
|
452
|
+
|
|
453
|
+
let flipSided = ( material.side === BackSide );
|
|
454
|
+
if ( frontFaceCW ) flipSided = ! flipSided;
|
|
455
|
+
|
|
456
|
+
this.setFlipSided( flipSided );
|
|
457
|
+
|
|
458
|
+
( material.blending === NormalBlending && material.transparent === false )
|
|
459
|
+
? this.setBlending( NoBlending )
|
|
460
|
+
: this.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
|
|
461
|
+
|
|
462
|
+
this.setDepthFunc( material.depthFunc );
|
|
463
|
+
this.setDepthTest( material.depthTest );
|
|
464
|
+
this.setDepthMask( material.depthWrite );
|
|
465
|
+
this.setDepthMask( material.colorWrite );
|
|
466
|
+
|
|
467
|
+
const stencilWrite = material.stencilWrite;
|
|
468
|
+
this.setStencilTest( stencilWrite );
|
|
469
|
+
if ( stencilWrite ) {
|
|
470
|
+
|
|
471
|
+
this.setStencilMask( material.stencilWriteMask );
|
|
472
|
+
this.setStencilFunc( material.stencilFunc, material.stencilRef, material.stencilFuncMask );
|
|
473
|
+
this.setStencilOp( material.stencilFail, material.stencilZFail, material.stencilZPass );
|
|
474
|
+
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
this.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
|
|
478
|
+
|
|
479
|
+
material.alphaToCoverage === true
|
|
480
|
+
? this.enable( gl.SAMPLE_ALPHA_TO_COVERAGE )
|
|
481
|
+
: this.disable( gl.SAMPLE_ALPHA_TO_COVERAGE );
|
|
482
|
+
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
setPolygonOffset( polygonOffset, factor, units ) {
|
|
486
|
+
|
|
487
|
+
const { gl } = this;
|
|
488
|
+
|
|
489
|
+
if ( polygonOffset ) {
|
|
490
|
+
|
|
491
|
+
this.enable( gl.POLYGON_OFFSET_FILL );
|
|
492
|
+
|
|
493
|
+
if ( this.currentPolygonOffsetFactor !== factor || this.currentPolygonOffsetUnits !== units ) {
|
|
494
|
+
|
|
495
|
+
gl.polygonOffset( factor, units );
|
|
496
|
+
|
|
497
|
+
this.currentPolygonOffsetFactor = factor;
|
|
498
|
+
this.currentPolygonOffsetUnits = units;
|
|
499
|
+
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
} else {
|
|
503
|
+
|
|
504
|
+
this.disable( gl.POLYGON_OFFSET_FILL );
|
|
505
|
+
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
useProgram( program ) {
|
|
511
|
+
|
|
512
|
+
if ( this.currentProgram !== program ) {
|
|
513
|
+
|
|
514
|
+
this.gl.useProgram( program );
|
|
515
|
+
|
|
516
|
+
this.currentProgram = program;
|
|
517
|
+
|
|
518
|
+
return true;
|
|
519
|
+
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
return false;
|
|
523
|
+
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
export default WebGLState;
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { LinearFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, NearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, RGBAFormat, DepthFormat, DepthStencilFormat, UnsignedShortType, UnsignedIntType, UnsignedInt248Type, FloatType, HalfFloatType, MirroredRepeatWrapping, ClampToEdgeWrapping, RepeatWrapping, UnsignedByteType, _SRGBAFormat, NoColorSpace, LinearSRGBColorSpace, SRGBColorSpace, NeverCompare, AlwaysCompare, LessCompare, LessEqualCompare, EqualCompare, GreaterEqualCompare, GreaterCompare, NotEqualCompare } from 'three';
|
|
2
|
+
|
|
3
|
+
let initialized = false, wrappingToGL, filterToGL, compareToGL;
|
|
4
|
+
|
|
5
|
+
class WebGLTextureUtils {
|
|
6
|
+
|
|
7
|
+
constructor( backend ) {
|
|
8
|
+
|
|
9
|
+
this.backend = backend;
|
|
10
|
+
|
|
11
|
+
this.gl = backend.gl;
|
|
12
|
+
this.extensions = backend.extensions;
|
|
13
|
+
|
|
14
|
+
if ( initialized === false ) {
|
|
15
|
+
|
|
16
|
+
this._init( this.gl );
|
|
17
|
+
|
|
18
|
+
initialized = true;
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
_init( gl ) {
|
|
25
|
+
|
|
26
|
+
// Store only WebGL constants here.
|
|
27
|
+
|
|
28
|
+
wrappingToGL = {
|
|
29
|
+
[ RepeatWrapping ]: gl.REPEAT,
|
|
30
|
+
[ ClampToEdgeWrapping ]: gl.CLAMP_TO_EDGE,
|
|
31
|
+
[ MirroredRepeatWrapping ]: gl.MIRRORED_REPEAT
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
filterToGL = {
|
|
35
|
+
[ NearestFilter ]: gl.NEAREST,
|
|
36
|
+
[ NearestMipmapNearestFilter ]: gl.NEAREST_MIPMAP_NEAREST,
|
|
37
|
+
[ NearestMipmapLinearFilter ]: gl.NEAREST_MIPMAP_LINEAR,
|
|
38
|
+
|
|
39
|
+
[ LinearFilter ]: gl.LINEAR,
|
|
40
|
+
[ LinearMipmapNearestFilter ]: gl.LINEAR_MIPMAP_NEAREST,
|
|
41
|
+
[ LinearMipmapLinearFilter ]: gl.LINEAR_MIPMAP_LINEAR
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
compareToGL = {
|
|
45
|
+
[ NeverCompare ]: gl.NEVER,
|
|
46
|
+
[ AlwaysCompare ]: gl.ALWAYS,
|
|
47
|
+
[ LessCompare ]: gl.LESS,
|
|
48
|
+
[ LessEqualCompare ]: gl.LEQUAL,
|
|
49
|
+
[ EqualCompare ]: gl.EQUAL,
|
|
50
|
+
[ GreaterEqualCompare ]: gl.GEQUAL,
|
|
51
|
+
[ GreaterCompare ]: gl.GREATER,
|
|
52
|
+
[ NotEqualCompare ]: gl.NOTEQUAL
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
filterFallback( f ) {
|
|
58
|
+
|
|
59
|
+
const { gl } = this;
|
|
60
|
+
|
|
61
|
+
if ( f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter ) {
|
|
62
|
+
|
|
63
|
+
return gl.NEAREST;
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return gl.LINEAR;
|
|
68
|
+
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
getGLTextureType( texture ) {
|
|
72
|
+
|
|
73
|
+
const { gl } = this;
|
|
74
|
+
|
|
75
|
+
let glTextureType;
|
|
76
|
+
|
|
77
|
+
if ( texture.isCubeTexture === true ) {
|
|
78
|
+
|
|
79
|
+
glTextureType = gl.TEXTURE_CUBE_MAP;
|
|
80
|
+
|
|
81
|
+
} else {
|
|
82
|
+
|
|
83
|
+
glTextureType = gl.TEXTURE_2D;
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return glTextureType;
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
getInternalFormat( internalFormatName, glFormat, glType, colorSpace, forceLinearTransfer = false ) {
|
|
93
|
+
|
|
94
|
+
const { gl, extensions } = this;
|
|
95
|
+
|
|
96
|
+
if ( internalFormatName !== null ) {
|
|
97
|
+
|
|
98
|
+
if ( gl[ internalFormatName ] !== undefined ) return gl[ internalFormatName ];
|
|
99
|
+
|
|
100
|
+
console.warn( 'THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'' );
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
let internalFormat = glFormat;
|
|
105
|
+
|
|
106
|
+
if ( glFormat === gl.RED ) {
|
|
107
|
+
|
|
108
|
+
if ( glType === gl.FLOAT ) internalFormat = gl.R32F;
|
|
109
|
+
if ( glType === gl.HALF_FLOAT ) internalFormat = gl.R16F;
|
|
110
|
+
if ( glType === gl.UNSIGNED_BYTE ) internalFormat = gl.R8;
|
|
111
|
+
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if ( glFormat === gl.RED_INTEGER ) {
|
|
115
|
+
|
|
116
|
+
if ( glType === gl.UNSIGNED_BYTE ) internalFormat = gl.R8UI;
|
|
117
|
+
if ( glType === gl.UNSIGNED_SHORT ) internalFormat = gl.R16UI;
|
|
118
|
+
if ( glType === gl.UNSIGNED_INT ) internalFormat = gl.R32UI;
|
|
119
|
+
if ( glType === gl.BYTE ) internalFormat = gl.R8I;
|
|
120
|
+
if ( glType === gl.SHORT ) internalFormat = gl.R16I;
|
|
121
|
+
if ( glType === gl.INT ) internalFormat = gl.R32I;
|
|
122
|
+
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if ( glFormat === gl.RG ) {
|
|
126
|
+
|
|
127
|
+
if ( glType === gl.FLOAT ) internalFormat = gl.RG32F;
|
|
128
|
+
if ( glType === gl.HALF_FLOAT ) internalFormat = gl.RG16F;
|
|
129
|
+
if ( glType === gl.UNSIGNED_BYTE ) internalFormat = gl.RG8;
|
|
130
|
+
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if ( glFormat === gl.RGBA ) {
|
|
134
|
+
|
|
135
|
+
if ( glType === gl.FLOAT ) internalFormat = gl.RGBA32F;
|
|
136
|
+
if ( glType === gl.HALF_FLOAT ) internalFormat = gl.RGBA16F;
|
|
137
|
+
if ( glType === gl.UNSIGNED_BYTE ) internalFormat = ( colorSpace === SRGBColorSpace && forceLinearTransfer === false ) ? gl.SRGB8_ALPHA8 : gl.RGBA8;
|
|
138
|
+
if ( glType === gl.UNSIGNED_SHORT_4_4_4_4 ) internalFormat = gl.RGBA4;
|
|
139
|
+
if ( glType === gl.UNSIGNED_SHORT_5_5_5_1 ) internalFormat = gl.RGB5_A1;
|
|
140
|
+
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if ( internalFormat === gl.R16F || internalFormat === gl.R32F ||
|
|
144
|
+
internalFormat === gl.RG16F || internalFormat === gl.RG32F ||
|
|
145
|
+
internalFormat === gl.RGBA16F || internalFormat === gl.RGBA32F ) {
|
|
146
|
+
|
|
147
|
+
extensions.get( 'EXT_color_buffer_float' );
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return internalFormat;
|
|
152
|
+
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
setTextureParameters( textureType, texture ) {
|
|
156
|
+
|
|
157
|
+
const { gl, extensions } = this;
|
|
158
|
+
|
|
159
|
+
gl.texParameteri( textureType, gl.TEXTURE_WRAP_S, wrappingToGL[ texture.wrapS ] );
|
|
160
|
+
gl.texParameteri( textureType, gl.TEXTURE_WRAP_T, wrappingToGL[ texture.wrapT ] );
|
|
161
|
+
|
|
162
|
+
if ( textureType === gl.TEXTURE_3D || textureType === gl.TEXTURE_2D_ARRAY ) {
|
|
163
|
+
|
|
164
|
+
gl.texParameteri( textureType, gl.TEXTURE_WRAP_R, wrappingToGL[ texture.wrapR ] );
|
|
165
|
+
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
gl.texParameteri( textureType, gl.TEXTURE_MAG_FILTER, filterToGL[ texture.magFilter ] );
|
|
169
|
+
gl.texParameteri( textureType, gl.TEXTURE_MIN_FILTER, filterToGL[ texture.minFilter ] );
|
|
170
|
+
|
|
171
|
+
if ( texture.compareFunction ) {
|
|
172
|
+
|
|
173
|
+
gl.texParameteri( textureType, gl.TEXTURE_COMPARE_MODE, gl.COMPARE_REF_TO_TEXTURE );
|
|
174
|
+
gl.texParameteri( textureType, gl.TEXTURE_COMPARE_FUNC, compareToGL[ texture.compareFunction ] );
|
|
175
|
+
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if ( extensions.has( 'EXT_texture_filter_anisotropic' ) === true ) {
|
|
179
|
+
|
|
180
|
+
//extension = extensions.get( 'EXT_texture_filter_anisotropic' );
|
|
181
|
+
|
|
182
|
+
if ( texture.magFilter === NearestFilter ) return;
|
|
183
|
+
if ( texture.minFilter !== NearestMipmapLinearFilter && texture.minFilter !== LinearMipmapLinearFilter ) return;
|
|
184
|
+
if ( texture.type === FloatType && extensions.has( 'OES_texture_float_linear' ) === false ) return; // verify extension for WebGL 1 and WebGL 2
|
|
185
|
+
|
|
186
|
+
if ( texture.anisotropy > 1 /*|| properties.get( texture ).__currentAnisotropy*/ ) {
|
|
187
|
+
|
|
188
|
+
//gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
|
|
189
|
+
//properties.get( texture ).__currentAnisotropy = texture.anisotropy;
|
|
190
|
+
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export default WebGLTextureUtils;
|