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

Nodes: Only use PMREM for background when blurriness is configured. #29089

Merged
merged 4 commits into from
Aug 8, 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
Binary file modified examples/screenshots/webgpu_clearcoat.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgpu_cubemap_adjustments.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgpu_cubemap_dynamic.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgpu_lightprobe.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgpu_loader_gltf.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgpu_loader_gltf_iridescence.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgpu_loader_gltf_sheen.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgpu_loader_materialx.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgpu_materials_basic.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgpu_materials_envmaps.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgpu_materials_transmission.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgpu_mrt.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgpu_parallax_uv.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgpu_postprocessing_3dlut.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/renderers/common/CubeRenderTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,14 @@ class CubeRenderTarget extends WebGLCubeRenderTarget {
if ( texture.minFilter === LinearMipmapLinearFilter ) texture.minFilter = LinearFilter;

const camera = new CubeCamera( 1, 10, this );

const currentMRT = renderer.getMRT();
renderer.setMRT( null );

camera.update( renderer, scene );
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CubeCamera.update() isn't MRT compatible so I fixed CubeRenderTarget here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have renderer state definition and restoration in many places, I was thinking about having a way to automate this otherwise every new feature related will break the chain of nodes that use beforeUpdate() to render().


renderer.setMRT( currentMRT );

texture.minFilter = currentMinFilter;
texture.currentGenerateMipmaps = currentGenerateMipmaps;

Expand Down
28 changes: 26 additions & 2 deletions src/renderers/common/nodes/Nodes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import DataMap from '../DataMap.js';
import ChainMap from '../ChainMap.js';
import NodeBuilderState from './NodeBuilderState.js';
import { cubeMapNode } from '../../../nodes/utils/CubeMapNode.js';
import { NodeFrame, objectGroup, renderGroup, frameGroup, cubeTexture, texture, rangeFog, densityFog, reference, viewportBottomLeft, normalWorld, pmremTexture, viewportTopLeft } from '../../../nodes/Nodes.js';

import { EquirectangularReflectionMapping, EquirectangularRefractionMapping } from '../../../constants.js';
Expand Down Expand Up @@ -264,13 +265,35 @@ class Nodes extends DataMap {

if ( background ) {

if ( sceneData.background !== background ) {
const forceUpdate = ( scene.backgroundBlurriness === 0 && sceneData.backgroundBlurriness > 0 ) || ( scene.backgroundBlurriness > 0 && sceneData.backgroundBlurriness === 0 );

if ( sceneData.background !== background || forceUpdate ) {

let backgroundNode = null;

if ( background.isCubeTexture === true || ( background.mapping === EquirectangularReflectionMapping || background.mapping === EquirectangularRefractionMapping ) ) {

backgroundNode = pmremTexture( background, normalWorld );
if ( scene.backgroundBlurriness > 0 ) {

backgroundNode = pmremTexture( background, normalWorld );

} else {

let envMap;

if ( background.isCubeTexture === true ) {

envMap = cubeTexture( background );

} else {

envMap = texture( background );

}

backgroundNode = cubeMapNode( envMap );

}

} else if ( background.isTexture === true ) {

Expand All @@ -284,6 +307,7 @@ class Nodes extends DataMap {

sceneData.backgroundNode = backgroundNode;
sceneData.background = background;
sceneData.backgroundBlurriness = scene.backgroundBlurriness;

}

Expand Down