Renderer.js 22 KB

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