added picking
This commit is contained in:
parent
44efb383a9
commit
cb4b696e12
@ -1,11 +1,11 @@
|
||||
// - Normal buffer
|
||||
layout (location = 0) out vec3 outNormal;
|
||||
// - Position in view space
|
||||
layout (location = 0) out vec4 outPosition;
|
||||
// - Color + objectId buffer
|
||||
layout (location = 1) out vec4 outColor;
|
||||
// - Normal buffer
|
||||
layout (location = 2) out vec3 outNormal;
|
||||
// - Specular color + Specular exponent buffer
|
||||
layout (location = 2) out vec4 outSpecular;
|
||||
// - Position in view space
|
||||
layout (location = 3) out vec4 outPosition;
|
||||
layout (location = 3) out vec4 outSpecular;
|
||||
|
||||
uniform float materialNs;
|
||||
|
||||
@ -69,7 +69,11 @@ void main()
|
||||
outColor.rgb = materialKd;
|
||||
#endif
|
||||
|
||||
#ifdef INSTANCED
|
||||
outColor.a = float(object_identifier+instanceId)/255;
|
||||
#else
|
||||
outColor.a = float(object_identifier)/255;
|
||||
#endif
|
||||
|
||||
#ifdef SPECULAR_TEXTURE
|
||||
outSpecular.rgb = texture(specularTexture, varTexCoord).rgb;
|
||||
|
@ -1,13 +1,13 @@
|
||||
// G-BUFFER
|
||||
|
||||
// - Normal buffer
|
||||
uniform sampler2DRect normalBuffer;
|
||||
// - Color + objectId buffer
|
||||
uniform sampler2DRect colorBuffer;
|
||||
// - Specular color + Specular exponent buffer
|
||||
uniform sampler2DRect specularBuffer;
|
||||
// - Position in view space
|
||||
uniform sampler2DRect positionBuffer;
|
||||
// - Color + objectId buffer
|
||||
uniform sampler2DRect colorBuffer;
|
||||
// - Normal buffer
|
||||
uniform sampler2DRect normalBuffer;
|
||||
// - Specular color + Specular exponent buffer
|
||||
uniform sampler2DRect specularBuffer;
|
||||
// - depth buffer
|
||||
uniform sampler2DRect depthBuffer;
|
||||
|
||||
|
@ -15,10 +15,11 @@ RESOURCE_PACK(shaders)
|
||||
GBuffer::GBuffer(int width, int height) : FrameBuffer()
|
||||
{
|
||||
Texture* tex;
|
||||
// - Normal buffer
|
||||
tex = new Texture(GL_RGB, GL_RGB16F, width, height, GL_FLOAT, GL_TEXTURE_RECTANGLE);
|
||||
|
||||
// - Position buffer
|
||||
tex = new Texture(GL_RGBA, GL_RGBA16F, width, height, GL_FLOAT, GL_TEXTURE_RECTANGLE);
|
||||
tex->setFiltering(GL_NEAREST);
|
||||
tex->setUnit(NORMAL);
|
||||
tex->setUnit(POSITION);
|
||||
addTexture(tex, GL_COLOR_ATTACHMENT0);
|
||||
|
||||
// - Color + objectId buffer
|
||||
@ -27,16 +28,16 @@ GBuffer::GBuffer(int width, int height) : FrameBuffer()
|
||||
tex->setUnit(DIFFUSE);
|
||||
addTexture(tex, GL_COLOR_ATTACHMENT1);
|
||||
|
||||
// - Normal buffer
|
||||
tex = new Texture(GL_RGB, GL_RGB16F, width, height, GL_FLOAT, GL_TEXTURE_RECTANGLE);
|
||||
tex->setFiltering(GL_NEAREST);
|
||||
tex->setUnit(NORMAL);
|
||||
addTexture(tex, GL_COLOR_ATTACHMENT2);
|
||||
|
||||
// - Specular color + Specular exponent buffer
|
||||
tex = new Texture(GL_RGBA, GL_RGBA, width, height, GL_UNSIGNED_BYTE, GL_TEXTURE_RECTANGLE);
|
||||
tex->setFiltering(GL_NEAREST);
|
||||
tex->setUnit(SPECULAR);
|
||||
addTexture(tex, GL_COLOR_ATTACHMENT2);
|
||||
|
||||
// - Position buffer
|
||||
tex = new Texture(GL_RGBA, GL_RGBA16F, width, height, GL_FLOAT, GL_TEXTURE_RECTANGLE);
|
||||
tex->setFiltering(GL_NEAREST);
|
||||
tex->setUnit(POSITION);
|
||||
addTexture(tex, GL_COLOR_ATTACHMENT3);
|
||||
|
||||
// - depth buffer
|
||||
@ -163,10 +164,10 @@ void DeferredPipeline::renderGL(Scene *scene)
|
||||
shader->bind();
|
||||
|
||||
// bind GBuffer
|
||||
shader->bindInteger(shader->getLocation("normalBuffer"), GBuffer::NORMAL);
|
||||
shader->bindInteger(shader->getLocation("colorBuffer"), GBuffer::DIFFUSE);
|
||||
shader->bindInteger(shader->getLocation("specularBuffer"), GBuffer::SPECULAR);
|
||||
shader->bindInteger(shader->getLocation("positionBuffer"), GBuffer::POSITION);
|
||||
shader->bindInteger(shader->getLocation("colorBuffer"), GBuffer::DIFFUSE);
|
||||
shader->bindInteger(shader->getLocation("normalBuffer"), GBuffer::NORMAL);
|
||||
shader->bindInteger(shader->getLocation("specularBuffer"), GBuffer::SPECULAR);
|
||||
shader->bindInteger(shader->getLocation("depthBuffer"), GBuffer::DEPTH);
|
||||
|
||||
// bind light
|
||||
@ -261,3 +262,12 @@ void DeferredPipeline::refreshScene(Scene *scene)
|
||||
for(unsigned int type : m_lightTypes)
|
||||
m_lightShaders[type] = m_lightingSource->compile(0, type);
|
||||
}
|
||||
|
||||
glm::vec4 DeferredPipeline::pick(int x, int y)
|
||||
{
|
||||
m_gBuffer->bindFBO();
|
||||
glm::vec4 pos;
|
||||
glReadPixels(x, y, 1, 1, GL_RGBA, GL_FLOAT, glm::value_ptr(pos));
|
||||
FrameBuffer::screen->bindFBO();
|
||||
return pos;
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ class Camera;
|
||||
class GBuffer : public FrameBuffer
|
||||
{
|
||||
public:
|
||||
enum Buffers { NORMAL, DIFFUSE, SPECULAR, POSITION, DEPTH, NB_BUFFERS };
|
||||
enum Buffers { POSITION, DIFFUSE, NORMAL, SPECULAR, DEPTH, NB_BUFFERS };
|
||||
GBuffer(int width, int height);
|
||||
void bindTextures();
|
||||
void unbindTextures();
|
||||
@ -61,6 +61,8 @@ public:
|
||||
|
||||
virtual void renderGL(Scene *scene);
|
||||
virtual void resizeGL(int w, int h);
|
||||
|
||||
glm::vec4 pick(int x, int y);
|
||||
};
|
||||
|
||||
#endif // DEFERREDPIPELINE_H
|
||||
|
@ -42,6 +42,13 @@ void TrackBallCamera::moveCamera(const glm::vec3 &diff)
|
||||
computeView();
|
||||
}
|
||||
|
||||
void TrackBallCamera::lookAt(const glm::vec3 &pos)
|
||||
{
|
||||
m_dist = glm::length(target);
|
||||
m_center = pos;
|
||||
computeView();
|
||||
}
|
||||
|
||||
void TrackBallCamera::reset()
|
||||
{
|
||||
m_center = glm::vec3(0, 4, 0);
|
||||
|
@ -21,6 +21,7 @@ public:
|
||||
void rotateCamera(float dx, float dy);
|
||||
void moveCamera(float dx, float dy);
|
||||
void moveCamera(const glm::vec3 &diff);
|
||||
void lookAt(const glm::vec3 &pos);
|
||||
void zoom(int nbScrolls);
|
||||
void reset();
|
||||
glm::vec3 getDefaultPxInfo();
|
||||
|
Loading…
x
Reference in New Issue
Block a user