Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Texture: Introduce pmremVersion #27963

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/renderers/webgl/WebGLCubeUVMaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,26 @@ function WebGLCubeUVMaps( renderer ) {

if ( isEquirectMap || isCubeMap ) {

if ( texture.isRenderTargetTexture && texture.needsPMREMUpdate === true ) {
let renderTarget = cubeUVmaps.get( texture );

texture.needsPMREMUpdate = false;
const currentPMREMVersion = renderTarget !== undefined ? renderTarget.texture.pmremVersion : 0;

let renderTarget = cubeUVmaps.get( texture );
if ( texture.isRenderTargetTexture && texture.pmremVersion !== currentPMREMVersion ) {

if ( pmremGenerator === null ) pmremGenerator = new PMREMGenerator( renderer );

renderTarget = isEquirectMap ? pmremGenerator.fromEquirectangular( texture, renderTarget ) : pmremGenerator.fromCubemap( texture, renderTarget );
renderTarget.texture.pmremVersion = texture.pmremVersion;

cubeUVmaps.set( texture, renderTarget );

return renderTarget.texture;

} else {

if ( cubeUVmaps.has( texture ) ) {
if ( renderTarget !== undefined ) {

return cubeUVmaps.get( texture ).texture;
return renderTarget.texture;

} else {

Expand All @@ -47,7 +49,9 @@ function WebGLCubeUVMaps( renderer ) {

if ( pmremGenerator === null ) pmremGenerator = new PMREMGenerator( renderer );

const renderTarget = isEquirectMap ? pmremGenerator.fromEquirectangular( texture ) : pmremGenerator.fromCubemap( texture );
renderTarget = isEquirectMap ? pmremGenerator.fromEquirectangular( texture ) : pmremGenerator.fromCubemap( texture );
renderTarget.texture.pmremVersion = texture.pmremVersion;

cubeUVmaps.set( texture, renderTarget );

texture.addEventListener( 'dispose', onTextureDispose );
Expand Down
12 changes: 11 additions & 1 deletion src/textures/Texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Texture extends EventDispatcher {
this.onUpdate = null;

this.isRenderTargetTexture = false; // indicates whether a texture belongs to a render target or not
this.needsPMREMUpdate = false; // indicates whether this texture should be processed by PMREMGenerator or not (only relevant for render target textures)
this.pmremVersion = 0; // indicates whether this texture should be processed by PMREMGenerator or not (only relevant for render target textures)

}

Expand Down Expand Up @@ -301,6 +301,16 @@ class Texture extends EventDispatcher {

}

set needsPMREMUpdate( value ) {

if ( value === true ) {

this.pmremVersion ++;

}

}

}

Texture.DEFAULT_IMAGE = null;
Expand Down