-
-
Notifications
You must be signed in to change notification settings - Fork 36.3k
Expand file tree
/
Copy pathRenderer.js
More file actions
3507 lines (2504 loc) · 92 KB
/
Renderer.js
File metadata and controls
3507 lines (2504 loc) · 92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import Animation from './Animation.js';
import RenderObjects from './RenderObjects.js';
import Attributes from './Attributes.js';
import Geometries from './Geometries.js';
import Info from './Info.js';
import Pipelines from './Pipelines.js';
import Bindings from './Bindings.js';
import RenderLists from './RenderLists.js';
import RenderContexts from './RenderContexts.js';
import Textures from './Textures.js';
import Background from './Background.js';
import Nodes from './nodes/Nodes.js';
import Color4 from './Color4.js';
import ClippingContext from './ClippingContext.js';
import QuadMesh from './QuadMesh.js';
import RenderBundles from './RenderBundles.js';
import NodeLibrary from './nodes/NodeLibrary.js';
import Lighting from './Lighting.js';
import XRManager from './XRManager.js';
import InspectorBase from './InspectorBase.js';
import CanvasTarget from './CanvasTarget.js';
import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
import { Scene } from '../../scenes/Scene.js';
import { ColorManagement } from '../../math/ColorManagement.js';
import { Frustum } from '../../math/Frustum.js';
import { FrustumArray } from '../../math/FrustumArray.js';
import { Matrix4 } from '../../math/Matrix4.js';
import { Vector2 } from '../../math/Vector2.js';
import { Vector4 } from '../../math/Vector4.js';
import { RenderTarget } from '../../core/RenderTarget.js';
import { DoubleSide, BackSide, FrontSide, SRGBColorSpace, NoToneMapping, LinearFilter, HalfFloatType, RGBAFormat, PCFShadowMap, VSMShadowMap } from '../../constants.js';
import { float, vec3, vec4, Fn } from '../../nodes/tsl/TSLCore.js';
import { reference } from '../../nodes/accessors/ReferenceNode.js';
import { highpModelNormalViewMatrix, highpModelViewMatrix } from '../../nodes/accessors/ModelNode.js';
import { context } from '../../nodes/core/ContextNode.js';
import { error, warn, warnOnce } from '../../utils.js';
const _scene = /*@__PURE__*/ new Scene();
const _drawingBufferSize = /*@__PURE__*/ new Vector2();
const _screen = /*@__PURE__*/ new Vector4();
const _frustum = /*@__PURE__*/ new Frustum();
const _frustumArray = /*@__PURE__*/ new FrustumArray();
const _projScreenMatrix = /*@__PURE__*/ new Matrix4();
const _vector4 = /*@__PURE__*/ new Vector4();
const _shadowSide = { [ FrontSide ]: BackSide, [ BackSide ]: FrontSide, [ DoubleSide ]: DoubleSide };
/**
* Base class for renderers.
*/
class Renderer {
/**
* Renderer options.
*
* @typedef {Object} Renderer~Options
* @property {boolean} [logarithmicDepthBuffer=false] - Whether logarithmic depth buffer is enabled or not.
* @property {boolean} [alpha=true] - Whether the default framebuffer (which represents the final contents of the canvas) should be transparent or opaque.
* @property {boolean} [depth=true] - Whether the default framebuffer should have a depth buffer or not.
* @property {boolean} [stencil=false] - Whether the default framebuffer should have a stencil buffer or not.
* @property {boolean} [antialias=false] - Whether MSAA as the default anti-aliasing should be enabled or not.
* @property {number} [samples=0] - When `antialias` is `true`, `4` samples are used by default. This parameter can set to any other integer value than 0
* to overwrite the default.
* @property {?Function} [getFallback=null] - This callback function can be used to provide a fallback backend, if the primary backend can't be targeted.
* @property {number} [outputBufferType=HalfFloatType] - Defines the type of output buffers. The default `HalfFloatType` is recommend for best
* quality. To save memory and bandwidth, `UnsignedByteType` might be used. This will reduce rendering quality though.
* @property {boolean} [multiview=false] - If set to `true`, the renderer will use multiview during WebXR rendering if supported.
*/
/**
* Constructs a new renderer.
*
* @param {Backend} backend - The backend the renderer is targeting (e.g. WebGPU or WebGL 2).
* @param {Renderer~Options} [parameters] - The configuration parameter.
*/
constructor( backend, parameters = {} ) {
/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isRenderer = true;
//
const {
logarithmicDepthBuffer = false,
alpha = true,
depth = true,
stencil = false,
antialias = false,
samples = 0,
getFallback = null,
outputBufferType = HalfFloatType,
multiview = false
} = parameters;
/**
* A reference to the current backend.
*
* @type {Backend}
*/
this.backend = backend;
/**
* Whether the renderer should automatically clear the current rendering target
* before execute a `render()` call. The target can be the canvas (default framebuffer)
* or the current bound render target (custom framebuffer).
*
* @type {boolean}
* @default true
*/
this.autoClear = true;
/**
* When `autoClear` is set to `true`, this property defines whether the renderer
* should clear the color buffer.
*
* @type {boolean}
* @default true
*/
this.autoClearColor = true;
/**
* When `autoClear` is set to `true`, this property defines whether the renderer
* should clear the depth buffer.
*
* @type {boolean}
* @default true
*/
this.autoClearDepth = true;
/**
* When `autoClear` is set to `true`, this property defines whether the renderer
* should clear the stencil buffer.
*
* @type {boolean}
* @default true
*/
this.autoClearStencil = true;
/**
* Whether the default framebuffer should be transparent or opaque.
*
* @type {boolean}
* @default true
*/
this.alpha = alpha;
/**
* Whether logarithmic depth buffer is enabled or not.
*
* @type {boolean}
* @default false
*/
this.logarithmicDepthBuffer = logarithmicDepthBuffer;
/**
* Defines the output color space of the renderer.
*
* @type {string}
* @default SRGBColorSpace
*/
this.outputColorSpace = SRGBColorSpace;
/**
* Defines the tone mapping of the renderer.
*
* @type {number}
* @default NoToneMapping
*/
this.toneMapping = NoToneMapping;
/**
* Defines the tone mapping exposure.
*
* @type {number}
* @default 1
*/
this.toneMappingExposure = 1.0;
/**
* Whether the renderer should sort its render lists or not.
*
* Note: Sorting is used to attempt to properly render objects that have some degree of transparency.
* By definition, sorting objects may not work in all cases. Depending on the needs of application,
* it may be necessary to turn off sorting and use other methods to deal with transparency rendering
* e.g. manually determining each object's rendering order.
*
* @type {boolean}
* @default true
*/
this.sortObjects = true;
/**
* Whether the default framebuffer should have a depth buffer or not.
*
* @type {boolean}
* @default true
*/
this.depth = depth;
/**
* Whether the default framebuffer should have a stencil buffer or not.
*
* @type {boolean}
* @default false
*/
this.stencil = stencil;
/**
* Holds a series of statistical information about the GPU memory
* and the rendering process. Useful for debugging and monitoring.
*
* @type {Info}
*/
this.info = new Info();
/**
* A global context node that stores override nodes for specific transformations or calculations.
* These nodes can be used to replace default behavior in the rendering pipeline.
*
* @type {ContextNode}
* @property {Object} value - The context value object.
*/
this.contextNode = context();
/**
* The node library defines how certain library objects like materials, lights
* or tone mapping functions are mapped to node types. This is required since
* although instances of classes like `MeshBasicMaterial` or `PointLight` can
* be part of the scene graph, they are internally represented as nodes for
* further processing.
*
* @type {NodeLibrary}
*/
this.library = new NodeLibrary();
/**
* A map-like data structure for managing lights.
*
* @type {Lighting}
*/
this.lighting = new Lighting();
// internals
/**
* The number of MSAA samples.
*
* @private
* @type {number}
* @default 0
*/
this._samples = samples || ( antialias === true ) ? 4 : 0;
/**
* OnCanvasTargetResize callback function.
*
* @private
* @type {Function}
*/
this._onCanvasTargetResize = this._onCanvasTargetResize.bind( this );
/**
* The canvas target for rendering.
*
* @private
* @type {CanvasTarget}
*/
this._canvasTarget = new CanvasTarget( backend.getDomElement() );
this._canvasTarget.addEventListener( 'resize', this._onCanvasTargetResize );
this._canvasTarget.isDefaultCanvasTarget = true;
/**
* The inspector provides information about the internal renderer state.
*
* @private
* @type {InspectorBase}
*/
this._inspector = new InspectorBase();
this._inspector.setRenderer( this );
/**
* This callback function can be used to provide a fallback backend, if the primary backend can't be targeted.
*
* @private
* @type {?Function}
*/
this._getFallback = getFallback;
/**
* A reference to a renderer module for managing shader attributes.
*
* @private
* @type {?Attributes}
* @default null
*/
this._attributes = null;
/**
* A reference to a renderer module for managing geometries.
*
* @private
* @type {?Geometries}
* @default null
*/
this._geometries = null;
/**
* A reference to a renderer module for managing node related logic.
*
* @private
* @type {?Nodes}
* @default null
*/
this._nodes = null;
/**
* A reference to a renderer module for managing the internal animation loop.
*
* @private
* @type {?Animation}
* @default null
*/
this._animation = null;
/**
* A reference to a renderer module for managing shader program bindings.
*
* @private
* @type {?Bindings}
* @default null
*/
this._bindings = null;
/**
* A reference to a renderer module for managing render objects.
*
* @private
* @type {?RenderObjects}
* @default null
*/
this._objects = null;
/**
* A reference to a renderer module for managing render and compute pipelines.
*
* @private
* @type {?Pipelines}
* @default null
*/
this._pipelines = null;
/**
* A reference to a renderer module for managing render bundles.
*
* @private
* @type {?RenderBundles}
* @default null
*/
this._bundles = null;
/**
* A reference to a renderer module for managing render lists.
*
* @private
* @type {?RenderLists}
* @default null
*/
this._renderLists = null;
/**
* A reference to a renderer module for managing render contexts.
*
* @private
* @type {?RenderContexts}
* @default null
*/
this._renderContexts = null;
/**
* A reference to a renderer module for managing textures.
*
* @private
* @type {?Textures}
* @default null
*/
this._textures = null;
/**
* A reference to a renderer module for backgrounds.
*
* @private
* @type {?Background}
* @default null
*/
this._background = null;
/**
* This fullscreen quad is used for internal render passes
* like the tone mapping and color space output pass.
*
* @private
* @type {QuadMesh}
*/
this._quad = new QuadMesh( new NodeMaterial() );
this._quad.name = 'Output Color Transform';
this._quad.material.name = 'outputColorTransform';
/**
* A reference to the current render context.
*
* @private
* @type {?RenderContext}
* @default null
*/
this._currentRenderContext = null;
/**
* A custom sort function for the opaque render list.
*
* @private
* @type {?Function}
* @default null
*/
this._opaqueSort = null;
/**
* A custom sort function for the transparent render list.
*
* @private
* @type {?Function}
* @default null
*/
this._transparentSort = null;
/**
* The framebuffer target.
*
* @private
* @type {?RenderTarget}
* @default null
*/
this._frameBufferTarget = null;
const alphaClear = this.alpha === true ? 0 : 1;
/**
* The clear color value.
*
* @private
* @type {Color4}
*/
this._clearColor = new Color4( 0, 0, 0, alphaClear );
/**
* The clear depth value.
*
* @private
* @type {number}
* @default 1
*/
this._clearDepth = 1;
/**
* The clear stencil value.
*
* @private
* @type {number}
* @default 0
*/
this._clearStencil = 0;
/**
* The current render target.
*
* @private
* @type {?RenderTarget}
* @default null
*/
this._renderTarget = null;
/**
* The active cube face.
*
* @private
* @type {number}
* @default 0
*/
this._activeCubeFace = 0;
/**
* The active mipmap level.
*
* @private
* @type {number}
* @default 0
*/
this._activeMipmapLevel = 0;
/**
* The current output render target.
*
* @private
* @type {?RenderTarget}
* @default null
*/
this._outputRenderTarget = null;
/**
* The MRT setting.
*
* @private
* @type {?MRTNode}
* @default null
*/
this._mrt = null;
/**
* This function defines how a render object is going
* to be rendered.
*
* @private
* @type {?Function}
* @default null
*/
this._renderObjectFunction = null;
/**
* Used to keep track of the current render object function.
*
* @private
* @type {?Function}
* @default null
*/
this._currentRenderObjectFunction = null;
/**
* Used to keep track of the current render bundle.
*
* @private
* @type {?RenderBundle}
* @default null
*/
this._currentRenderBundle = null;
/**
* Next to `_renderObjectFunction()`, this function provides another hook
* for influencing the render process of a render object. It is meant for internal
* use and only relevant for `compileAsync()` right now. Instead of using
* the default logic of `_renderObjectDirect()` which actually draws the render object,
* a different function might be used which performs no draw but just the node
* and pipeline updates.
*
* @private
* @type {Function}
*/
this._handleObjectFunction = this._renderObjectDirect;
/**
* Indicates whether the device has been lost or not. In WebGL terms, the device
* lost is considered as a context lost. When this is set to `true`, rendering
* isn't possible anymore.
*
* @private
* @type {boolean}
* @default false
*/
this._isDeviceLost = false;
/**
* A callback function that defines what should happen when a device/context lost occurs.
*
* @type {Function}
*/
this.onDeviceLost = this._onDeviceLost;
/**
* Defines the type of output buffers. The default `HalfFloatType` is recommend for
* best quality. To save memory and bandwidth, `UnsignedByteType` might be used.
* This will reduce rendering quality though.
*
* @private
* @type {number}
* @default HalfFloatType
*/
this._outputBufferType = outputBufferType;
/**
* A cache for shadow nodes per material
*
* @private
* @type {WeakMap<Material, Object>}
*/
this._cacheShadowNodes = new WeakMap();
/**
* Whether the renderer has been initialized or not.
*
* @private
* @type {boolean}
* @default false
*/
this._initialized = false;
/**
* The call depth of the renderer. Counts the number of
* nested render calls.
*
* @private
* @type {number}
* @default - 1
*/
this._callDepth = - 1;
/**
* A reference to the promise which initializes the renderer.
*
* @private
* @type {?Promise<this>}
* @default null
*/
this._initPromise = null;
/**
* An array of compilation promises which are used in `compileAsync()`.
*
* @private
* @type {?Array<Promise>}
* @default null
*/
this._compilationPromises = null;
/**
* Whether the renderer should render transparent render objects or not.
*
* @type {boolean}
* @default true
*/
this.transparent = true;
/**
* Whether the renderer should render opaque render objects or not.
*
* @type {boolean}
* @default true
*/
this.opaque = true;
/**
* Shadow map configuration
* @typedef {Object} ShadowMapConfig
* @property {boolean} enabled - Whether to globally enable shadows or not.
* @property {boolean} transmitted - Whether to enable light transmission through non-opaque materials.
* @property {number} type - The shadow map type.
*/
/**
* The renderer's shadow configuration.
*
* @type {ShadowMapConfig}
*/
this.shadowMap = {
enabled: false,
transmitted: false,
type: PCFShadowMap
};
/**
* XR configuration.
* @typedef {Object} XRConfig
* @property {boolean} enabled - Whether to globally enable XR or not.
*/
/**
* The renderer's XR manager.
*
* @type {XRManager}
*/
this.xr = new XRManager( this, multiview );
/**
* Debug configuration.
* @typedef {Object} DebugConfig
* @property {boolean} checkShaderErrors - Whether shader errors should be checked or not.
* @property {?Function} onShaderError - A callback function that is executed when a shader error happens. Only supported with WebGL 2 right now.
* @property {Function} getShaderAsync - Allows the get the raw shader code for the given scene, camera and 3D object.
*/
/**
* The renderer's debug configuration.
*
* @type {DebugConfig}
*/
this.debug = {
checkShaderErrors: true,
onShaderError: null,
getShaderAsync: async ( scene, camera, object ) => {
await this.compileAsync( scene, camera );
const renderList = this._renderLists.get( scene, camera );
const renderContext = this._renderContexts.get( this._renderTarget, this._mrt );
const material = scene.overrideMaterial || object.material;
const renderObject = this._objects.get( object, material, scene, camera, renderList.lightsNode, renderContext, renderContext.clippingContext );
const { fragmentShader, vertexShader } = renderObject.getNodeBuilderState();
return { fragmentShader, vertexShader };
}
};
}
/**
* Initializes the renderer so it is ready for usage.
*
* @async
* @return {Promise<this>} A Promise that resolves when the renderer has been initialized.
*/
async init() {
if ( this._initPromise !== null ) {
return this._initPromise;
}
this._initPromise = new Promise( async ( resolve, reject ) => {
let backend = this.backend;
try {
await backend.init( this );
} catch ( error ) {
if ( this._getFallback !== null ) {
// try the fallback
try {
this.backend = backend = this._getFallback( error );
await backend.init( this );
} catch ( error ) {
reject( error );
return;
}
} else {
reject( error );
return;
}
}
this._nodes = new Nodes( this, backend );
this._animation = new Animation( this, this._nodes, this.info );
this._attributes = new Attributes( backend );
this._background = new Background( this, this._nodes );
this._geometries = new Geometries( this._attributes, this.info );
this._textures = new Textures( this, backend, this.info );
this._pipelines = new Pipelines( backend, this._nodes );
this._bindings = new Bindings( backend, this._nodes, this._textures, this._attributes, this._pipelines, this.info );
this._objects = new RenderObjects( this, this._nodes, this._geometries, this._pipelines, this._bindings, this.info );
this._renderLists = new RenderLists( this.lighting );
this._bundles = new RenderBundles();
this._renderContexts = new RenderContexts();
//
this._animation.start();
this._initialized = true;
//
this._inspector.init();
//
resolve( this );
} );
return this._initPromise;
}
/**
* A reference to the canvas element the renderer is drawing to.
* This value of this property will automatically be created by
* the renderer.
*
* @type {HTMLCanvasElement|OffscreenCanvas}
*/
get domElement() {
return this._canvasTarget.domElement;
}
/**
* The coordinate system of the renderer. The value of this property
* depends on the selected backend. Either `THREE.WebGLCoordinateSystem` or
* `THREE.WebGPUCoordinateSystem`.
*
* @readonly
* @type {number}
*/
get coordinateSystem() {
return this.backend.coordinateSystem;
}
/**
* Compiles all materials in the given scene. This can be useful to avoid a
* phenomenon which is called "shader compilation stutter", which occurs when
* rendering an object with a new shader for the first time.
*
* If you want to add a 3D object to an existing scene, use the third optional
* parameter for applying the target scene. Note that the (target) scene's lighting
* and environment must be configured before calling this method.
*
* @async
* @param {Object3D} scene - The scene or 3D object to precompile.
* @param {Camera} camera - The camera that is used to render the scene.
* @param {?Scene} targetScene - If the first argument is a 3D object, this parameter must represent the scene the 3D object is going to be added.
* @return {Promise} A Promise that resolves when the compile has been finished.
*/
async compileAsync( scene, camera, targetScene = null ) {
if ( this._isDeviceLost === true ) return;
if ( this._initialized === false ) await this.init();
// preserve render tree
const nodeFrame = this._nodes.nodeFrame;
const previousRenderId = nodeFrame.renderId;
const previousRenderContext = this._currentRenderContext;
const previousRenderObjectFunction = this._currentRenderObjectFunction;
const previousHandleObjectFunction = this._handleObjectFunction;
const previousCompilationPromises = this._compilationPromises;
//
const sceneRef = ( scene.isScene === true ) ? scene : _scene;
if ( targetScene === null ) targetScene = scene;
const renderTarget = this._renderTarget;
const renderContext = this._renderContexts.get( renderTarget, this._mrt );
const activeMipmapLevel = this._activeMipmapLevel;
const compilationPromises = [];
this._currentRenderContext = renderContext;
this._currentRenderObjectFunction = this.renderObject;
this._handleObjectFunction = this._createObjectPipeline;
this._compilationPromises = compilationPromises;
nodeFrame.renderId ++;
//
nodeFrame.update();
//
renderContext.depth = this.depth;
renderContext.stencil = this.stencil;
if ( ! renderContext.clippingContext ) renderContext.clippingContext = new ClippingContext();
renderContext.clippingContext.updateGlobal( sceneRef, camera );
//
sceneRef.onBeforeRender( this, scene, camera, renderTarget );
//
const renderList = this._renderLists.get( scene, camera );
renderList.begin();
this._projectObject( scene, camera, 0, renderList, renderContext.clippingContext );
// include lights from target scene
if ( targetScene !== scene ) {
targetScene.traverseVisible( function ( object ) {
if ( object.isLight && object.layers.test( camera.layers ) ) {
renderList.pushLight( object );
}
} );
}
renderList.finish();
//
if ( renderTarget !== null ) {
this._textures.updateRenderTarget( renderTarget, activeMipmapLevel );
const renderTargetData = this._textures.get( renderTarget );
renderContext.textures = renderTargetData.textures;
renderContext.depthTexture = renderTargetData.depthTexture;
} else {
renderContext.textures = null;
renderContext.depthTexture = null;
}
//
if ( targetScene !== scene ) {
this._background.update( targetScene, renderList, renderContext );
} else {
this._background.update( sceneRef, renderList, renderContext );
}
// process render lists
const opaqueObjects = renderList.opaque;
const transparentObjects = renderList.transparent;
const transparentDoublePassObjects = renderList.transparentDoublePass;
const lightsNode = renderList.lightsNode;
if ( this.opaque === true && opaqueObjects.length > 0 ) this._renderObjects( opaqueObjects, camera, sceneRef, lightsNode );
if ( this.transparent === true && transparentObjects.length > 0 ) this._renderTransparents( transparentObjects, transparentDoublePassObjects, camera, sceneRef, lightsNode );
// restore render tree
nodeFrame.renderId = previousRenderId;
this._currentRenderContext = previousRenderContext;
this._currentRenderObjectFunction = previousRenderObjectFunction;
this._handleObjectFunction = previousHandleObjectFunction;
this._compilationPromises = previousCompilationPromises;
// wait for all promises setup by backends awaiting compilation/linking/pipeline creation to complete
await Promise.all( compilationPromises );
}
/**
* Renders the scene in an async fashion.
*
* @async
* @deprecated
* @param {Object3D} scene - The scene or 3D object to render.
* @param {Camera} camera - The camera.
* @return {Promise} A Promise that resolves when the render has been finished.
*/
async renderAsync( scene, camera ) {
warnOnce( 'Renderer: "renderAsync()" has been deprecated. Use "render()" and "await renderer.init();" when creating the renderer.' ); // @deprecated r181
await this.init();
this.render( scene, camera );
}