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