Skip to content

Commit f367f20

Browse files
authored
WebGPURenderer: Relates MRT for RenderContext in obtaining a unique context. (#32264)
1 parent ed0e71f commit f367f20

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

src/renderers/common/RenderContexts.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,24 @@ class RenderContexts {
3535
* @param {Scene} scene - The scene.
3636
* @param {Camera} camera - The camera that is used to render the scene.
3737
* @param {?RenderTarget} [renderTarget=null] - The active render target.
38+
* @param {?MRT} [mrt=null] - The active multiple render target.
3839
* @return {RenderContext} The render context.
3940
*/
40-
get( scene, camera, renderTarget = null ) {
41+
get( scene, camera, renderTarget = null, mrt = null ) {
4142

42-
_chainKeys[ 0 ] = scene;
43-
_chainKeys[ 1 ] = camera;
43+
let index = 0;
44+
45+
if ( mrt !== null ) {
46+
47+
// TODO: Improve ChainMap so that it only matches submaps corresponding to the key lengths.
48+
// For we use: if ( mrt !== null ) _chainKeys[ 2 ] = mrt;
49+
50+
_chainKeys[ index ++ ] = mrt;
51+
52+
}
53+
54+
_chainKeys[ index ++ ] = scene;
55+
_chainKeys[ index ++ ] = camera;
4456

4557
let attachmentState;
4658

src/renderers/common/RenderObject.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,8 @@ class RenderObject {
778778

779779
}
780780

781+
cacheKey += this.context.id + ',';
782+
781783
cacheKey += object.receiveShadow + ',';
782784

783785
return hashString( cacheKey );

src/renderers/common/Renderer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ class Renderer {
699699
await this.compileAsync( scene, camera );
700700

701701
const renderList = this._renderLists.get( scene, camera );
702-
const renderContext = this._renderContexts.get( scene, camera, this._renderTarget );
702+
const renderContext = this._renderContexts.get( scene, camera, this._renderTarget, this._mrt );
703703

704704
const material = scene.overrideMaterial || object.material;
705705

@@ -859,7 +859,7 @@ class Renderer {
859859
if ( targetScene === null ) targetScene = scene;
860860

861861
const renderTarget = this._renderTarget;
862-
const renderContext = this._renderContexts.get( targetScene, camera, renderTarget );
862+
const renderContext = this._renderContexts.get( targetScene, camera, renderTarget, this._mrt );
863863
const activeMipmapLevel = this._activeMipmapLevel;
864864

865865
const compilationPromises = [];
@@ -1361,7 +1361,7 @@ class Renderer {
13611361

13621362
//
13631363

1364-
const renderContext = this._renderContexts.get( scene, camera, renderTarget );
1364+
const renderContext = this._renderContexts.get( scene, camera, renderTarget, this._mrt );
13651365

13661366
this._currentRenderContext = renderContext;
13671367
this._currentRenderObjectFunction = this._renderObjectFunction || this.renderObject;

0 commit comments

Comments
 (0)