HDR Renderer: gamma correction

This commit is contained in:
yvt 2015-06-20 18:32:30 +09:00
parent 1ca429ffba
commit 9d603fe5d9
2 changed files with 8 additions and 1 deletions

View File

@ -23,10 +23,12 @@ uniform sampler2D texture;
varying vec2 texCoord; varying vec2 texCoord;
uniform float gamma;
void main() { void main() {
vec3 color; vec3 color;
color = texture2D(texture, texCoord).xyz; color = texture2D(texture, texCoord).xyz;
color = sqrt(color); color = pow(color, vec3(gamma));
gl_FragColor = vec4(color, 1.); gl_FragColor = vec4(color, 1.);
} }

View File

@ -31,6 +31,8 @@
#include "../Core/Debug.h" #include "../Core/Debug.h"
#include <Core/Settings.h> #include <Core/Settings.h>
SPADES_SETTING(r_hdrGamma, "2.2");
namespace spades { namespace spades {
namespace draw { namespace draw {
GLNonlinearlizeFilter::GLNonlinearlizeFilter(GLRenderer *renderer): GLNonlinearlizeFilter::GLNonlinearlizeFilter(GLRenderer *renderer):
@ -45,15 +47,18 @@ namespace spades {
static GLProgramAttribute lensPosition("positionAttribute"); static GLProgramAttribute lensPosition("positionAttribute");
static GLProgramUniform lensTexture("texture"); static GLProgramUniform lensTexture("texture");
static GLProgramUniform lensGamma("gamma");
dev->Enable(IGLDevice::Blend, false); dev->Enable(IGLDevice::Blend, false);
lensPosition(lens); lensPosition(lens);
lensTexture(lens); lensTexture(lens);
lensGamma(lens);
lens->Use(); lens->Use();
lensTexture.SetValue(0); lensTexture.SetValue(0);
lensGamma.SetValue(1.f / (float)r_hdrGamma);
// composite to the final image // composite to the final image
GLColorBuffer output = input.GetManager()->CreateBufferHandle(); GLColorBuffer output = input.GetManager()->CreateBufferHandle();