updated picking

This commit is contained in:
Anselme 2016-03-07 13:06:52 +01:00
parent d96476d171
commit a65ce42695
3 changed files with 24 additions and 4 deletions

View File

@ -55,7 +55,7 @@ uniform float attenuation;
#endif
layout(location = 0)out vec4 outColor;
layout(location = 1)out vec4 pickData;
layout(location = 1)out vec3 pickData;
vec3 phongLighting(in vec3 kd, in vec3 ks, in float ns, in vec3 color, in vec3 normal, in vec3 lightDir, in vec3 halfVec){
float diffuseComponent = max(dot(normal, lightDir), 0);
@ -119,12 +119,12 @@ void main(void) {
#endif
#ifdef INSTANCING
pickData = vec4(gl_FragCoord.z, gl_FragCoord.w, float(int(objectId) + instanceId), 0);
pickData = vec3(gl_FragCoord.z, gl_FragCoord.w, float(int(objectId) + instanceId));
#else
pickData = vec4(gl_FragCoord.z, gl_FragCoord.w, float(objectId), 0);
pickData = vec3(gl_FragCoord.z, gl_FragCoord.w, float(objectId));
#endif
#ifndef AMBIENT_LIGHT
pickData = vec4(0);
pickData = vec3(0);
#endif
}

View File

@ -72,6 +72,10 @@ void PostEffectModule::resize(int w, int h)
tex = new Texture(GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, width, height, GL_FLOAT, GL_TEXTURE_RECTANGLE);
frameBuffers[INPUT_FBO].addTexture(tex, GL_DEPTH_ATTACHMENT);
// Picking texture
tex = new Texture(GL_RGB, GL_RGB32F, width, height, GL_FLOAT, GL_TEXTURE_RECTANGLE);
frameBuffers[INPUT_FBO].addTexture(tex, GL_COLOR_ATTACHMENT1);
frameBuffers[INPUT_FBO].initColorAttachments();
@ -122,10 +126,13 @@ void PostEffectModule::renderGL(Camera* myCamera, Scene* scene)
glAssert(glBindVertexArray(vao));
// threasholding the luminance to isolate high luminance pixels for bloom
luminanceStep();
// blur the high luminance pixels
bloomStep();
// compute average luminance and apply tonemapping
hdrStep();
glAssert(glEnable(GL_DEPTH_TEST));
@ -218,6 +225,17 @@ void PostEffectModule::setShaders(const std::string &luminanceFragSource,
}
glm::vec3 PostEffectModule::getObjectInfo(int x, int y)
{
fbo->getTexture(1)->bind(0);
glm::vec3 *val = new glm::vec3[w*h];
glAssert(glGetTexImage(GL_TEXTURE_RECTANGLE, 0, GL_RGB, GL_FLOAT, val));
glm::vec3 ret = val[x + (h-y)*w];
ret.z -= 1; // clearColor compensation
delete[] val;
return ret;
}
const std::string PostEffectModule::vertSource =
"layout(location = 0)in vec2 inPosition;\n\
void main(void) {\n\

View File

@ -81,6 +81,8 @@ public:
void setRenderTarget(FrameBuffer* renderTarget) {outputFBO = renderTarget;}
void setBloomThreshold(float threshold) {bloom_threshold = threshold;}
glm::vec3 getObjectInfo(int x, int y);
};
#endif // POSTEFFECTMODULE_H