Skip to content

WebGPURenderer: Apply fog before tonemapping and encoding#27850

Merged
sunag merged 13 commits into
mrdoob:devfrom
sunag:dev-apply-fog
Mar 13, 2024
Merged

WebGPURenderer: Apply fog before tonemapping and encoding#27850
sunag merged 13 commits into
mrdoob:devfrom
sunag:dev-apply-fog

Conversation

@sunag

@sunag sunag commented Feb 29, 2024

Copy link
Copy Markdown
Collaborator

Related: #26857

@mrdoob Do you think we can advance this implementation in WebGPURenderer? it seems important to add transmission in this architecture.

@sunag

sunag commented Mar 3, 2024

Copy link
Copy Markdown
Collaborator Author

I created an example of how we can solve this in TSL without needing a transparent background.

// render scene pass ( the same of css )
const scenePass = pass( scene, camera );
const scenePassViewZ = scenePass.getViewZNode();

// background color
const backgroundColor = color( 0x0066ff );

// get fog factor from scene pass context
// equivalent to: scene.fog = new THREE.Fog( 0x0066ff, 2.5, 4 );
const fogFactor = rangeFog( backgroundColor, 2.5, 4 ).context( { viewZ: scenePassViewZ } );

// tone mapping scene pass
const scenePassTM = scenePass.toneMapping( THREE.ACESFilmicToneMapping );

// mix fog from fog factor and background color
const compose = fogFactor.mix( scenePassTM, backgroundColor );

postProcessing = new PostProcessing( renderer );
postProcessing.outputNode = compose;

image

/cc @donmccurdy @Mugen87 @LeviPesin

@sunag sunag added this to the r163 milestone Mar 3, 2024

}

getViewZNode() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe we can do these just as getters? I.e. something like get viewZ(), get depth() instead of getViewZNode(), getDepthNode()?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think it's a good idea move to getters, I just will add *Node suffix.

export const toneMapping = ( mapping, exposure, color ) => nodeObject( new ToneMappingNode( mapping, nodeObject( exposure ), nodeObject( color ) ) );
export const toneMappingExposure = rendererReference( 'toneMappingExposure', 'float' );

addNodeElement( 'toneMapping', ( color, mapping, exposure ) => toneMapping( mapping, exposure, color ) );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this may be quite confusing...

@mrdoob

mrdoob commented Mar 12, 2024

Copy link
Copy Markdown
Owner

@mrdoob Do you think we can advance this implementation in WebGPURenderer? it seems important to add transmission in this architecture.

Sounds good yep!

@sunag sunag marked this pull request as ready for review March 13, 2024 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants