Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
WestLangley committed Aug 7, 2024
1 parent 6ab3d7d commit d8994d2
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions src/nodes/display/ToneMappingNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,30 @@ import { NoToneMapping, LinearToneMapping, ReinhardToneMapping, CineonToneMappin
// exposure only
const LinearToneMappingNode = Fn( ( { color, exposure } ) => {

let c = vec3( color.rgb ).mul( exposure );

c = clamp( c, 0.0, 1.0 );

return vec4( c, color.a );
return color.mul( exposure ).clamp();

} );

// source: https://www.cs.utah.edu/docs/techreports/2002/pdf/UUCS-02-001.pdf
const ReinhardToneMappingNode = Fn( ( { color, exposure } ) => {

let c = vec3( color.rgb ).mul( exposure );

c = c.div( c.add( 1.0 ) );
color = color.mul( exposure );

return vec4( c, color.a );
return color.div( color.add( 1.0 ) ).clamp();

} );

// source: http://filmicworlds.com/blog/filmic-tonemapping-operators/
const OptimizedCineonToneMappingNode = Fn( ( { color, exposure } ) => {

// optimized filmic operator by Jim Hejl and Richard Burgess-Dawson
let c = vec3( color.rgb ).mul( exposure );

c = c.sub( 0.004 ).max( 0.0 );

const a = c.mul( c.mul( 6.2 ).add( 0.5 ) );
const b = c.mul( c.mul( 6.2 ).add( 1.7 ) ).add( 0.06 );
color = color.mul( exposure );
color = color.sub( 0.004 ).max( 0.0 );

c = a.div( b ).pow( 2.2 );
const a = color.mul( color.mul( 6.2 ).add( 0.5 ) );
const b = color.mul( color.mul( 6.2 ).add( 1.7 ) ).add( 0.06 );

return vec4( c, color.a );
return a.div( b ).pow( 2.2 );

} );

Expand Down Expand Up @@ -123,7 +114,7 @@ const AGXToneMappingNode = Fn( ( { color, exposure } ) => {
colortone.assign( LINEAR_REC2020_TO_LINEAR_SRGB.mul( colortone ) );
colortone.assign( clamp( colortone, 0.0, 1.0 ) );

return vec4( colortone, color.a );
return colortone;

} );

Expand Down Expand Up @@ -203,14 +194,14 @@ class ToneMappingNode extends TempNode {

if ( toneMapping === NoToneMapping ) return colorNode;

const toneMappingParams = { exposure: this.exposureNode, color: colorNode };
const toneMappingParams = { exposure: this.exposureNode, color: colorNode.rgb };
const toneMappingNode = toneMappingLib[ toneMapping ];

let outputNode = null;

if ( toneMappingNode ) {

outputNode = toneMappingNode( toneMappingParams );
outputNode = vec4( toneMappingNode( toneMappingParams ), colorNode.a );

} else {

Expand Down

0 comments on commit d8994d2

Please sign in to comment.