Merge branch 'master' of https://git.epicsparrow.com/epicsparrow/sparrowrenderer
This commit is contained in:
commit
e94f2a3c98
@ -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,7 +1,7 @@
|
||||
layout(location = 0)in vec2 inPosition;
|
||||
|
||||
#ifdef TEXTURABLE
|
||||
layout(location = 0)in vec2 inTexCoord;
|
||||
layout(location = 2)in vec2 inTexCoord;
|
||||
|
||||
out vec2 texCoord;
|
||||
#endif
|
||||
|
@ -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
|
||||
@ -188,6 +189,8 @@ void DeferredPipeline::renderGL(Scene *scene)
|
||||
|
||||
// 2D GUI PASS
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
for(GeometryNode* node : mesh2D)
|
||||
{
|
||||
Shader *shader = m_mesh2DShaders[node->mesh->getFlags()];
|
||||
@ -261,3 +264,27 @@ 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->setTarget(GL_READ_FRAMEBUFFER);
|
||||
m_gBuffer->bindFBO();
|
||||
//m_gBuffer->getTexture(0)->
|
||||
float values[4] = {1};
|
||||
glReadPixels(x, y, 1, 1, GL_RGBA, GL_FLOAT, values);
|
||||
GLenum err = glGetError();
|
||||
while(err != GL_NO_ERROR)
|
||||
{
|
||||
switch(err)
|
||||
{
|
||||
case GL_INVALID_ENUM : printf("OpenGL error : GL_INVALID_ENUM\n"); break;
|
||||
case GL_INVALID_VALUE : printf("OpenGL error : GL_INVALID_VALUE\n"); break;
|
||||
case GL_INVALID_OPERATION : printf("OpenGL error : GL_INVALID_OPERATION\n"); break;
|
||||
default : printf("OpenGL error : other\n"); break;
|
||||
}
|
||||
err = glGetError();
|
||||
}
|
||||
m_gBuffer->setTarget();
|
||||
FrameBuffer::screen->bindFBO();
|
||||
return glm::vec4(values[0], values[1], values[2], values[3]);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -13,12 +13,10 @@ TrackBallCamera::TrackBallCamera(float myFov, float myNear, float myFar) :
|
||||
|
||||
void TrackBallCamera::rotateCamera(float dx, float dy)
|
||||
{
|
||||
m_rotation.x += dx*DEFAULT_ROTATION_SPEED;
|
||||
m_rotation.y += dy*DEFAULT_ROTATION_SPEED;
|
||||
if(m_rotation.y > 1.57f)
|
||||
m_rotation.y = 1.57f;
|
||||
if(m_rotation.y < -1.57f)
|
||||
m_rotation.y = -1.57f;
|
||||
glm::vec3 vert(0, 1, 0);
|
||||
m_direction = glm::rotate(m_direction, -dx*DEFAULT_ROTATION_SPEED, vert);
|
||||
m_direction = glm::rotate(m_direction, -dy*DEFAULT_ROTATION_SPEED, glm::cross(m_direction, vert));
|
||||
m_direction = glm::normalize(m_direction);
|
||||
computeView();
|
||||
}
|
||||
|
||||
@ -42,20 +40,26 @@ void TrackBallCamera::moveCamera(const glm::vec3 &diff)
|
||||
computeView();
|
||||
}
|
||||
|
||||
void TrackBallCamera::lookAt(const glm::vec3 &pos)
|
||||
{
|
||||
m_direction = pos + m_direction*m_dist - m_center;
|
||||
m_dist = glm::length(m_direction);
|
||||
m_direction = glm::normalize(m_direction);
|
||||
m_center = pos;
|
||||
computeView();
|
||||
}
|
||||
|
||||
void TrackBallCamera::reset()
|
||||
{
|
||||
m_center = glm::vec3(0, 4, 0);
|
||||
m_rotation = glm::vec2(0, 1);
|
||||
m_direction = glm::normalize(glm::vec3(0, -1, -1));
|
||||
m_dist = 20;
|
||||
computeView();
|
||||
}
|
||||
|
||||
void TrackBallCamera::computeView()
|
||||
{
|
||||
m_view = glm::translate(glm::mat4(), glm::vec3(0, 0, -m_dist));
|
||||
m_view = glm::rotate(m_view, m_rotation.y, glm::vec3(1, 0, 0));
|
||||
m_view = glm::rotate(m_view, m_rotation.x, glm::vec3(0, 1, 0));
|
||||
m_view = glm::translate(m_view, -m_center);
|
||||
m_view = glm::lookAt(m_center - m_direction*m_dist, m_center, glm::vec3(0, 1, 0));
|
||||
}
|
||||
|
||||
void TrackBallCamera::zoom(int nbUnits)
|
||||
|
@ -10,7 +10,7 @@ class TrackBallCamera : public BasicCamera
|
||||
private:
|
||||
// camera position
|
||||
glm::vec3 m_center;
|
||||
glm::vec2 m_rotation;
|
||||
glm::vec3 m_direction;
|
||||
float m_dist;
|
||||
|
||||
void computeView();
|
||||
@ -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