Skip to content

Commit

Permalink
Adjust channel index calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
mjurczyk committed Jul 10, 2024
1 parent e14d2b1 commit 09fb705
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions examples/jsm/loaders/UltraHDRLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,11 @@ class UltraHDRLoader extends Loader {
const x = ( pixelIndex / 4 ) % sdrImage.width;
const y = Math.floor( pixelIndex / 4 / sdrImage.width );

for ( let index = pixelIndex; index < pixelIndex + 3; index ++ ) {
for ( let channelIndex = 0; channelIndex < 3; channelIndex ++ ) {

const sdrValue = sdrImageData.data[ index ];
const sdrValue = sdrImageData.data[ pixelIndex + channelIndex ];

const gainmapIndex = ( y * sdrImage.width + x ) * 4;
const gainmapIndex = ( y * sdrImage.width + x ) * 4 + channelIndex;
const gainmapValue = gainmapImageData.data[ gainmapIndex ] / 255.0;

/* Gamma is 1.0 by default */
Expand All @@ -547,28 +547,25 @@ class UltraHDRLoader extends Loader {
: Math.pow( gainmapValue, 1.0 / xmpMetadata.gamma );

const logBoost =
xmpMetadata.gainMapMin * ( 1.0 - logRecovery ) +
xmpMetadata.gainMapMax * logRecovery;
xmpMetadata.gainMapMin * ( 1.0 - logRecovery ) +
xmpMetadata.gainMapMax * logRecovery;

const hdrValue =
( sdrValue + xmpMetadata.offsetSDR ) *
( logBoost * weightFactor === 0.0
? 1.0
: Math.pow( 2, logBoost * weightFactor ) ) -
xmpMetadata.offsetHDR;
( logBoost * weightFactor === 0.0
? 1.0
: Math.pow( 2, logBoost * weightFactor ) ) -
xmpMetadata.offsetHDR;

const linearHDRValue = Math.min(
Math.max(
this._srgbToLinear( hdrValue ),
0
),
Math.max( this._srgbToLinear( hdrValue ), 0 ),
65504
);

hdrBuffer[ index ] =
this.type === HalfFloatType
? DataUtils.toHalfFloat( linearHDRValue )
: linearHDRValue;
hdrBuffer[ pixelIndex + channelIndex ] =
this.type === HalfFloatType
? DataUtils.toHalfFloat( linearHDRValue )
: linearHDRValue;

}

Expand All @@ -589,4 +586,4 @@ class UltraHDRLoader extends Loader {

}

export { UltraHDRLoader };
export { UltraHDRLoader };

0 comments on commit 09fb705

Please sign in to comment.