-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow changing the hdr tonemap, add pbr neutral tonemap
- Loading branch information
Showing
6 changed files
with
338 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,64 @@ | ||
/** | ||
* A tonemapping algorithm when rendering with high dynamic range. | ||
* | ||
* @enum {number} | ||
* @private | ||
* @enum {string} | ||
*/ | ||
const Tonemapper = { | ||
/** | ||
* Use the Reinhard tonemapping operator. | ||
* | ||
* @type {number} | ||
* @type {string} | ||
* @constant | ||
*/ | ||
REINHARD: 0, | ||
REINHARD: "REINHARD", | ||
|
||
/** | ||
* Use the modified Reinhard tonemapping operator. | ||
* | ||
* @type {number} | ||
* @type {string} | ||
* @constant | ||
*/ | ||
MODIFIED_REINHARD: 1, | ||
MODIFIED_REINHARD: "MODIFIED_REINHARD", | ||
|
||
/** | ||
* Use the Filmic tonemapping operator. | ||
* | ||
* @type {number} | ||
* @type {string} | ||
* @constant | ||
*/ | ||
FILMIC: 2, | ||
FILMIC: "FILMIC", | ||
|
||
/** | ||
* Use the ACES tonemapping operator. | ||
* | ||
* @type {number} | ||
* @type {string} | ||
* @constant | ||
*/ | ||
ACES: 3, | ||
ACES: "ACES", | ||
|
||
/** | ||
* @private | ||
* Use the PBRNeutral tonemapping operator. | ||
* | ||
* @type {string} | ||
* @constant | ||
*/ | ||
validate: function (tonemapper) { | ||
return ( | ||
tonemapper === Tonemapper.REINHARD || | ||
tonemapper === Tonemapper.MODIFIED_REINHARD || | ||
tonemapper === Tonemapper.FILMIC || | ||
tonemapper === Tonemapper.ACES | ||
); | ||
}, | ||
PBR_NEUTRAL: "PBR_NEUTRAL", | ||
}; | ||
|
||
/** | ||
* Validate whether the provided value is a known Tonemapper type | ||
* @private | ||
* | ||
* @param {string} tonemapper | ||
*/ | ||
export function validateToneMapper(tonemapper) { | ||
return ( | ||
tonemapper === Tonemapper.REINHARD || | ||
tonemapper === Tonemapper.MODIFIED_REINHARD || | ||
tonemapper === Tonemapper.FILMIC || | ||
tonemapper === Tonemapper.ACES || | ||
tonemapper === Tonemapper.PBR_NEUTRAL | ||
); | ||
} | ||
|
||
export default Object.freeze(Tonemapper); |
45 changes: 45 additions & 0 deletions
45
packages/engine/Source/Shaders/PostProcessStages/PBRNeutralTonemapping.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// KhronosGroup https://github.com/KhronosGroup/ToneMapping/tree/main/PBR_Neutral | ||
|
||
// Input color is non-negative and resides in the Linear Rec. 709 color space. | ||
// Output color is also Linear Rec. 709, but in the [0, 1] range. | ||
|
||
vec3 PBRNeutralToneMapping( vec3 color ) { | ||
const float startCompression = 0.8 - 0.04; | ||
const float desaturation = 0.15; | ||
|
||
float x = min(color.r, min(color.g, color.b)); | ||
float offset = x < 0.08 ? x - 6.25 * x * x : 0.04; | ||
color -= offset; | ||
|
||
float peak = max(color.r, max(color.g, color.b)); | ||
if (peak < startCompression) return color; | ||
|
||
const float d = 1.0 - startCompression; | ||
float newPeak = 1.0 - d * d / (peak + d - startCompression); | ||
color *= newPeak / peak; | ||
|
||
float g = 1.0 - 1.0 / (desaturation * (peak - newPeak) + 1.0); | ||
return mix(color, newPeak * vec3(1, 1, 1), g); | ||
} | ||
|
||
uniform sampler2D colorTexture; | ||
|
||
in vec2 v_textureCoordinates; | ||
|
||
#ifdef AUTO_EXPOSURE | ||
uniform sampler2D autoExposure; | ||
#endif | ||
|
||
void main() | ||
{ | ||
vec4 fragmentColor = texture(colorTexture, v_textureCoordinates); | ||
vec3 color = fragmentColor.rgb; | ||
|
||
#ifdef AUTO_EXPOSURE | ||
color /= texture(autoExposure, vec2(0.5)).r; | ||
#endif | ||
color = PBRNeutralToneMapping(color); | ||
color = czm_inverseGamma(color); | ||
|
||
out_FragColor = vec4(color, fragmentColor.a); | ||
} |
Oops, something went wrong.