Renderer.js 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793
  1. import Animation from './Animation.js';
  2. import RenderObjects from './RenderObjects.js';
  3. import Attributes from './Attributes.js';
  4. import Geometries from './Geometries.js';
  5. import Info from './Info.js';
  6. import Pipelines from './Pipelines.js';
  7. import Bindings from './Bindings.js';
  8. import RenderLists from './RenderLists.js';
  9. import RenderContexts from './RenderContexts.js';
  10. import Textures from './Textures.js';
  11. import Background from './Background.js';
  12. import Nodes from './nodes/Nodes.js';
  13. import Color4 from './Color4.js';
  14. import ClippingContext from './ClippingContext.js';
  15. import QuadMesh from './QuadMesh.js';
  16. import RenderBundles from './RenderBundles.js';
  17. import NodeLibrary from './nodes/NodeLibrary.js';
  18. import Lighting from './Lighting.js';
  19. import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
  20. import { Scene } from '../../scenes/Scene.js';
  21. import { Frustum } from '../../math/Frustum.js';
  22. import { Matrix4 } from '../../math/Matrix4.js';
  23. import { Vector2 } from '../../math/Vector2.js';
  24. import { Vector4 } from '../../math/Vector4.js';
  25. import { RenderTarget } from '../../core/RenderTarget.js';
  26. import { DoubleSide, BackSide, FrontSide, SRGBColorSpace, NoToneMapping, LinearFilter, LinearSRGBColorSpace, HalfFloatType, RGBAFormat, PCFShadowMap } from '../../constants.js';
  27. const _scene = /*@__PURE__*/ new Scene();
  28. const _drawingBufferSize = /*@__PURE__*/ new Vector2();
  29. const _screen = /*@__PURE__*/ new Vector4();
  30. const _frustum = /*@__PURE__*/ new Frustum();
  31. const _projScreenMatrix = /*@__PURE__*/ new Matrix4();
  32. const _vector4 = /*@__PURE__*/ new Vector4();
  33. class Renderer {
  34. constructor( backend, parameters = {} ) {
  35. this.isRenderer = true;
  36. //
  37. const {
  38. logarithmicDepthBuffer = false,
  39. alpha = true,
  40. depth = true,
  41. stencil = false,
  42. antialias = false,
  43. samples = 0,
  44. getFallback = null
  45. } = parameters;
  46. // public
  47. this.domElement = backend.getDomElement();
  48. this.backend = backend;
  49. this.samples = samples || ( antialias === true ) ? 4 : 0;
  50. this.autoClear = true;
  51. this.autoClearColor = true;
  52. this.autoClearDepth = true;
  53. this.autoClearStencil = true;
  54. this.alpha = alpha;
  55. this.logarithmicDepthBuffer = logarithmicDepthBuffer;
  56. this.outputColorSpace = SRGBColorSpace;
  57. this.toneMapping = NoToneMapping;
  58. this.toneMappingExposure = 1.0;
  59. this.sortObjects = true;
  60. this.depth = depth;
  61. this.stencil = stencil;
  62. this.info = new Info();
  63. this.nodes = {
  64. modelViewMatrix: null,
  65. modelNormalViewMatrix: null
  66. };
  67. this.library = new NodeLibrary();
  68. this.lighting = new Lighting();
  69. // internals
  70. this._getFallback = getFallback;
  71. this._pixelRatio = 1;
  72. this._width = this.domElement.width;
  73. this._height = this.domElement.height;
  74. this._viewport = new Vector4( 0, 0, this._width, this._height );
  75. this._scissor = new Vector4( 0, 0, this._width, this._height );
  76. this._scissorTest = false;
  77. this._attributes = null;
  78. this._geometries = null;
  79. this._nodes = null;
  80. this._animation = null;
  81. this._bindings = null;
  82. this._objects = null;
  83. this._pipelines = null;
  84. this._bundles = null;
  85. this._renderLists = null;
  86. this._renderContexts = null;
  87. this._textures = null;
  88. this._background = null;
  89. this._quad = new QuadMesh( new NodeMaterial() );
  90. this._quad.material.type = 'Renderer_output';
  91. this._currentRenderContext = null;
  92. this._opaqueSort = null;
  93. this._transparentSort = null;
  94. this._frameBufferTarget = null;
  95. const alphaClear = this.alpha === true ? 0 : 1;
  96. this._clearColor = new Color4( 0, 0, 0, alphaClear );
  97. this._clearDepth = 1;
  98. this._clearStencil = 0;
  99. this._renderTarget = null;
  100. this._activeCubeFace = 0;
  101. this._activeMipmapLevel = 0;
  102. this._mrt = null;
  103. this._renderObjectFunction = null;
  104. this._currentRenderObjectFunction = null;
  105. this._currentRenderBundle = null;
  106. this._handleObjectFunction = this._renderObjectDirect;
  107. this._isDeviceLost = false;
  108. this.onDeviceLost = this._onDeviceLost;
  109. this._initialized = false;
  110. this._initPromise = null;
  111. this._compilationPromises = null;
  112. this.transparent = true;
  113. this.opaque = true;
  114. this.shadowMap = {
  115. enabled: false,
  116. type: PCFShadowMap
  117. };
  118. this.xr = {
  119. enabled: false
  120. };
  121. this.debug = {
  122. checkShaderErrors: true,
  123. onShaderError: null,
  124. getShaderAsync: async ( scene, camera, object ) => {
  125. await this.compileAsync( scene, camera );
  126. const renderList = this._renderLists.get( scene, camera );
  127. const renderContext = this._renderContexts.get( scene, camera, this._renderTarget );
  128. const material = scene.overrideMaterial || object.material;
  129. const renderObject = this._objects.get( object, material, scene, camera, renderList.lightsNode, renderContext, renderContext.clippingContext );
  130. const { fragmentShader, vertexShader } = renderObject.getNodeBuilderState();
  131. return { fragmentShader, vertexShader };
  132. }
  133. };
  134. }
  135. async init() {
  136. if ( this._initialized ) {
  137. throw new Error( 'Renderer: Backend has already been initialized.' );
  138. }
  139. if ( this._initPromise !== null ) {
  140. return this._initPromise;
  141. }
  142. this._initPromise = new Promise( async ( resolve, reject ) => {
  143. let backend = this.backend;
  144. try {
  145. await backend.init( this );
  146. } catch ( error ) {
  147. if ( this._getFallback !== null ) {
  148. // try the fallback
  149. try {
  150. this.backend = backend = this._getFallback( error );
  151. await backend.init( this );
  152. } catch ( error ) {
  153. reject( error );
  154. return;
  155. }
  156. } else {
  157. reject( error );
  158. return;
  159. }
  160. }
  161. this._nodes = new Nodes( this, backend );
  162. this._animation = new Animation( this._nodes, this.info );
  163. this._attributes = new Attributes( backend );
  164. this._background = new Background( this, this._nodes );
  165. this._geometries = new Geometries( this._attributes, this.info );
  166. this._textures = new Textures( this, backend, this.info );
  167. this._pipelines = new Pipelines( backend, this._nodes );
  168. this._bindings = new Bindings( backend, this._nodes, this._textures, this._attributes, this._pipelines, this.info );
  169. this._objects = new RenderObjects( this, this._nodes, this._geometries, this._pipelines, this._bindings, this.info );
  170. this._renderLists = new RenderLists( this.lighting );
  171. this._bundles = new RenderBundles();
  172. this._renderContexts = new RenderContexts();
  173. //
  174. this._animation.start();
  175. this._initialized = true;
  176. resolve();
  177. } );
  178. return this._initPromise;
  179. }
  180. get coordinateSystem() {
  181. return this.backend.coordinateSystem;
  182. }
  183. async compileAsync( scene, camera, targetScene = null ) {
  184. if ( this._isDeviceLost === true ) return;
  185. if ( this._initialized === false ) await this.init();
  186. // preserve render tree
  187. const nodeFrame = this._nodes.nodeFrame;
  188. const previousRenderId = nodeFrame.renderId;
  189. const previousRenderContext = this._currentRenderContext;
  190. const previousRenderObjectFunction = this._currentRenderObjectFunction;
  191. const previousCompilationPromises = this._compilationPromises;
  192. //
  193. const sceneRef = ( scene.isScene === true ) ? scene : _scene;
  194. if ( targetScene === null ) targetScene = scene;
  195. const renderTarget = this._renderTarget;
  196. const renderContext = this._renderContexts.get( targetScene, camera, renderTarget );
  197. const activeMipmapLevel = this._activeMipmapLevel;
  198. const compilationPromises = [];
  199. this._currentRenderContext = renderContext;
  200. this._currentRenderObjectFunction = this.renderObject;
  201. this._handleObjectFunction = this._createObjectPipeline;
  202. this._compilationPromises = compilationPromises;
  203. nodeFrame.renderId ++;
  204. //
  205. nodeFrame.update();
  206. //
  207. renderContext.depth = this.depth;
  208. renderContext.stencil = this.stencil;
  209. if ( ! renderContext.clippingContext ) renderContext.clippingContext = new ClippingContext();
  210. renderContext.clippingContext.updateGlobal( sceneRef, camera );
  211. //
  212. sceneRef.onBeforeRender( this, scene, camera, renderTarget );
  213. //
  214. const renderList = this._renderLists.get( scene, camera );
  215. renderList.begin();
  216. this._projectObject( scene, camera, 0, renderList, renderContext.clippingContext );
  217. // include lights from target scene
  218. if ( targetScene !== scene ) {
  219. targetScene.traverseVisible( function ( object ) {
  220. if ( object.isLight && object.layers.test( camera.layers ) ) {
  221. renderList.pushLight( object );
  222. }
  223. } );
  224. }
  225. renderList.finish();
  226. //
  227. if ( renderTarget !== null ) {
  228. this._textures.updateRenderTarget( renderTarget, activeMipmapLevel );
  229. const renderTargetData = this._textures.get( renderTarget );
  230. renderContext.textures = renderTargetData.textures;
  231. renderContext.depthTexture = renderTargetData.depthTexture;
  232. } else {
  233. renderContext.textures = null;
  234. renderContext.depthTexture = null;
  235. }
  236. //
  237. this._nodes.updateScene( sceneRef );
  238. //
  239. this._background.update( sceneRef, renderList, renderContext );
  240. // process render lists
  241. const opaqueObjects = renderList.opaque;
  242. const transparentObjects = renderList.transparent;
  243. const transparentDoublePassObjects = renderList.transparentDoublePass;
  244. const lightsNode = renderList.lightsNode;
  245. if ( this.opaque === true && opaqueObjects.length > 0 ) this._renderObjects( opaqueObjects, camera, sceneRef, lightsNode );
  246. if ( this.transparent === true && transparentObjects.length > 0 ) this._renderTransparents( transparentObjects, transparentDoublePassObjects, camera, sceneRef, lightsNode );
  247. // restore render tree
  248. nodeFrame.renderId = previousRenderId;
  249. this._currentRenderContext = previousRenderContext;
  250. this._currentRenderObjectFunction = previousRenderObjectFunction;
  251. this._compilationPromises = previousCompilationPromises;
  252. this._handleObjectFunction = this._renderObjectDirect;
  253. // wait for all promises setup by backends awaiting compilation/linking/pipeline creation to complete
  254. await Promise.all( compilationPromises );
  255. }
  256. async renderAsync( scene, camera ) {
  257. if ( this._initialized === false ) await this.init();
  258. const renderContext = this._renderScene( scene, camera );
  259. await this.backend.resolveTimestampAsync( renderContext, 'render' );
  260. }
  261. async waitForGPU() {
  262. await this.backend.waitForGPU();
  263. }
  264. setMRT( mrt ) {
  265. this._mrt = mrt;
  266. return this;
  267. }
  268. getMRT() {
  269. return this._mrt;
  270. }
  271. _onDeviceLost( info ) {
  272. let errorMessage = `THREE.WebGPURenderer: ${info.api} Device Lost:\n\nMessage: ${info.message}`;
  273. if ( info.reason ) {
  274. errorMessage += `\nReason: ${info.reason}`;
  275. }
  276. console.error( errorMessage );
  277. this._isDeviceLost = true;
  278. }
  279. _renderBundle( bundle, sceneRef, lightsNode ) {
  280. const { bundleGroup, camera, renderList } = bundle;
  281. const renderContext = this._currentRenderContext;
  282. //
  283. const renderBundle = this._bundles.get( bundleGroup, camera );
  284. const renderBundleData = this.backend.get( renderBundle );
  285. if ( renderBundleData.renderContexts === undefined ) renderBundleData.renderContexts = new Set();
  286. //
  287. const needsUpdate = bundleGroup.version !== renderBundleData.version;
  288. const renderBundleNeedsUpdate = renderBundleData.renderContexts.has( renderContext ) === false || needsUpdate;
  289. renderBundleData.renderContexts.add( renderContext );
  290. if ( renderBundleNeedsUpdate ) {
  291. this.backend.beginBundle( renderContext );
  292. if ( renderBundleData.renderObjects === undefined || needsUpdate ) {
  293. renderBundleData.renderObjects = [];
  294. }
  295. this._currentRenderBundle = renderBundle;
  296. const opaqueObjects = renderList.opaque;
  297. if ( this.opaque === true && opaqueObjects.length > 0 ) this._renderObjects( opaqueObjects, camera, sceneRef, lightsNode );
  298. this._currentRenderBundle = null;
  299. //
  300. this.backend.finishBundle( renderContext, renderBundle );
  301. renderBundleData.version = bundleGroup.version;
  302. } else {
  303. const { renderObjects } = renderBundleData;
  304. for ( let i = 0, l = renderObjects.length; i < l; i ++ ) {
  305. const renderObject = renderObjects[ i ];
  306. if ( this._nodes.needsRefresh( renderObject ) ) {
  307. this._nodes.updateBefore( renderObject );
  308. this._nodes.updateForRender( renderObject );
  309. this._bindings.updateForRender( renderObject );
  310. this._nodes.updateAfter( renderObject );
  311. }
  312. }
  313. }
  314. this.backend.addBundle( renderContext, renderBundle );
  315. }
  316. render( scene, camera ) {
  317. if ( this._initialized === false ) {
  318. console.warn( 'THREE.Renderer: .render() called before the backend is initialized. Try using .renderAsync() instead.' );
  319. return this.renderAsync( scene, camera );
  320. }
  321. this._renderScene( scene, camera );
  322. }
  323. _getFrameBufferTarget() {
  324. const { currentToneMapping, currentColorSpace } = this;
  325. const useToneMapping = currentToneMapping !== NoToneMapping;
  326. const useColorSpace = currentColorSpace !== LinearSRGBColorSpace;
  327. if ( useToneMapping === false && useColorSpace === false ) return null;
  328. const { width, height } = this.getDrawingBufferSize( _drawingBufferSize );
  329. const { depth, stencil } = this;
  330. let frameBufferTarget = this._frameBufferTarget;
  331. if ( frameBufferTarget === null ) {
  332. frameBufferTarget = new RenderTarget( width, height, {
  333. depthBuffer: depth,
  334. stencilBuffer: stencil,
  335. type: HalfFloatType, // FloatType
  336. format: RGBAFormat,
  337. colorSpace: LinearSRGBColorSpace,
  338. generateMipmaps: false,
  339. minFilter: LinearFilter,
  340. magFilter: LinearFilter,
  341. samples: this.samples
  342. } );
  343. frameBufferTarget.isPostProcessingRenderTarget = true;
  344. this._frameBufferTarget = frameBufferTarget;
  345. }
  346. frameBufferTarget.depthBuffer = depth;
  347. frameBufferTarget.stencilBuffer = stencil;
  348. frameBufferTarget.setSize( width, height );
  349. frameBufferTarget.viewport.copy( this._viewport );
  350. frameBufferTarget.scissor.copy( this._scissor );
  351. frameBufferTarget.viewport.multiplyScalar( this._pixelRatio );
  352. frameBufferTarget.scissor.multiplyScalar( this._pixelRatio );
  353. frameBufferTarget.scissorTest = this._scissorTest;
  354. return frameBufferTarget;
  355. }
  356. _renderScene( scene, camera, useFrameBufferTarget = true ) {
  357. if ( this._isDeviceLost === true ) return;
  358. const frameBufferTarget = useFrameBufferTarget ? this._getFrameBufferTarget() : null;
  359. // preserve render tree
  360. const nodeFrame = this._nodes.nodeFrame;
  361. const previousRenderId = nodeFrame.renderId;
  362. const previousRenderContext = this._currentRenderContext;
  363. const previousRenderObjectFunction = this._currentRenderObjectFunction;
  364. //
  365. const sceneRef = ( scene.isScene === true ) ? scene : _scene;
  366. const outputRenderTarget = this._renderTarget;
  367. const activeCubeFace = this._activeCubeFace;
  368. const activeMipmapLevel = this._activeMipmapLevel;
  369. //
  370. let renderTarget;
  371. if ( frameBufferTarget !== null ) {
  372. renderTarget = frameBufferTarget;
  373. this.setRenderTarget( renderTarget );
  374. } else {
  375. renderTarget = outputRenderTarget;
  376. }
  377. //
  378. const renderContext = this._renderContexts.get( scene, camera, renderTarget );
  379. this._currentRenderContext = renderContext;
  380. this._currentRenderObjectFunction = this._renderObjectFunction || this.renderObject;
  381. //
  382. this.info.calls ++;
  383. this.info.render.calls ++;
  384. this.info.render.frameCalls ++;
  385. nodeFrame.renderId = this.info.calls;
  386. //
  387. const coordinateSystem = this.coordinateSystem;
  388. if ( camera.coordinateSystem !== coordinateSystem ) {
  389. camera.coordinateSystem = coordinateSystem;
  390. camera.updateProjectionMatrix();
  391. }
  392. //
  393. if ( scene.matrixWorldAutoUpdate === true ) scene.updateMatrixWorld();
  394. if ( camera.parent === null && camera.matrixWorldAutoUpdate === true ) camera.updateMatrixWorld();
  395. //
  396. let viewport = this._viewport;
  397. let scissor = this._scissor;
  398. let pixelRatio = this._pixelRatio;
  399. if ( renderTarget !== null ) {
  400. viewport = renderTarget.viewport;
  401. scissor = renderTarget.scissor;
  402. pixelRatio = 1;
  403. }
  404. this.getDrawingBufferSize( _drawingBufferSize );
  405. _screen.set( 0, 0, _drawingBufferSize.width, _drawingBufferSize.height );
  406. const minDepth = ( viewport.minDepth === undefined ) ? 0 : viewport.minDepth;
  407. const maxDepth = ( viewport.maxDepth === undefined ) ? 1 : viewport.maxDepth;
  408. renderContext.viewportValue.copy( viewport ).multiplyScalar( pixelRatio ).floor();
  409. renderContext.viewportValue.width >>= activeMipmapLevel;
  410. renderContext.viewportValue.height >>= activeMipmapLevel;
  411. renderContext.viewportValue.minDepth = minDepth;
  412. renderContext.viewportValue.maxDepth = maxDepth;
  413. renderContext.viewport = renderContext.viewportValue.equals( _screen ) === false;
  414. renderContext.scissorValue.copy( scissor ).multiplyScalar( pixelRatio ).floor();
  415. renderContext.scissor = this._scissorTest && renderContext.scissorValue.equals( _screen ) === false;
  416. renderContext.scissorValue.width >>= activeMipmapLevel;
  417. renderContext.scissorValue.height >>= activeMipmapLevel;
  418. if ( ! renderContext.clippingContext ) renderContext.clippingContext = new ClippingContext();
  419. renderContext.clippingContext.updateGlobal( sceneRef, camera );
  420. //
  421. sceneRef.onBeforeRender( this, scene, camera, renderTarget );
  422. //
  423. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  424. _frustum.setFromProjectionMatrix( _projScreenMatrix, coordinateSystem );
  425. const renderList = this._renderLists.get( scene, camera );
  426. renderList.begin();
  427. this._projectObject( scene, camera, 0, renderList, renderContext.clippingContext );
  428. renderList.finish();
  429. if ( this.sortObjects === true ) {
  430. renderList.sort( this._opaqueSort, this._transparentSort );
  431. }
  432. //
  433. if ( renderTarget !== null ) {
  434. this._textures.updateRenderTarget( renderTarget, activeMipmapLevel );
  435. const renderTargetData = this._textures.get( renderTarget );
  436. renderContext.textures = renderTargetData.textures;
  437. renderContext.depthTexture = renderTargetData.depthTexture;
  438. renderContext.width = renderTargetData.width;
  439. renderContext.height = renderTargetData.height;
  440. renderContext.renderTarget = renderTarget;
  441. renderContext.depth = renderTarget.depthBuffer;
  442. renderContext.stencil = renderTarget.stencilBuffer;
  443. } else {
  444. renderContext.textures = null;
  445. renderContext.depthTexture = null;
  446. renderContext.width = this.domElement.width;
  447. renderContext.height = this.domElement.height;
  448. renderContext.depth = this.depth;
  449. renderContext.stencil = this.stencil;
  450. }
  451. renderContext.width >>= activeMipmapLevel;
  452. renderContext.height >>= activeMipmapLevel;
  453. renderContext.activeCubeFace = activeCubeFace;
  454. renderContext.activeMipmapLevel = activeMipmapLevel;
  455. renderContext.occlusionQueryCount = renderList.occlusionQueryCount;
  456. //
  457. this._nodes.updateScene( sceneRef );
  458. //
  459. this._background.update( sceneRef, renderList, renderContext );
  460. //
  461. this.backend.beginRender( renderContext );
  462. // process render lists
  463. const {
  464. bundles,
  465. lightsNode,
  466. transparentDoublePass: transparentDoublePassObjects,
  467. transparent: transparentObjects,
  468. opaque: opaqueObjects
  469. } = renderList;
  470. if ( bundles.length > 0 ) this._renderBundles( bundles, sceneRef, lightsNode );
  471. if ( this.opaque === true && opaqueObjects.length > 0 ) this._renderObjects( opaqueObjects, camera, sceneRef, lightsNode );
  472. if ( this.transparent === true && transparentObjects.length > 0 ) this._renderTransparents( transparentObjects, transparentDoublePassObjects, camera, sceneRef, lightsNode );
  473. // finish render pass
  474. this.backend.finishRender( renderContext );
  475. // restore render tree
  476. nodeFrame.renderId = previousRenderId;
  477. this._currentRenderContext = previousRenderContext;
  478. this._currentRenderObjectFunction = previousRenderObjectFunction;
  479. //
  480. if ( frameBufferTarget !== null ) {
  481. this.setRenderTarget( outputRenderTarget, activeCubeFace, activeMipmapLevel );
  482. const quad = this._quad;
  483. if ( this._nodes.hasOutputChange( renderTarget.texture ) ) {
  484. quad.material.fragmentNode = this._nodes.getOutputNode( renderTarget.texture );
  485. quad.material.needsUpdate = true;
  486. }
  487. this._renderScene( quad, quad.camera, false );
  488. }
  489. //
  490. sceneRef.onAfterRender( this, scene, camera, renderTarget );
  491. //
  492. return renderContext;
  493. }
  494. getMaxAnisotropy() {
  495. return this.backend.getMaxAnisotropy();
  496. }
  497. getActiveCubeFace() {
  498. return this._activeCubeFace;
  499. }
  500. getActiveMipmapLevel() {
  501. return this._activeMipmapLevel;
  502. }
  503. async setAnimationLoop( callback ) {
  504. if ( this._initialized === false ) await this.init();
  505. this._animation.setAnimationLoop( callback );
  506. }
  507. async getArrayBufferAsync( attribute ) {
  508. return await this.backend.getArrayBufferAsync( attribute );
  509. }
  510. getContext() {
  511. return this.backend.getContext();
  512. }
  513. getPixelRatio() {
  514. return this._pixelRatio;
  515. }
  516. getDrawingBufferSize( target ) {
  517. return target.set( this._width * this._pixelRatio, this._height * this._pixelRatio ).floor();
  518. }
  519. getSize( target ) {
  520. return target.set( this._width, this._height );
  521. }
  522. setPixelRatio( value = 1 ) {
  523. if ( this._pixelRatio === value ) return;
  524. this._pixelRatio = value;
  525. this.setSize( this._width, this._height, false );
  526. }
  527. setDrawingBufferSize( width, height, pixelRatio ) {
  528. this._width = width;
  529. this._height = height;
  530. this._pixelRatio = pixelRatio;
  531. this.domElement.width = Math.floor( width * pixelRatio );
  532. this.domElement.height = Math.floor( height * pixelRatio );
  533. this.setViewport( 0, 0, width, height );
  534. if ( this._initialized ) this.backend.updateSize();
  535. }
  536. setSize( width, height, updateStyle = true ) {
  537. this._width = width;
  538. this._height = height;
  539. this.domElement.width = Math.floor( width * this._pixelRatio );
  540. this.domElement.height = Math.floor( height * this._pixelRatio );
  541. if ( updateStyle === true ) {
  542. this.domElement.style.width = width + 'px';
  543. this.domElement.style.height = height + 'px';
  544. }
  545. this.setViewport( 0, 0, width, height );
  546. if ( this._initialized ) this.backend.updateSize();
  547. }
  548. setOpaqueSort( method ) {
  549. this._opaqueSort = method;
  550. }
  551. setTransparentSort( method ) {
  552. this._transparentSort = method;
  553. }
  554. getScissor( target ) {
  555. const scissor = this._scissor;
  556. target.x = scissor.x;
  557. target.y = scissor.y;
  558. target.width = scissor.width;
  559. target.height = scissor.height;
  560. return target;
  561. }
  562. setScissor( x, y, width, height ) {
  563. const scissor = this._scissor;
  564. if ( x.isVector4 ) {
  565. scissor.copy( x );
  566. } else {
  567. scissor.set( x, y, width, height );
  568. }
  569. }
  570. getScissorTest() {
  571. return this._scissorTest;
  572. }
  573. setScissorTest( boolean ) {
  574. this._scissorTest = boolean;
  575. this.backend.setScissorTest( boolean );
  576. }
  577. getViewport( target ) {
  578. return target.copy( this._viewport );
  579. }
  580. setViewport( x, y, width, height, minDepth = 0, maxDepth = 1 ) {
  581. const viewport = this._viewport;
  582. if ( x.isVector4 ) {
  583. viewport.copy( x );
  584. } else {
  585. viewport.set( x, y, width, height );
  586. }
  587. viewport.minDepth = minDepth;
  588. viewport.maxDepth = maxDepth;
  589. }
  590. getClearColor( target ) {
  591. return target.copy( this._clearColor );
  592. }
  593. setClearColor( color, alpha = 1 ) {
  594. this._clearColor.set( color );
  595. this._clearColor.a = alpha;
  596. }
  597. getClearAlpha() {
  598. return this._clearColor.a;
  599. }
  600. setClearAlpha( alpha ) {
  601. this._clearColor.a = alpha;
  602. }
  603. getClearDepth() {
  604. return this._clearDepth;
  605. }
  606. setClearDepth( depth ) {
  607. this._clearDepth = depth;
  608. }
  609. getClearStencil() {
  610. return this._clearStencil;
  611. }
  612. setClearStencil( stencil ) {
  613. this._clearStencil = stencil;
  614. }
  615. isOccluded( object ) {
  616. const renderContext = this._currentRenderContext;
  617. return renderContext && this.backend.isOccluded( renderContext, object );
  618. }
  619. clear( color = true, depth = true, stencil = true ) {
  620. if ( this._initialized === false ) {
  621. console.warn( 'THREE.Renderer: .clear() called before the backend is initialized. Try using .clearAsync() instead.' );
  622. return this.clearAsync( color, depth, stencil );
  623. }
  624. const renderTarget = this._renderTarget || this._getFrameBufferTarget();
  625. let renderTargetData = null;
  626. if ( renderTarget !== null ) {
  627. this._textures.updateRenderTarget( renderTarget );
  628. renderTargetData = this._textures.get( renderTarget );
  629. }
  630. this.backend.clear( color, depth, stencil, renderTargetData );
  631. if ( renderTarget !== null && this._renderTarget === null ) {
  632. // If a color space transform or tone mapping is required,
  633. // the clear operation clears the intermediate renderTarget texture, but does not update the screen canvas.
  634. const quad = this._quad;
  635. if ( this._nodes.hasOutputChange( renderTarget.texture ) ) {
  636. quad.material.fragmentNode = this._nodes.getOutputNode( renderTarget.texture );
  637. quad.material.needsUpdate = true;
  638. }
  639. this._renderScene( quad, quad.camera, false );
  640. }
  641. }
  642. clearColor() {
  643. return this.clear( true, false, false );
  644. }
  645. clearDepth() {
  646. return this.clear( false, true, false );
  647. }
  648. clearStencil() {
  649. return this.clear( false, false, true );
  650. }
  651. async clearAsync( color = true, depth = true, stencil = true ) {
  652. if ( this._initialized === false ) await this.init();
  653. this.clear( color, depth, stencil );
  654. }
  655. clearColorAsync() {
  656. return this.clearAsync( true, false, false );
  657. }
  658. clearDepthAsync() {
  659. return this.clearAsync( false, true, false );
  660. }
  661. clearStencilAsync() {
  662. return this.clearAsync( false, false, true );
  663. }
  664. get currentToneMapping() {
  665. return this._renderTarget !== null ? NoToneMapping : this.toneMapping;
  666. }
  667. get currentColorSpace() {
  668. return this._renderTarget !== null ? LinearSRGBColorSpace : this.outputColorSpace;
  669. }
  670. dispose() {
  671. this.info.dispose();
  672. this.backend.dispose();
  673. this._animation.dispose();
  674. this._objects.dispose();
  675. this._pipelines.dispose();
  676. this._nodes.dispose();
  677. this._bindings.dispose();
  678. this._renderLists.dispose();
  679. this._renderContexts.dispose();
  680. this._textures.dispose();
  681. this.setRenderTarget( null );
  682. this.setAnimationLoop( null );
  683. }
  684. setRenderTarget( renderTarget, activeCubeFace = 0, activeMipmapLevel = 0 ) {
  685. this._renderTarget = renderTarget;
  686. this._activeCubeFace = activeCubeFace;
  687. this._activeMipmapLevel = activeMipmapLevel;
  688. }
  689. getRenderTarget() {
  690. return this._renderTarget;
  691. }
  692. setRenderObjectFunction( renderObjectFunction ) {
  693. this._renderObjectFunction = renderObjectFunction;
  694. }
  695. getRenderObjectFunction() {
  696. return this._renderObjectFunction;
  697. }
  698. compute( computeNodes ) {
  699. if ( this.isDeviceLost === true ) return;
  700. if ( this._initialized === false ) {
  701. console.warn( 'THREE.Renderer: .compute() called before the backend is initialized. Try using .computeAsync() instead.' );
  702. return this.computeAsync( computeNodes );
  703. }
  704. //
  705. const nodeFrame = this._nodes.nodeFrame;
  706. const previousRenderId = nodeFrame.renderId;
  707. //
  708. this.info.calls ++;
  709. this.info.compute.calls ++;
  710. this.info.compute.frameCalls ++;
  711. nodeFrame.renderId = this.info.calls;
  712. //
  713. const backend = this.backend;
  714. const pipelines = this._pipelines;
  715. const bindings = this._bindings;
  716. const nodes = this._nodes;
  717. const computeList = Array.isArray( computeNodes ) ? computeNodes : [ computeNodes ];
  718. if ( computeList[ 0 ] === undefined || computeList[ 0 ].isComputeNode !== true ) {
  719. throw new Error( 'THREE.Renderer: .compute() expects a ComputeNode.' );
  720. }
  721. backend.beginCompute( computeNodes );
  722. for ( const computeNode of computeList ) {
  723. // onInit
  724. if ( pipelines.has( computeNode ) === false ) {
  725. const dispose = () => {
  726. computeNode.removeEventListener( 'dispose', dispose );
  727. pipelines.delete( computeNode );
  728. bindings.delete( computeNode );
  729. nodes.delete( computeNode );
  730. };
  731. computeNode.addEventListener( 'dispose', dispose );
  732. //
  733. const onInitFn = computeNode.onInitFunction;
  734. if ( onInitFn !== null ) {
  735. onInitFn.call( computeNode, { renderer: this } );
  736. }
  737. }
  738. nodes.updateForCompute( computeNode );
  739. bindings.updateForCompute( computeNode );
  740. const computeBindings = bindings.getForCompute( computeNode );
  741. const computePipeline = pipelines.getForCompute( computeNode, computeBindings );
  742. backend.compute( computeNodes, computeNode, computeBindings, computePipeline );
  743. }
  744. backend.finishCompute( computeNodes );
  745. //
  746. nodeFrame.renderId = previousRenderId;
  747. }
  748. async computeAsync( computeNodes ) {
  749. if ( this._initialized === false ) await this.init();
  750. this.compute( computeNodes );
  751. await this.backend.resolveTimestampAsync( computeNodes, 'compute' );
  752. }
  753. async hasFeatureAsync( name ) {
  754. if ( this._initialized === false ) await this.init();
  755. return this.backend.hasFeature( name );
  756. }
  757. hasFeature( name ) {
  758. if ( this._initialized === false ) {
  759. console.warn( 'THREE.Renderer: .hasFeature() called before the backend is initialized. Try using .hasFeatureAsync() instead.' );
  760. return false;
  761. }
  762. return this.backend.hasFeature( name );
  763. }
  764. hasInitialized() {
  765. return this._initialized;
  766. }
  767. async initTextureAsync( texture ) {
  768. if ( this._initialized === false ) await this.init();
  769. this._textures.updateTexture( texture );
  770. }
  771. initTexture( texture ) {
  772. if ( this._initialized === false ) {
  773. console.warn( 'THREE.Renderer: .initTexture() called before the backend is initialized. Try using .initTextureAsync() instead.' );
  774. return false;
  775. }
  776. this._textures.updateTexture( texture );
  777. }
  778. copyFramebufferToTexture( framebufferTexture, rectangle = null ) {
  779. if ( rectangle !== null ) {
  780. if ( rectangle.isVector2 ) {
  781. rectangle = _vector4.set( rectangle.x, rectangle.y, framebufferTexture.image.width, framebufferTexture.image.height ).floor();
  782. } else if ( rectangle.isVector4 ) {
  783. rectangle = _vector4.copy( rectangle ).floor();
  784. } else {
  785. console.error( 'THREE.Renderer.copyFramebufferToTexture: Invalid rectangle.' );
  786. return;
  787. }
  788. } else {
  789. rectangle = _vector4.set( 0, 0, framebufferTexture.image.width, framebufferTexture.image.height );
  790. }
  791. //
  792. let renderContext = this._currentRenderContext;
  793. let renderTarget;
  794. if ( renderContext !== null ) {
  795. renderTarget = renderContext.renderTarget;
  796. } else {
  797. renderTarget = this._renderTarget || this._getFrameBufferTarget();
  798. if ( renderTarget !== null ) {
  799. this._textures.updateRenderTarget( renderTarget );
  800. renderContext = this._textures.get( renderTarget );
  801. }
  802. }
  803. //
  804. this._textures.updateTexture( framebufferTexture, { renderTarget } );
  805. this.backend.copyFramebufferToTexture( framebufferTexture, renderContext, rectangle );
  806. }
  807. copyTextureToTexture( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) {
  808. this._textures.updateTexture( srcTexture );
  809. this._textures.updateTexture( dstTexture );
  810. this.backend.copyTextureToTexture( srcTexture, dstTexture, srcRegion, dstPosition, level );
  811. }
  812. readRenderTargetPixelsAsync( renderTarget, x, y, width, height, index = 0, faceIndex = 0 ) {
  813. return this.backend.copyTextureToBuffer( renderTarget.textures[ index ], x, y, width, height, faceIndex );
  814. }
  815. _projectObject( object, camera, groupOrder, renderList, clippingContext ) {
  816. if ( object.visible === false ) return;
  817. const visible = object.layers.test( camera.layers );
  818. if ( visible ) {
  819. if ( object.isGroup ) {
  820. groupOrder = object.renderOrder;
  821. if ( object.isClippingGroup && object.enabled ) clippingContext = clippingContext.getGroupContext( object );
  822. } else if ( object.isLOD ) {
  823. if ( object.autoUpdate === true ) object.update( camera );
  824. } else if ( object.isLight ) {
  825. renderList.pushLight( object );
  826. } else if ( object.isSprite ) {
  827. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  828. if ( this.sortObjects === true ) {
  829. _vector4.setFromMatrixPosition( object.matrixWorld ).applyMatrix4( _projScreenMatrix );
  830. }
  831. const { geometry, material } = object;
  832. if ( material.visible ) {
  833. renderList.push( object, geometry, material, groupOrder, _vector4.z, null, clippingContext );
  834. }
  835. }
  836. } else if ( object.isLineLoop ) {
  837. console.error( 'THREE.Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.' );
  838. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  839. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  840. const { geometry, material } = object;
  841. if ( this.sortObjects === true ) {
  842. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  843. _vector4
  844. .copy( geometry.boundingSphere.center )
  845. .applyMatrix4( object.matrixWorld )
  846. .applyMatrix4( _projScreenMatrix );
  847. }
  848. if ( Array.isArray( material ) ) {
  849. const groups = geometry.groups;
  850. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  851. const group = groups[ i ];
  852. const groupMaterial = material[ group.materialIndex ];
  853. if ( groupMaterial && groupMaterial.visible ) {
  854. renderList.push( object, geometry, groupMaterial, groupOrder, _vector4.z, group, clippingContext );
  855. }
  856. }
  857. } else if ( material.visible ) {
  858. renderList.push( object, geometry, material, groupOrder, _vector4.z, null, clippingContext );
  859. }
  860. }
  861. }
  862. }
  863. if ( object.isBundleGroup === true && this.backend.beginBundle !== undefined ) {
  864. const baseRenderList = renderList;
  865. // replace render list
  866. renderList = this._renderLists.get( object, camera );
  867. renderList.begin();
  868. baseRenderList.pushBundle( {
  869. bundleGroup: object,
  870. camera,
  871. renderList,
  872. } );
  873. renderList.finish();
  874. }
  875. const children = object.children;
  876. for ( let i = 0, l = children.length; i < l; i ++ ) {
  877. this._projectObject( children[ i ], camera, groupOrder, renderList, clippingContext );
  878. }
  879. }
  880. _renderBundles( bundles, sceneRef, lightsNode ) {
  881. for ( const bundle of bundles ) {
  882. this._renderBundle( bundle, sceneRef, lightsNode );
  883. }
  884. }
  885. _renderTransparents( renderList, doublePassList, camera, scene, lightsNode ) {
  886. if ( doublePassList.length > 0 ) {
  887. // render back side
  888. for ( const { material } of doublePassList ) {
  889. material.side = BackSide;
  890. }
  891. this._renderObjects( doublePassList, camera, scene, lightsNode, 'backSide' );
  892. // render front side
  893. for ( const { material } of doublePassList ) {
  894. material.side = FrontSide;
  895. }
  896. this._renderObjects( renderList, camera, scene, lightsNode );
  897. // restore
  898. for ( const { material } of doublePassList ) {
  899. material.side = DoubleSide;
  900. }
  901. } else {
  902. this._renderObjects( renderList, camera, scene, lightsNode );
  903. }
  904. }
  905. _renderObjects( renderList, camera, scene, lightsNode, passId = null ) {
  906. // process renderable objects
  907. for ( let i = 0, il = renderList.length; i < il; i ++ ) {
  908. const renderItem = renderList[ i ];
  909. // @TODO: Add support for multiple materials per object. This will require to extract
  910. // the material from the renderItem object and pass it with its group data to renderObject().
  911. const { object, geometry, material, group, clippingContext } = renderItem;
  912. if ( camera.isArrayCamera ) {
  913. const cameras = camera.cameras;
  914. for ( let j = 0, jl = cameras.length; j < jl; j ++ ) {
  915. const camera2 = cameras[ j ];
  916. if ( object.layers.test( camera2.layers ) ) {
  917. const vp = camera2.viewport;
  918. const minDepth = ( vp.minDepth === undefined ) ? 0 : vp.minDepth;
  919. const maxDepth = ( vp.maxDepth === undefined ) ? 1 : vp.maxDepth;
  920. const viewportValue = this._currentRenderContext.viewportValue;
  921. viewportValue.copy( vp ).multiplyScalar( this._pixelRatio ).floor();
  922. viewportValue.minDepth = minDepth;
  923. viewportValue.maxDepth = maxDepth;
  924. this.backend.updateViewport( this._currentRenderContext );
  925. this._currentRenderObjectFunction( object, scene, camera2, geometry, material, group, lightsNode, clippingContext, passId );
  926. }
  927. }
  928. } else {
  929. this._currentRenderObjectFunction( object, scene, camera, geometry, material, group, lightsNode, clippingContext, passId );
  930. }
  931. }
  932. }
  933. renderObject( object, scene, camera, geometry, material, group, lightsNode, clippingContext = null, passId = null ) {
  934. let overridePositionNode;
  935. let overrideFragmentNode;
  936. let overrideDepthNode;
  937. //
  938. object.onBeforeRender( this, scene, camera, geometry, material, group );
  939. //
  940. if ( scene.overrideMaterial !== null ) {
  941. const overrideMaterial = scene.overrideMaterial;
  942. if ( material.positionNode && material.positionNode.isNode ) {
  943. overridePositionNode = overrideMaterial.positionNode;
  944. overrideMaterial.positionNode = material.positionNode;
  945. }
  946. if ( overrideMaterial.isShadowNodeMaterial ) {
  947. overrideMaterial.side = material.shadowSide === null ? material.side : material.shadowSide;
  948. if ( material.depthNode && material.depthNode.isNode ) {
  949. overrideDepthNode = overrideMaterial.depthNode;
  950. overrideMaterial.depthNode = material.depthNode;
  951. }
  952. if ( material.castShadowNode && material.castShadowNode.isNode ) {
  953. overrideFragmentNode = overrideMaterial.fragmentNode;
  954. overrideMaterial.fragmentNode = material.castShadowNode;
  955. }
  956. }
  957. material = overrideMaterial;
  958. }
  959. //
  960. if ( material.transparent === true && material.side === DoubleSide && material.forceSinglePass === false ) {
  961. material.side = BackSide;
  962. this._handleObjectFunction( object, material, scene, camera, lightsNode, group, clippingContext, 'backSide' ); // create backSide pass id
  963. material.side = FrontSide;
  964. this._handleObjectFunction( object, material, scene, camera, lightsNode, group, clippingContext, passId ); // use default pass id
  965. material.side = DoubleSide;
  966. } else {
  967. this._handleObjectFunction( object, material, scene, camera, lightsNode, group, clippingContext, passId );
  968. }
  969. //
  970. if ( overridePositionNode !== undefined ) {
  971. scene.overrideMaterial.positionNode = overridePositionNode;
  972. }
  973. if ( overrideDepthNode !== undefined ) {
  974. scene.overrideMaterial.depthNode = overrideDepthNode;
  975. }
  976. if ( overrideFragmentNode !== undefined ) {
  977. scene.overrideMaterial.fragmentNode = overrideFragmentNode;
  978. }
  979. //
  980. object.onAfterRender( this, scene, camera, geometry, material, group );
  981. }
  982. _renderObjectDirect( object, material, scene, camera, lightsNode, group, clippingContext, passId ) {
  983. const renderObject = this._objects.get( object, material, scene, camera, lightsNode, this._currentRenderContext, clippingContext, passId );
  984. renderObject.drawRange = object.geometry.drawRange;
  985. renderObject.group = group;
  986. //
  987. const needsRefresh = this._nodes.needsRefresh( renderObject );
  988. if ( needsRefresh ) {
  989. this._nodes.updateBefore( renderObject );
  990. this._geometries.updateForRender( renderObject );
  991. this._nodes.updateForRender( renderObject );
  992. this._bindings.updateForRender( renderObject );
  993. }
  994. this._pipelines.updateForRender( renderObject );
  995. //
  996. if ( this._currentRenderBundle !== null ) {
  997. const renderBundleData = this.backend.get( this._currentRenderBundle );
  998. renderBundleData.renderObjects.push( renderObject );
  999. renderObject.bundle = this._currentRenderBundle.scene;
  1000. }
  1001. this.backend.draw( renderObject, this.info );
  1002. if ( needsRefresh ) this._nodes.updateAfter( renderObject );
  1003. }
  1004. _createObjectPipeline( object, material, scene, camera, lightsNode, clippingContext, passId ) {
  1005. const renderObject = this._objects.get( object, material, scene, camera, lightsNode, this._currentRenderContext, clippingContext, passId );
  1006. //
  1007. this._nodes.updateBefore( renderObject );
  1008. this._geometries.updateForRender( renderObject );
  1009. this._nodes.updateForRender( renderObject );
  1010. this._bindings.updateForRender( renderObject );
  1011. this._pipelines.getForRender( renderObject, this._compilationPromises );
  1012. this._nodes.updateAfter( renderObject );
  1013. }
  1014. get compile() {
  1015. return this.compileAsync;
  1016. }
  1017. }
  1018. export default Renderer;
粤ICP备19079148号