Skip to content

Commit

Permalink
change default tonemap when HDR is off
Browse files Browse the repository at this point in the history
  • Loading branch information
jjspace committed Aug 28, 2024
1 parent f75cc7a commit 517884f
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 40 deletions.
6 changes: 3 additions & 3 deletions packages/engine/Source/Scene/PostProcessStageCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import TextureWrap from "../Renderer/TextureWrap.js";
import PassThrough from "../Shaders/PostProcessStages/PassThrough.js";
import PostProcessStageLibrary from "./PostProcessStageLibrary.js";
import PostProcessStageTextureCache from "./PostProcessStageTextureCache.js";
import Tonemapper, { validateToneMapper } from "./Tonemapper.js";
import Tonemapper, { validateTonemapper } from "./Tonemapper.js";

const stackScratch = [];

Expand Down Expand Up @@ -327,7 +327,7 @@ Object.defineProperties(PostProcessStageCollection.prototype, {
return;
}
//>>includeStart('debug', pragmas.debug);
if (!validateToneMapper(value)) {
if (!validateTonemapper(value)) {
throw new DeveloperError("tonemapper was set to an invalid value.");
}
//>>includeEnd('debug');
Expand Down Expand Up @@ -357,7 +357,7 @@ Object.defineProperties(PostProcessStageCollection.prototype, {
);
break;
case Tonemapper.PBR_NEUTRAL:
tonemapping = PostProcessStageLibrary.createPBRNeutralTonemappingStage(
tonemapping = PostProcessStageLibrary.createPbrNeutralTonemappingStage(
useAutoExposure
);
break;
Expand Down
6 changes: 3 additions & 3 deletions packages/engine/Source/Scene/PostProcessStageLibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import DepthOfField from "../Shaders/PostProcessStages/DepthOfField.js";
import DepthView from "../Shaders/PostProcessStages/DepthView.js";
import EdgeDetection from "../Shaders/PostProcessStages/EdgeDetection.js";
import FilmicTonemapping from "../Shaders/PostProcessStages/FilmicTonemapping.js";
import PBRNeutralTonemapping from "../Shaders/PostProcessStages/PBRNeutralTonemapping.js";
import PbrNeutralTonemapping from "../Shaders/PostProcessStages/PbrNeutralTonemapping.js";
import FXAA from "../Shaders/PostProcessStages/FXAA.js";
import GaussianBlur1D from "../Shaders/PostProcessStages/GaussianBlur1D.js";
import LensFlare from "../Shaders/PostProcessStages/LensFlare.js";
Expand Down Expand Up @@ -700,11 +700,11 @@ PostProcessStageLibrary.createFilmicTonemappingStage = function (
* @return {PostProcessStage} A post-process stage that applies filmic tonemapping operator.
* @private
*/
PostProcessStageLibrary.createPBRNeutralTonemappingStage = function (
PostProcessStageLibrary.createPbrNeutralTonemappingStage = function (
useAutoExposure
) {
let fs = useAutoExposure ? "#define AUTO_EXPOSURE\n" : "";
fs += PBRNeutralTonemapping;
fs += PbrNeutralTonemapping;
return new PostProcessStage({
name: "czm_pbr_neutral",
fragmentShader: fs,
Expand Down
12 changes: 6 additions & 6 deletions packages/engine/Source/Scene/Tonemapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,39 @@
*/
const Tonemapper = {
/**
* Use the Reinhard tonemapping operator.
* Use the Reinhard tonemapping.
*
* @type {string}
* @constant
*/
REINHARD: "REINHARD",

/**
* Use the modified Reinhard tonemapping operator.
* Use the modified Reinhard tonemapping.
*
* @type {string}
* @constant
*/
MODIFIED_REINHARD: "MODIFIED_REINHARD",

/**
* Use the Filmic tonemapping operator.
* Use the Filmic tonemapping.
*
* @type {string}
* @constant
*/
FILMIC: "FILMIC",

/**
* Use the ACES tonemapping operator.
* Use the ACES tonemapping.
*
* @type {string}
* @constant
*/
ACES: "ACES",

/**
* Use the PBRNeutral tonemapping operator.
* Use the PbrNeutral tonemapping from Khronos.
*
* @type {string}
* @constant
Expand All @@ -51,7 +51,7 @@ const Tonemapper = {
*
* @param {string} tonemapper
*/
export function validateToneMapper(tonemapper) {
export function validateTonemapper(tonemapper) {
return (
tonemapper === Tonemapper.REINHARD ||
tonemapper === Tonemapper.MODIFIED_REINHARD ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// 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 ) {
vec3 czm_pbrNeutralTonemapping( vec3 color ) {
const float startCompression = 0.8 - 0.04;
const float desaturation = 0.15;

Expand All @@ -21,25 +21,3 @@ vec3 PBRNeutralToneMapping( vec3 color ) {
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);
}
4 changes: 2 additions & 2 deletions packages/engine/Source/Shaders/GlobeFS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ void main()
#ifdef ENABLE_CLIPPING_POLYGONS
vec2 clippingPosition = v_clippingPosition;
int regionIndex = v_regionIndex;
clipPolygons(u_clippingDistance, CLIPPING_POLYGON_REGIONS_LENGTH, clippingPosition, regionIndex);
clipPolygons(u_clippingDistance, CLIPPING_POLYGON_REGIONS_LENGTH, clippingPosition, regionIndex);
#endif

#ifdef HIGHLIGHT_FILL_TILE
Expand Down Expand Up @@ -489,7 +489,7 @@ void main()
#endif

#ifndef HDR
fogColor.rgb = czm_acesTonemapping(fogColor.rgb);
fogColor.rgb = czm_pbrNeutralTonemapping(fogColor.rgb);
fogColor.rgb = czm_inverseGamma(fogColor.rgb);
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void applyFog(inout vec4 color, vec4 groundAtmosphereColor, vec3 lightDirection,

// Tonemap if HDR rendering is disabled
#ifndef HDR
fogColor.rgb = czm_acesTonemapping(fogColor.rgb);
fogColor.rgb = czm_pbrNeutralTonemapping(fogColor.rgb);
fogColor.rgb = czm_inverseGamma(fogColor.rgb);
#endif

Expand Down
2 changes: 1 addition & 1 deletion packages/engine/Source/Shaders/Model/LightingStageFS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void lightingStage(inout czm_modelMaterial material, ProcessedAttributes attribu
// tonemapping. However, if HDR is not enabled, we must tonemap else large
// values may be clamped to 1.0
#ifndef HDR
color = czm_acesTonemapping(color);
color = czm_pbrNeutralTonemapping(color);
#endif
#else // unlit
vec3 color = material.diffuse;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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 = czm_pbrNeutralTonemapping(color);
color = czm_inverseGamma(color);

out_FragColor = vec4(color, fragmentColor.a);
}
2 changes: 1 addition & 1 deletion packages/engine/Source/Shaders/SkyAtmosphereFS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void main (void)
vec4 color = computeAtmosphereColor(v_outerPositionWC, lightDirection, rayleighColor, mieColor, opacity);

#ifndef HDR
color.rgb = czm_acesTonemapping(color.rgb);
color.rgb = czm_pbrNeutralTonemapping(color.rgb);
color.rgb = czm_inverseGamma(color.rgb);
#endif

Expand Down

0 comments on commit 517884f

Please sign in to comment.