HDR and Bloom working well
This commit is contained in:
parent
1b14d61bdc
commit
a25344dbaf
@ -15,11 +15,13 @@ layout(location = 1)out vec4 outColor;
|
|||||||
void main(void) {
|
void main(void) {
|
||||||
ivec2 ipos = ivec2(gl_FragCoord.xy);
|
ivec2 ipos = ivec2(gl_FragCoord.xy);
|
||||||
vec3 color = texelFetch(colorSampler, ipos).xyz;
|
vec3 color = texelFetch(colorSampler, ipos).xyz;
|
||||||
color += texelFetch(blurSampler0, ipos).xyz;
|
|
||||||
vec2 pos = vec2(gl_FragCoord.x/width, gl_FragCoord.y/height);
|
vec3 bloom = texelFetch(blurSampler0, ipos).xyz;
|
||||||
color += texture(blurSampler1, pos).xyz;
|
bloom += texture(blurSampler1, gl_FragCoord.xy/2).xyz;
|
||||||
color += texture(blurSampler2, pos).xyz;
|
bloom += texture(blurSampler2, gl_FragCoord.xy/4).xyz;
|
||||||
color += texture(blurSampler3, pos).xyz;
|
bloom += texture(blurSampler3, gl_FragCoord.xy/8).xyz;
|
||||||
outColor = vec4(color, 1.0);
|
|
||||||
|
color += bloom;
|
||||||
|
outColor = vec4(color + bloom*0.02f, 1.0);
|
||||||
minMaxMean = vec3(0.2126*color.r + 0.7152*color.g + 0.0722*color.b);
|
minMaxMean = vec3(0.2126*color.r + 0.7152*color.g + 0.0722*color.b);
|
||||||
}
|
}
|
||||||
|
@ -12,20 +12,17 @@ uniform int height;
|
|||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
//vec3 color = vec3(0);
|
vec3 color = texelFetch(colorSampler, ivec2(gl_FragCoord.xy)).xyz * 0.2270270270;
|
||||||
vec3 color = texelFetch(colorSampler, ivec2(gl_FragCoord.x/width, gl_FragCoord.y/height)).xyz * 0.2270270270;
|
|
||||||
#ifdef HORIZONTAL_BLUR
|
#ifdef HORIZONTAL_BLUR
|
||||||
float y = gl_FragCoord.y/height;
|
color += texture(colorSampler, vec2((gl_FragCoord.x + 1.3846153846), gl_FragCoord.y)).xyz * 0.3162162162;
|
||||||
color += texture(colorSampler, vec2((gl_FragCoord.x + 1.3846153846)/width, y)).xyz * 0.3162162162;
|
color += texture(colorSampler, vec2((gl_FragCoord.x - 1.3846153846), gl_FragCoord.y)).xyz * 0.3162162162;
|
||||||
color += texture(colorSampler, vec2((gl_FragCoord.x - 1.3846153846)/width, y)).xyz * 0.3162162162;
|
color += texture(colorSampler, vec2((gl_FragCoord.x + 3.2307692308), gl_FragCoord.y)).xyz * 0.0702702703;
|
||||||
color += texture(colorSampler, vec2((gl_FragCoord.x + 3.2307692308)/width, y)).xyz * 0.0702702703;
|
color += texture(colorSampler, vec2((gl_FragCoord.x - 3.2307692308), gl_FragCoord.y)).xyz * 0.0702702703;
|
||||||
color += texture(colorSampler, vec2((gl_FragCoord.x - 3.2307692308)/width, y)).xyz * 0.0702702703;
|
|
||||||
#else
|
#else
|
||||||
float x = gl_FragCoord.x/width;
|
color += texture(colorSampler, vec2(gl_FragCoord.x, (gl_FragCoord.y + 1.3846153846))).xyz * 0.3162162162;
|
||||||
color += texture(colorSampler, vec2(x, (gl_FragCoord.y + 1.3846153846)/height)).xyz * 0.3162162162;
|
color += texture(colorSampler, vec2(gl_FragCoord.x, (gl_FragCoord.y - 1.3846153846))).xyz * 0.3162162162;
|
||||||
color += texture(colorSampler, vec2(x, (gl_FragCoord.y - 1.3846153846)/height)).xyz * 0.3162162162;
|
color += texture(colorSampler, vec2(gl_FragCoord.x, (gl_FragCoord.y + 3.2307692308))).xyz * 0.0702702703;
|
||||||
color += texture(colorSampler, vec2(x, (gl_FragCoord.y + 3.2307692308)/height)).xyz * 0.0702702703;
|
color += texture(colorSampler, vec2(gl_FragCoord.x, (gl_FragCoord.y - 3.2307692308))).xyz * 0.0702702703;
|
||||||
color += texture(colorSampler, vec2(x, (gl_FragCoord.y - 3.2307692308)/height)).xyz * 0.0702702703;
|
|
||||||
#endif
|
#endif
|
||||||
outColor = vec4(color, 1.0);
|
outColor = vec4(color, 1.0);
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ void main(void) {
|
|||||||
|
|
||||||
#ifdef NORMAL_MAP
|
#ifdef NORMAL_MAP
|
||||||
vec3 normal = normalize(texture(normalMap, varTexCoord).xyz * tangentSpace);
|
vec3 normal = normalize(texture(normalMap, varTexCoord).xyz * tangentSpace);
|
||||||
normal = normalize(vec3(0, 0, 1) * tangentSpace);
|
//normal = normalize(vec3(0, 0, 1) * tangentSpace);
|
||||||
#else
|
#else
|
||||||
vec3 normal = normalize(varNormal);
|
vec3 normal = normalize(varNormal);
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,11 +2,20 @@
|
|||||||
|
|
||||||
uniform sampler2DRect colorSampler;
|
uniform sampler2DRect colorSampler;
|
||||||
|
|
||||||
uniform vec3 minMaxMean;
|
uniform float exposition;
|
||||||
|
uniform float gamma;
|
||||||
|
|
||||||
layout(location = 0)out vec4 outColor;
|
layout(location = 0)out vec4 outColor;
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
ivec2 pos = ivec2(gl_FragCoord.xy);
|
ivec2 pos = ivec2(gl_FragCoord.xy);
|
||||||
outColor = vec4(texelFetch(colorSampler, pos).xyz, 1.0);
|
vec3 color = texelFetch(colorSampler, pos).xyz;
|
||||||
|
|
||||||
|
// Exposure tone mapping
|
||||||
|
vec3 mapped = vec3(1.0) - exp(-color * 1);
|
||||||
|
|
||||||
|
// Gamma correction
|
||||||
|
mapped = pow(mapped, vec3(1.0 / gamma));
|
||||||
|
|
||||||
|
outColor = vec4(mapped, 1.0);
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ void Light::initShadowMap(int resWidth, int resHeight, glm::vec3 dim)
|
|||||||
shadowMap = new FrameBuffer();
|
shadowMap = new FrameBuffer();
|
||||||
// Depth buffer
|
// Depth buffer
|
||||||
Texture* tex = new Texture(GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, resWidth, resHeight, GL_FLOAT);
|
Texture* tex = new Texture(GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, resWidth, resHeight, GL_FLOAT);
|
||||||
tex->setFiltering(GL_NEAREST);
|
tex->setFiltering(GL_LINEAR);
|
||||||
shadowMap->addTexture(tex, GL_DEPTH_ATTACHMENT);
|
shadowMap->addTexture(tex, GL_DEPTH_ATTACHMENT);
|
||||||
shadowMap->initColorAttachments();
|
shadowMap->initColorAttachments();
|
||||||
|
|
||||||
|
@ -40,11 +40,12 @@ void PhongEntity::modernInit(bool isDynamic)
|
|||||||
vbo = new GLuint[nb_buffers]();
|
vbo = new GLuint[nb_buffers]();
|
||||||
glAssert(glGenBuffers(nb_buffers, vbo));
|
glAssert(glGenBuffers(nb_buffers, vbo));
|
||||||
|
|
||||||
for(const Mesh::Group &g : mesh->indiceGroups)
|
for(int i=0; i<mesh->indiceGroups.size(); ++i)
|
||||||
{
|
{
|
||||||
|
const Mesh::Group &g = mesh->indiceGroups[i];
|
||||||
// init indices vbos
|
// init indices vbos
|
||||||
glAssert(glBindBuffer(GL_ARRAY_BUFFER, vbo[INDICES_BUFFER]));
|
glAssert(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo[INDICES_BUFFERS + i]));
|
||||||
glAssert(glBufferData(GL_ARRAY_BUFFER, g.indices.size() * sizeof(GLuint), g.indices.data(), buffer_type));
|
glAssert(glBufferData(GL_ELEMENT_ARRAY_BUFFER, g.indices.size() * sizeof(GLuint), g.indices.data(), buffer_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
// init positions vbo
|
// init positions vbo
|
||||||
@ -144,7 +145,8 @@ void PhongEntity::drawGroup(int groupId, bool drawNormals, bool drawTexCoord, bo
|
|||||||
glAssert(glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, sizeof(Mesh::Tangents), BUFFER_OFFSET(sizeof(glm::vec3))));
|
glAssert(glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, sizeof(Mesh::Tangents), BUFFER_OFFSET(sizeof(glm::vec3))));
|
||||||
glAssert(glEnableVertexAttribArray(4));
|
glAssert(glEnableVertexAttribArray(4));
|
||||||
}
|
}
|
||||||
glAssert(glDrawElements(GL_TRIANGLES, mesh->indiceGroups[groupId].indices.size(), GL_UNSIGNED_INT, mesh->indiceGroups[groupId].indices.data()));
|
glAssert(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo[INDICES_BUFFERS + groupId]));
|
||||||
|
glAssert(glDrawElements(GL_TRIANGLES, mesh->indiceGroups[groupId].indices.size(), GL_UNSIGNED_INT, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhongEntity::drawDisplayList()
|
void PhongEntity::drawDisplayList()
|
||||||
|
@ -22,7 +22,7 @@ protected:
|
|||||||
// optionnal buffers :
|
// optionnal buffers :
|
||||||
NORMAL_BUFFER, TEXCOORD_BUFFER, TANGENT_BUFFER,
|
NORMAL_BUFFER, TEXCOORD_BUFFER, TANGENT_BUFFER,
|
||||||
// indices buffers
|
// indices buffers
|
||||||
INDICES_BUFFER
|
INDICES_BUFFERS
|
||||||
};
|
};
|
||||||
|
|
||||||
GLuint vao;
|
GLuint vao;
|
||||||
|
@ -178,6 +178,8 @@ void PostEffectModule::bloomStep()
|
|||||||
void PostEffectModule::hdrStep()
|
void PostEffectModule::hdrStep()
|
||||||
{
|
{
|
||||||
glm::vec3 minMaxMean = redux->redux();
|
glm::vec3 minMaxMean = redux->redux();
|
||||||
|
float exposition = 1/(2*minMaxMean.z);
|
||||||
|
float gamma = 2.2f;
|
||||||
|
|
||||||
glAssert(glViewport(0, 0, width, height));
|
glAssert(glViewport(0, 0, width, height));
|
||||||
|
|
||||||
@ -187,7 +189,8 @@ void PostEffectModule::hdrStep()
|
|||||||
|
|
||||||
shaders[HDR_SHADER]->bindInteger(shaders[HDR_SHADER]->getLocation("colorSampler"), 0);
|
shaders[HDR_SHADER]->bindInteger(shaders[HDR_SHADER]->getLocation("colorSampler"), 0);
|
||||||
frameBuffers[BLOOM_FBO].getTexture(1)->bind(0);
|
frameBuffers[BLOOM_FBO].getTexture(1)->bind(0);
|
||||||
shaders[HDR_SHADER]->bindVec3(shaders[HDR_SHADER]->getLocation("minMaxMean"), minMaxMean);
|
shaders[HDR_SHADER]->bindFloat(shaders[HDR_SHADER]->getLocation("exposition"), exposition);
|
||||||
|
shaders[HDR_SHADER]->bindFloat(shaders[HDR_SHADER]->getLocation("gamma"), gamma);
|
||||||
|
|
||||||
glAssert(glDrawArrays(GL_TRIANGLES, 0, 3));
|
glAssert(glDrawArrays(GL_TRIANGLES, 0, 3));
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ glm::vec3 TextureRedux::redux()
|
|||||||
bool inverted = false;
|
bool inverted = false;
|
||||||
int tempWidth = pong.getTexture(0)->getWidth();
|
int tempWidth = pong.getTexture(0)->getWidth();
|
||||||
int tempHeight = pong.getTexture(0)->getHeight();
|
int tempHeight = pong.getTexture(0)->getHeight();
|
||||||
while(tempWidth > 1 && tempHeight > 1)
|
while(!(tempWidth == 1 && tempHeight == 1))
|
||||||
{
|
{
|
||||||
m_shader->bind();
|
m_shader->bind();
|
||||||
m_shader->bindInteger(uniformLocations[SAMPLER], 0);
|
m_shader->bindInteger(uniformLocations[SAMPLER], 0);
|
||||||
@ -52,10 +52,15 @@ glm::vec3 TextureRedux::redux()
|
|||||||
}
|
}
|
||||||
tempWidth /= 2;
|
tempWidth /= 2;
|
||||||
tempHeight /= 2;
|
tempHeight /= 2;
|
||||||
|
if(tempWidth < 1)
|
||||||
|
tempWidth = 1;
|
||||||
|
if(tempHeight < 1)
|
||||||
|
tempHeight = 1;
|
||||||
glViewport(0, 0, tempWidth, tempHeight);
|
glViewport(0, 0, tempWidth, tempHeight);
|
||||||
glAssert(glDrawArrays(GL_TRIANGLES, 0, 3));
|
glAssert(glDrawArrays(GL_TRIANGLES, 0, 3));
|
||||||
|
inverted = !inverted;
|
||||||
}
|
}
|
||||||
glm::vec3 minMaxMean;
|
glm::vec3 minMaxMean;
|
||||||
glAssert(glReadPixels(0, 0, 0, 0, GL_RGB, GL_FLOAT, glm::value_ptr(minMaxMean)));
|
glAssert(glReadPixels(0, 0, 1, 1, GL_RGB, GL_FLOAT, glm::value_ptr(minMaxMean)));
|
||||||
return minMaxMean;
|
return minMaxMean;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user