From 9d603fe5d9a700348969e7bb9e79b384c8f65490 Mon Sep 17 00:00:00 2001 From: yvt Date: Sat, 20 Jun 2015 18:32:30 +0900 Subject: [PATCH] HDR Renderer: gamma correction --- Resources/Shaders/PostFilters/Nonlinearize.fs | 4 +++- Sources/Draw/GLNonlinearizeFilter.cpp | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Resources/Shaders/PostFilters/Nonlinearize.fs b/Resources/Shaders/PostFilters/Nonlinearize.fs index 1aabc5a0..fee3430c 100644 --- a/Resources/Shaders/PostFilters/Nonlinearize.fs +++ b/Resources/Shaders/PostFilters/Nonlinearize.fs @@ -23,10 +23,12 @@ uniform sampler2D texture; varying vec2 texCoord; +uniform float gamma; + void main() { vec3 color; color = texture2D(texture, texCoord).xyz; - color = sqrt(color); + color = pow(color, vec3(gamma)); gl_FragColor = vec4(color, 1.); } diff --git a/Sources/Draw/GLNonlinearizeFilter.cpp b/Sources/Draw/GLNonlinearizeFilter.cpp index 853b0f18..0512dc40 100644 --- a/Sources/Draw/GLNonlinearizeFilter.cpp +++ b/Sources/Draw/GLNonlinearizeFilter.cpp @@ -31,6 +31,8 @@ #include "../Core/Debug.h" #include +SPADES_SETTING(r_hdrGamma, "2.2"); + namespace spades { namespace draw { GLNonlinearlizeFilter::GLNonlinearlizeFilter(GLRenderer *renderer): @@ -45,15 +47,18 @@ namespace spades { static GLProgramAttribute lensPosition("positionAttribute"); static GLProgramUniform lensTexture("texture"); + static GLProgramUniform lensGamma("gamma"); dev->Enable(IGLDevice::Blend, false); lensPosition(lens); lensTexture(lens); + lensGamma(lens); lens->Use(); lensTexture.SetValue(0); + lensGamma.SetValue(1.f / (float)r_hdrGamma); // composite to the final image GLColorBuffer output = input.GetManager()->CreateBufferHandle();