Skip to content

Commit

Permalink
HDR: use constant exposure.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpcy committed Jul 7, 2016
1 parent e436b85 commit 717c950
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion code/renderer_bgfx/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ void Main::renderScene(const SceneDefinition &scene)
Clamped(g_cvars.saturation.getFloat(), 0.0f, 3.0f)
));

uniforms_->hdrKey.set(vec4(Clamped(g_cvars.hdrKey.getFloat(), 0.01f, 0.2f), 0, 0, 0));
uniforms_->hdrExposure.set(vec4(g_cvars.hdrExposure.getFloat(), 0, 0, 0));
bgfx::setTexture(0, uniforms_->textureSampler.handle, sceneFb_.handle, SceneFrameBufferAttachment::Color);
bgfx::setTexture(1, uniforms_->adaptedLuminanceSampler.handle, adaptedLuminanceFB_[currentAdaptedLuminanceFB_].handle);
renderScreenSpaceQuad(aa_ == AntiAliasing::None ? defaultFb_ : sceneTempFb_, ShaderProgramId::ToneMap, BGFX_STATE_RGB_WRITE, BGFX_CLEAR_NONE, isTextureOriginBottomLeft_);
Expand Down
2 changes: 1 addition & 1 deletion code/renderer_bgfx/Main_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void ConsoleVariables::initialize()
dynamicLightIntensity = interface::Cvar_Get("r_dynamicLightIntensity", "1", ConsoleVariableFlags::Archive);
dynamicLightScale = interface::Cvar_Get("r_dynamicLightScale", "0.7", ConsoleVariableFlags::Archive);
hdr = interface::Cvar_Get("r_hdr", "0", ConsoleVariableFlags::Archive | ConsoleVariableFlags::Latch);
hdrKey = interface::Cvar_Get("r_hdrKey", "0.1", ConsoleVariableFlags::Archive);
hdrExposure = interface::Cvar_Get("r_hdrExposure", "0.7", ConsoleVariableFlags::Archive);
lerpTextureAnimation = interface::Cvar_Get("r_lerpTextureAnimation", "1", ConsoleVariableFlags::Archive | ConsoleVariableFlags::Latch);
maxAnisotropy = interface::Cvar_Get("r_maxAnisotropy", "0", ConsoleVariableFlags::Archive | ConsoleVariableFlags::Latch);
picmip = interface::Cvar_Get("r_picmip", "0", ConsoleVariableFlags::Archive | ConsoleVariableFlags::Latch);
Expand Down
4 changes: 2 additions & 2 deletions code/renderer_bgfx/Precompiled.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ struct ConsoleVariables
ConsoleVariable dynamicLightIntensity;
ConsoleVariable dynamicLightScale;
ConsoleVariable hdr;
ConsoleVariable hdrKey;
ConsoleVariable hdrExposure;
ConsoleVariable lerpTextureAnimation;
ConsoleVariable maxAnisotropy;
ConsoleVariable picmip;
Expand Down Expand Up @@ -1388,7 +1388,7 @@ struct Uniforms
Uniform_vec4 brightnessContrastGammaSaturation = "u_BrightnessContrastGammaSaturation";

/// @remarks Only x used.
Uniform_vec4 hdrKey = "u_HdrKey";
Uniform_vec4 hdrExposure = "u_HdrExposure";
/// @}

/// @name Texture samplers
Expand Down
5 changes: 2 additions & 3 deletions shaders/ToneMap_fragment.sc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ uniform vec4 u_BrightnessContrastGammaSaturation;
#define gamma u_BrightnessContrastGammaSaturation.z
#define saturation u_BrightnessContrastGammaSaturation.w

uniform vec4 u_HdrKey; // only x used
uniform vec4 u_HdrExposure; // only x used

// https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/
vec3 ACESFilm(vec3 x)
Expand All @@ -30,8 +30,7 @@ void main()
vec3 color = texture2D(u_TextureSampler, v_texcoord0).rgb;

// tone map
color *= u_HdrKey.x / (texture2D(u_AdaptedLuminanceSampler, vec2_splat(0.0)).r + 0.001);
color = ACESFilm(color);
color = ACESFilm(color * u_HdrExposure.x);

// contrast and brightness
color = (color - 0.5) * contrast + 0.5 + brightness;
Expand Down

0 comments on commit 717c950

Please sign in to comment.