updated picking
This commit is contained in:
parent
d96476d171
commit
a65ce42695
@ -55,7 +55,7 @@ uniform float attenuation;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
layout(location = 0)out vec4 outColor;
|
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){
|
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);
|
float diffuseComponent = max(dot(normal, lightDir), 0);
|
||||||
@ -119,12 +119,12 @@ void main(void) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INSTANCING
|
#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
|
#else
|
||||||
pickData = vec4(gl_FragCoord.z, gl_FragCoord.w, float(objectId), 0);
|
pickData = vec3(gl_FragCoord.z, gl_FragCoord.w, float(objectId));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef AMBIENT_LIGHT
|
#ifndef AMBIENT_LIGHT
|
||||||
pickData = vec4(0);
|
pickData = vec3(0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -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);
|
tex = new Texture(GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, width, height, GL_FLOAT, GL_TEXTURE_RECTANGLE);
|
||||||
frameBuffers[INPUT_FBO].addTexture(tex, GL_DEPTH_ATTACHMENT);
|
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();
|
frameBuffers[INPUT_FBO].initColorAttachments();
|
||||||
|
|
||||||
|
|
||||||
@ -122,10 +126,13 @@ void PostEffectModule::renderGL(Camera* myCamera, Scene* scene)
|
|||||||
|
|
||||||
glAssert(glBindVertexArray(vao));
|
glAssert(glBindVertexArray(vao));
|
||||||
|
|
||||||
|
// threasholding the luminance to isolate high luminance pixels for bloom
|
||||||
luminanceStep();
|
luminanceStep();
|
||||||
|
|
||||||
|
// blur the high luminance pixels
|
||||||
bloomStep();
|
bloomStep();
|
||||||
|
|
||||||
|
// compute average luminance and apply tonemapping
|
||||||
hdrStep();
|
hdrStep();
|
||||||
|
|
||||||
glAssert(glEnable(GL_DEPTH_TEST));
|
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 =
|
const std::string PostEffectModule::vertSource =
|
||||||
"layout(location = 0)in vec2 inPosition;\n\
|
"layout(location = 0)in vec2 inPosition;\n\
|
||||||
void main(void) {\n\
|
void main(void) {\n\
|
||||||
|
@ -81,6 +81,8 @@ public:
|
|||||||
void setRenderTarget(FrameBuffer* renderTarget) {outputFBO = renderTarget;}
|
void setRenderTarget(FrameBuffer* renderTarget) {outputFBO = renderTarget;}
|
||||||
|
|
||||||
void setBloomThreshold(float threshold) {bloom_threshold = threshold;}
|
void setBloomThreshold(float threshold) {bloom_threshold = threshold;}
|
||||||
|
|
||||||
|
glm::vec3 getObjectInfo(int x, int y);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // POSTEFFECTMODULE_H
|
#endif // POSTEFFECTMODULE_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user