Renderer.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998
  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 { Scene, Frustum, Matrix4, Vector2, Vector3, Vector4, DoubleSide, BackSide, FrontSide, SRGBColorSpace, NoToneMapping } from 'three';
  15. const _scene = new Scene();
  16. const _drawingBufferSize = new Vector2();
  17. const _screen = new Vector4();
  18. const _frustum = new Frustum();
  19. const _projScreenMatrix = new Matrix4();
  20. const _vector3 = new Vector3();
  21. class Renderer {
  22. constructor( backend, parameters = {} ) {
  23. this.isRenderer = true;
  24. //
  25. const {
  26. logarithmicDepthBuffer = false,
  27. } = parameters;
  28. // public
  29. this.domElement = backend.getDomElement();
  30. this.backend = backend;
  31. this.autoClear = true;
  32. this.autoClearColor = true;
  33. this.autoClearDepth = true;
  34. this.autoClearStencil = true;
  35. this.logarithmicDepthBuffer = logarithmicDepthBuffer;
  36. this.outputColorSpace = SRGBColorSpace;
  37. this.toneMapping = NoToneMapping;
  38. this.toneMappingExposure = 1.0;
  39. this.sortObjects = true;
  40. this.depth = true;
  41. this.stencil = true;
  42. this.info = new Info();
  43. // internals
  44. this._pixelRatio = 1;
  45. this._width = this.domElement.width;
  46. this._height = this.domElement.height;
  47. this._viewport = new Vector4( 0, 0, this._width, this._height );
  48. this._scissor = new Vector4( 0, 0, this._width, this._height );
  49. this._scissorTest = false;
  50. this._properties = null;
  51. this._attributes = null;
  52. this._geometries = null;
  53. this._nodes = null;
  54. this._animation = null;
  55. this._bindings = null;
  56. this._objects = null;
  57. this._pipelines = null;
  58. this._renderLists = null;
  59. this._renderContexts = null;
  60. this._textures = null;
  61. this._background = null;
  62. this._currentRenderContext = null;
  63. this._opaqueSort = null;
  64. this._transparentSort = null;
  65. this._clearColor = new Color4( 0x000000 );
  66. this._clearDepth = 1;
  67. this._clearStencil = 0;
  68. this._renderTarget = null;
  69. this._activeCubeFace = 0;
  70. this._activeMipmapLevel = 0;
  71. this._renderObjectFunction = null;
  72. this._currentRenderObjectFunction = null;
  73. this._initialized = false;
  74. this._initPromise = null;
  75. // backwards compatibility
  76. this.shadowMap = {
  77. enabled: false,
  78. type: null
  79. };
  80. this.xr = {
  81. enabled: false
  82. };
  83. }
  84. async init() {
  85. if ( this._initialized ) {
  86. throw new Error( 'Renderer: Backend has already been initialized.' );
  87. }
  88. if ( this._initPromise !== null ) {
  89. return this._initPromise;
  90. }
  91. this._initPromise = new Promise( async ( resolve, reject ) => {
  92. const backend = this.backend;
  93. try {
  94. await backend.init( this );
  95. } catch ( error ) {
  96. reject( error );
  97. return;
  98. }
  99. this._nodes = new Nodes( this, backend );
  100. this._animation = new Animation( this._nodes, this.info );
  101. this._attributes = new Attributes( backend );
  102. this._background = new Background( this, this._nodes );
  103. this._geometries = new Geometries( this._attributes, this.info );
  104. this._textures = new Textures( backend, this.info );
  105. this._pipelines = new Pipelines( backend, this._nodes );
  106. this._bindings = new Bindings( backend, this._nodes, this._textures, this._attributes, this._pipelines, this.info );
  107. this._objects = new RenderObjects( this, this._nodes, this._geometries, this._pipelines, this._bindings, this.info );
  108. this._renderLists = new RenderLists();
  109. this._renderContexts = new RenderContexts();
  110. //
  111. this._initialized = true;
  112. resolve();
  113. } );
  114. return this._initPromise;
  115. }
  116. get coordinateSystem() {
  117. return this.backend.coordinateSystem;
  118. }
  119. async compile( /*scene, camera*/ ) {
  120. console.warn( 'THREE.Renderer: .compile() is not implemented yet.' );
  121. }
  122. async render( scene, camera ) {
  123. if ( this._initialized === false ) await this.init();
  124. // preserve render tree
  125. const nodeFrame = this._nodes.nodeFrame;
  126. const previousRenderId = nodeFrame.renderId;
  127. const previousRenderContext = this._currentRenderContext;
  128. const previousRenderObjectFunction = this._currentRenderObjectFunction;
  129. //
  130. const sceneRef = ( scene.isScene === true ) ? scene : _scene;
  131. const renderTarget = this._renderTarget;
  132. const renderContext = this._renderContexts.get( scene, camera, renderTarget );
  133. const activeCubeFace = this._activeCubeFace;
  134. const activeMipmapLevel = this._activeMipmapLevel;
  135. this._currentRenderContext = renderContext;
  136. this._currentRenderObjectFunction = this._renderObjectFunction || this.renderObject;
  137. //
  138. this.info.calls ++;
  139. this.info.render.calls ++;
  140. nodeFrame.renderId = this.info.calls;
  141. //
  142. const coordinateSystem = this.coordinateSystem;
  143. if ( camera.coordinateSystem !== coordinateSystem ) {
  144. camera.coordinateSystem = coordinateSystem;
  145. camera.updateProjectionMatrix();
  146. }
  147. //
  148. if ( scene.matrixWorldAutoUpdate === true ) scene.updateMatrixWorld();
  149. if ( camera.parent === null && camera.matrixWorldAutoUpdate === true ) camera.updateMatrixWorld();
  150. if ( this.info.autoReset === true ) this.info.reset();
  151. //
  152. let viewport = this._viewport;
  153. let scissor = this._scissor;
  154. let pixelRatio = this._pixelRatio;
  155. if ( renderTarget !== null ) {
  156. viewport = renderTarget.viewport;
  157. scissor = renderTarget.scissor;
  158. pixelRatio = 1;
  159. }
  160. this.getDrawingBufferSize( _drawingBufferSize );
  161. _screen.set( 0, 0, _drawingBufferSize.width, _drawingBufferSize.height );
  162. const minDepth = ( viewport.minDepth === undefined ) ? 0 : viewport.minDepth;
  163. const maxDepth = ( viewport.maxDepth === undefined ) ? 1 : viewport.maxDepth;
  164. renderContext.viewportValue.copy( viewport ).multiplyScalar( pixelRatio ).floor();
  165. renderContext.viewportValue.width >>= activeMipmapLevel;
  166. renderContext.viewportValue.height >>= activeMipmapLevel;
  167. renderContext.viewportValue.minDepth = minDepth;
  168. renderContext.viewportValue.maxDepth = maxDepth;
  169. renderContext.viewport = renderContext.viewportValue.equals( _screen ) === false;
  170. renderContext.scissorValue.copy( scissor ).multiplyScalar( pixelRatio ).floor();
  171. renderContext.scissor = this._scissorTest && renderContext.scissorValue.equals( _screen ) === false;
  172. renderContext.scissorValue.width >>= activeMipmapLevel;
  173. renderContext.scissorValue.height >>= activeMipmapLevel;
  174. renderContext.depth = this.depth;
  175. renderContext.stencil = this.stencil;
  176. //
  177. sceneRef.onBeforeRender( this, scene, camera, renderTarget );
  178. //
  179. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  180. _frustum.setFromProjectionMatrix( _projScreenMatrix, coordinateSystem );
  181. const renderList = this._renderLists.get( scene, camera );
  182. renderList.begin();
  183. this._projectObject( scene, camera, 0, renderList );
  184. renderList.finish();
  185. if ( this.sortObjects === true ) {
  186. renderList.sort( this._opaqueSort, this._transparentSort );
  187. }
  188. //
  189. if ( renderTarget !== null ) {
  190. this._textures.updateRenderTarget( renderTarget, activeMipmapLevel );
  191. const renderTargetData = this._textures.get( renderTarget );
  192. renderContext.textures = renderTargetData.textures;
  193. renderContext.depthTexture = renderTargetData.depthTexture;
  194. renderContext.width = renderTargetData.width;
  195. renderContext.height = renderTargetData.height;
  196. } else {
  197. renderContext.textures = null;
  198. renderContext.depthTexture = null;
  199. renderContext.width = this.domElement.width;
  200. renderContext.height = this.domElement.height;
  201. }
  202. renderContext.width >>= activeMipmapLevel;
  203. renderContext.height >>= activeMipmapLevel;
  204. renderContext.activeCubeFace = activeCubeFace;
  205. renderContext.activeMipmapLevel = activeMipmapLevel;
  206. renderContext.occlusionQueryCount = renderList.occlusionQueryCount;
  207. //
  208. this._nodes.updateScene( sceneRef );
  209. //
  210. this._background.update( sceneRef, renderList, renderContext );
  211. //
  212. this.backend.beginRender( renderContext );
  213. // process render lists
  214. const opaqueObjects = renderList.opaque;
  215. const transparentObjects = renderList.transparent;
  216. const lightsNode = renderList.lightsNode;
  217. if ( opaqueObjects.length > 0 ) this._renderObjects( opaqueObjects, camera, sceneRef, lightsNode );
  218. if ( transparentObjects.length > 0 ) this._renderObjects( transparentObjects, camera, sceneRef, lightsNode );
  219. // finish render pass
  220. this.backend.finishRender( renderContext );
  221. // restore render tree
  222. nodeFrame.renderId = previousRenderId;
  223. this._currentRenderContext = previousRenderContext;
  224. this._currentRenderObjectFunction = previousRenderObjectFunction;
  225. //
  226. sceneRef.onAfterRender( this, scene, camera, renderTarget );
  227. }
  228. getActiveCubeFace() {
  229. return this._activeCubeFace;
  230. }
  231. getActiveMipmapLevel() {
  232. return this._activeMipmapLevel;
  233. }
  234. async setAnimationLoop( callback ) {
  235. if ( this._initialized === false ) await this.init();
  236. this._animation.setAnimationLoop( callback );
  237. }
  238. getArrayBuffer( attribute ) { // @deprecated, r155
  239. console.warn( 'THREE.Renderer: getArrayBuffer() is deprecated. Use getArrayBufferAsync() instead.' );
  240. return this.getArrayBufferAsync( attribute );
  241. }
  242. async getArrayBufferAsync( attribute ) {
  243. return await this.backend.getArrayBufferAsync( attribute );
  244. }
  245. getContext() {
  246. return this._context;
  247. }
  248. getPixelRatio() {
  249. return this._pixelRatio;
  250. }
  251. getDrawingBufferSize( target ) {
  252. return target.set( this._width * this._pixelRatio, this._height * this._pixelRatio ).floor();
  253. }
  254. getSize( target ) {
  255. return target.set( this._width, this._height );
  256. }
  257. setPixelRatio( value = 1 ) {
  258. this._pixelRatio = value;
  259. this.setSize( this._width, this._height, false );
  260. }
  261. setDrawingBufferSize( width, height, pixelRatio ) {
  262. this._width = width;
  263. this._height = height;
  264. this._pixelRatio = pixelRatio;
  265. this.domElement.width = Math.floor( width * pixelRatio );
  266. this.domElement.height = Math.floor( height * pixelRatio );
  267. this.setViewport( 0, 0, width, height );
  268. if ( this._initialized ) this.backend.updateSize();
  269. }
  270. setSize( width, height, updateStyle = true ) {
  271. this._width = width;
  272. this._height = height;
  273. this.domElement.width = Math.floor( width * this._pixelRatio );
  274. this.domElement.height = Math.floor( height * this._pixelRatio );
  275. if ( updateStyle === true ) {
  276. this.domElement.style.width = width + 'px';
  277. this.domElement.style.height = height + 'px';
  278. }
  279. this.setViewport( 0, 0, width, height );
  280. if ( this._initialized ) this.backend.updateSize();
  281. }
  282. setOpaqueSort( method ) {
  283. this._opaqueSort = method;
  284. }
  285. setTransparentSort( method ) {
  286. this._transparentSort = method;
  287. }
  288. getScissor( target ) {
  289. const scissor = this._scissor;
  290. target.x = scissor.x;
  291. target.y = scissor.y;
  292. target.width = scissor.width;
  293. target.height = scissor.height;
  294. return target;
  295. }
  296. setScissor( x, y, width, height ) {
  297. const scissor = this._scissor;
  298. if ( x.isVector4 ) {
  299. scissor.copy( x );
  300. } else {
  301. scissor.set( x, y, width, height );
  302. }
  303. }
  304. getScissorTest() {
  305. return this._scissorTest;
  306. }
  307. setScissorTest( boolean ) {
  308. this._scissorTest = boolean;
  309. }
  310. getViewport( target ) {
  311. return target.copy( this._viewport );
  312. }
  313. setViewport( x, y, width, height, minDepth = 0, maxDepth = 1 ) {
  314. const viewport = this._viewport;
  315. if ( x.isVector4 ) {
  316. viewport.copy( x );
  317. } else {
  318. viewport.set( x, y, width, height );
  319. }
  320. viewport.minDepth = minDepth;
  321. viewport.maxDepth = maxDepth;
  322. }
  323. getClearColor( target ) {
  324. return target.copy( this._clearColor );
  325. }
  326. setClearColor( color, alpha = 1 ) {
  327. this._clearColor.set( color );
  328. this._clearColor.a = alpha;
  329. }
  330. getClearAlpha() {
  331. return this._clearColor.a;
  332. }
  333. setClearAlpha( alpha ) {
  334. this._clearColor.a = alpha;
  335. }
  336. getClearDepth() {
  337. return this._clearDepth;
  338. }
  339. setClearDepth( depth ) {
  340. this._clearDepth = depth;
  341. }
  342. getClearStencil() {
  343. return this._clearStencil;
  344. }
  345. setClearStencil( stencil ) {
  346. this._clearStencil = stencil;
  347. }
  348. isOccluded( object ) {
  349. const renderContext = this._currentRenderContext;
  350. return renderContext && this.backend.isOccluded( renderContext, object );
  351. }
  352. clear( color = true, depth = true, stencil = true ) {
  353. let renderTargetData = null;
  354. const renderTarget = this._renderTarget;
  355. if ( renderTarget !== null ) {
  356. this._textures.updateRenderTarget( renderTarget );
  357. renderTargetData = this._textures.get( renderTarget );
  358. }
  359. this.backend.clear( color, depth, stencil, renderTargetData );
  360. }
  361. clearColor() {
  362. this.clear( true, false, false );
  363. }
  364. clearDepth() {
  365. this.clear( false, true, false );
  366. }
  367. clearStencil() {
  368. this.clear( false, false, true );
  369. }
  370. get currentColorSpace() {
  371. const renderTarget = this._renderTarget;
  372. if ( renderTarget !== null ) {
  373. const texture = renderTarget.texture;
  374. return ( Array.isArray( texture ) ? texture[ 0 ] : texture ).colorSpace;
  375. }
  376. return this.outputColorSpace;
  377. }
  378. dispose() {
  379. this.info.dispose();
  380. this._animation.dispose();
  381. this._objects.dispose();
  382. this._properties.dispose();
  383. this._pipelines.dispose();
  384. this._nodes.dispose();
  385. this._bindings.dispose();
  386. this._renderLists.dispose();
  387. this._renderContexts.dispose();
  388. this._textures.dispose();
  389. this.setRenderTarget( null );
  390. this.setAnimationLoop( null );
  391. }
  392. setRenderTarget( renderTarget, activeCubeFace = 0, activeMipmapLevel = 0 ) {
  393. this._renderTarget = renderTarget;
  394. this._activeCubeFace = activeCubeFace;
  395. this._activeMipmapLevel = activeMipmapLevel;
  396. }
  397. getRenderTarget() {
  398. return this._renderTarget;
  399. }
  400. setRenderObjectFunction( renderObjectFunction ) {
  401. this._renderObjectFunction = renderObjectFunction;
  402. }
  403. getRenderObjectFunction() {
  404. return this._renderObjectFunction;
  405. }
  406. async compute( computeNodes ) {
  407. if ( this._initialized === false ) await this.init();
  408. const nodeFrame = this._nodes.nodeFrame;
  409. const previousRenderId = nodeFrame.renderId;
  410. //
  411. this.info.calls ++;
  412. this.info.compute.calls ++;
  413. nodeFrame.renderId = this.info.calls;
  414. //
  415. const backend = this.backend;
  416. const pipelines = this._pipelines;
  417. const bindings = this._bindings;
  418. const nodes = this._nodes;
  419. const computeList = Array.isArray( computeNodes ) ? computeNodes : [ computeNodes ];
  420. if ( computeList[ 0 ] === undefined || computeList[ 0 ].isComputeNode !== true ) {
  421. throw new Error( 'THREE.Renderer: .compute() expects a ComputeNode.' );
  422. }
  423. backend.beginCompute( computeNodes );
  424. for ( const computeNode of computeList ) {
  425. // onInit
  426. if ( pipelines.has( computeNode ) === false ) {
  427. const dispose = () => {
  428. computeNode.removeEventListener( 'dispose', dispose );
  429. pipelines.delete( computeNode );
  430. bindings.delete( computeNode );
  431. nodes.delete( computeNode );
  432. };
  433. computeNode.addEventListener( 'dispose', dispose );
  434. //
  435. computeNode.onInit( { renderer: this } );
  436. }
  437. nodes.updateForCompute( computeNode );
  438. bindings.updateForCompute( computeNode );
  439. const computeBindings = bindings.getForCompute( computeNode );
  440. const computePipeline = pipelines.getForCompute( computeNode, computeBindings );
  441. backend.compute( computeNodes, computeNode, computeBindings, computePipeline );
  442. }
  443. backend.finishCompute( computeNodes );
  444. //
  445. nodeFrame.renderId = previousRenderId;
  446. }
  447. hasFeature( name ) {
  448. return this.backend.hasFeature( name );
  449. }
  450. copyFramebufferToTexture( framebufferTexture ) {
  451. const renderContext = this._currentRenderContext;
  452. this._textures.updateTexture( framebufferTexture );
  453. this.backend.copyFramebufferToTexture( framebufferTexture, renderContext );
  454. }
  455. readRenderTargetPixelsAsync( renderTarget, x, y, width, height ) {
  456. return this.backend.copyTextureToBuffer( renderTarget.texture, x, y, width, height );
  457. }
  458. _projectObject( object, camera, groupOrder, renderList ) {
  459. if ( object.visible === false ) return;
  460. const visible = object.layers.test( camera.layers );
  461. if ( visible ) {
  462. if ( object.isGroup ) {
  463. groupOrder = object.renderOrder;
  464. } else if ( object.isLOD ) {
  465. if ( object.autoUpdate === true ) object.update( camera );
  466. } else if ( object.isLight ) {
  467. renderList.pushLight( object );
  468. } else if ( object.isSprite ) {
  469. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  470. if ( this.sortObjects === true ) {
  471. _vector3.setFromMatrixPosition( object.matrixWorld ).applyMatrix4( _projScreenMatrix );
  472. }
  473. const geometry = object.geometry;
  474. const material = object.material;
  475. if ( material.visible ) {
  476. renderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  477. }
  478. }
  479. } else if ( object.isLineLoop ) {
  480. console.error( 'THREE.Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.' );
  481. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  482. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  483. const geometry = object.geometry;
  484. const material = object.material;
  485. if ( this.sortObjects === true ) {
  486. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  487. _vector3
  488. .copy( geometry.boundingSphere.center )
  489. .applyMatrix4( object.matrixWorld )
  490. .applyMatrix4( _projScreenMatrix );
  491. }
  492. if ( Array.isArray( material ) ) {
  493. const groups = geometry.groups;
  494. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  495. const group = groups[ i ];
  496. const groupMaterial = material[ group.materialIndex ];
  497. if ( groupMaterial && groupMaterial.visible ) {
  498. renderList.push( object, geometry, groupMaterial, groupOrder, _vector3.z, group );
  499. }
  500. }
  501. } else if ( material.visible ) {
  502. renderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  503. }
  504. }
  505. }
  506. }
  507. const children = object.children;
  508. for ( let i = 0, l = children.length; i < l; i ++ ) {
  509. this._projectObject( children[ i ], camera, groupOrder, renderList );
  510. }
  511. }
  512. _renderObjects( renderList, camera, scene, lightsNode ) {
  513. // process renderable objects
  514. for ( let i = 0, il = renderList.length; i < il; i ++ ) {
  515. const renderItem = renderList[ i ];
  516. // @TODO: Add support for multiple materials per object. This will require to extract
  517. // the material from the renderItem object and pass it with its group data to renderObject().
  518. const { object, geometry, material, group } = renderItem;
  519. if ( camera.isArrayCamera ) {
  520. const cameras = camera.cameras;
  521. for ( let j = 0, jl = cameras.length; j < jl; j ++ ) {
  522. const camera2 = cameras[ j ];
  523. if ( object.layers.test( camera2.layers ) ) {
  524. const vp = camera2.viewport;
  525. const minDepth = ( vp.minDepth === undefined ) ? 0 : vp.minDepth;
  526. const maxDepth = ( vp.maxDepth === undefined ) ? 1 : vp.maxDepth;
  527. const viewportValue = this._currentRenderContext.viewportValue;
  528. viewportValue.copy( vp ).multiplyScalar( this._pixelRatio ).floor();
  529. viewportValue.minDepth = minDepth;
  530. viewportValue.maxDepth = maxDepth;
  531. this.backend.updateViewport( this._currentRenderContext );
  532. this._currentRenderObjectFunction( object, scene, camera2, geometry, material, group, lightsNode );
  533. }
  534. }
  535. } else {
  536. this._currentRenderObjectFunction( object, scene, camera, geometry, material, group, lightsNode );
  537. }
  538. }
  539. }
  540. renderObject( object, scene, camera, geometry, material, group, lightsNode ) {
  541. material = scene.overrideMaterial !== null ? scene.overrideMaterial : material;
  542. //
  543. object.onBeforeRender( this, scene, camera, geometry, material, group );
  544. material.onBeforeRender( this, scene, camera, geometry, material, group );
  545. //
  546. if ( material.transparent === true && material.side === DoubleSide && material.forceSinglePass === false ) {
  547. material.side = BackSide;
  548. this._renderObjectDirect( object, material, scene, camera, lightsNode, 'backSide' ); // create backSide pass id
  549. material.side = FrontSide;
  550. this._renderObjectDirect( object, material, scene, camera, lightsNode ); // use default pass id
  551. material.side = DoubleSide;
  552. } else {
  553. this._renderObjectDirect( object, material, scene, camera, lightsNode );
  554. }
  555. //
  556. object.onAfterRender( this, scene, camera, geometry, material, group );
  557. }
  558. _renderObjectDirect( object, material, scene, camera, lightsNode, passId ) {
  559. const renderObject = this._objects.get( object, material, scene, camera, lightsNode, this._currentRenderContext, passId );
  560. //
  561. this._nodes.updateBefore( renderObject );
  562. //
  563. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  564. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  565. //
  566. this._nodes.updateForRender( renderObject );
  567. this._geometries.updateForRender( renderObject );
  568. this._bindings.updateForRender( renderObject );
  569. this._pipelines.updateForRender( renderObject );
  570. //
  571. this.backend.draw( renderObject, this.info );
  572. }
  573. }
  574. export default Renderer;