added stencil buffer for future use
This commit is contained in:
parent
db4a174197
commit
2b324ec1da
@ -43,11 +43,11 @@ GBuffer::GBuffer(int width, int height) : FrameBuffer()
|
||||
tex->setUnit(EMISSION);
|
||||
addTexture(tex, GL_COLOR_ATTACHMENT3);
|
||||
|
||||
// - depth buffer
|
||||
tex = new Texture(GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, width, height, GL_FLOAT, GL_TEXTURE_RECTANGLE);
|
||||
// - depth and stencil buffer
|
||||
tex = new Texture(GL_DEPTH_STENCIL, GL_DEPTH24_STENCIL8, width, height, GL_UNSIGNED_INT_24_8, GL_TEXTURE_RECTANGLE);
|
||||
tex->setFiltering(GL_NEAREST);
|
||||
tex->setUnit(DEPTH);
|
||||
addTexture(tex, GL_DEPTH_ATTACHMENT);
|
||||
addTexture(tex, GL_DEPTH_STENCIL_ATTACHMENT);
|
||||
|
||||
initColorAttachments();
|
||||
}
|
||||
@ -120,7 +120,10 @@ void DeferredPipeline::renderGL(Scene *scene)
|
||||
glDisable(GL_BLEND);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.f);
|
||||
glClearDepth(1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glClearStencil(1);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
glStencilMask(0xFF);
|
||||
glStencilFunc(GL_ALWAYS, 0, 0xFF); // always draw fragments (ignore the stencil buffer values for now)
|
||||
// draw skybox
|
||||
if(m_skybox != nullptr)
|
||||
{
|
||||
|
@ -226,14 +226,14 @@ void DirectionnalLight::updateShadowMap(Scene* scene)
|
||||
m_shaders[shaderId]->bindMat4(m_shaders[shaderId]->getLocation("midShadowMVP"), lightMVP);
|
||||
lightMVP = m_projectionMatrices[2] * (m_viewMatrices[2] * node->modelMatrix);
|
||||
m_shaders[shaderId]->bindMat4(m_shaders[shaderId]->getLocation("backShadowMVP"), lightMVP);
|
||||
node->mesh->draw(m_shaders[shaderId], false, shaderId, false);
|
||||
node->mesh->draw(m_shaders[shaderId]);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_shaders[shaderId]->bind();
|
||||
glm::mat4 lightMVP = m_projectionMatrices[0] * (m_viewMatrices[0] * node->modelMatrix);
|
||||
m_shaders[shaderId]->bindMat4(m_shaders[shaderId]->getLocation("MVP"), lightMVP);
|
||||
node->mesh->draw(m_shaders[shaderId], false, shaderId, false);
|
||||
node->mesh->draw(m_shaders[shaderId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -370,7 +370,7 @@ void PointLight::updateShadowMap(Scene* scene)
|
||||
m_shaders[shaderId]->bindMat4(m_shaders[shaderId]->getLocation("modelMatrix"), node->modelMatrix);
|
||||
m_shaders[shaderId]->bindMat4Array(m_shaders[shaderId]->getLocation("layerTransform"), m_shadowTransforms.data(), m_shadowTransforms.size());
|
||||
m_shaders[shaderId]->bindFloat(m_shaders[shaderId]->getLocation("far_plane"), m_range);
|
||||
node->mesh->draw(m_shaders[shaderId], false, shaderId, false);
|
||||
node->mesh->draw(m_shaders[shaderId]);
|
||||
}
|
||||
}
|
||||
tempGetShadowMap();
|
||||
|
@ -171,8 +171,12 @@ void Mesh::initGL()
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
void Mesh::draw(Shader* shader, bool drawNormals, bool drawTexCoord, bool drawTangents)
|
||||
void Mesh::draw(Shader* shader)
|
||||
{
|
||||
if(isWireframe)
|
||||
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
|
||||
else
|
||||
glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
|
||||
if(isDoubleSided)
|
||||
glDisable(GL_CULL_FACE);
|
||||
if(material != NULL)
|
||||
|
@ -102,7 +102,7 @@ public:
|
||||
* - destroyGL releases the allocated GPU memory, destroyGL is called automatically in Mesh's destructor and at the beginning of initGL
|
||||
*/
|
||||
void initGL();
|
||||
void draw(Shader* shader, bool drawNormals = true, bool drawTexCoord = true, bool drawTangents = true);
|
||||
void draw(Shader* shader);
|
||||
void destroyGL();
|
||||
|
||||
/**
|
||||
|
@ -43,8 +43,8 @@ public:
|
||||
virtual SceneIterator<Light*>* getLights() = 0;
|
||||
virtual SceneIterator<GeometryNode*>* getGeometry() = 0;
|
||||
|
||||
void getMeshTypes(std::vector<unsigned int> &meshTypes);
|
||||
void getLightTypes(std::vector<unsigned int> &lightTypes);
|
||||
virtual void getMeshTypes(std::vector<unsigned int> &meshTypes);
|
||||
virtual void getLightTypes(std::vector<unsigned int> &lightTypes);
|
||||
};
|
||||
|
||||
// A basic implementation :
|
||||
|
@ -54,6 +54,7 @@ void Skybox::renderGL(Camera* myCamera)
|
||||
cubeMap->bind(0);
|
||||
glBindVertexArray(vao);
|
||||
|
||||
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbos[0]);
|
||||
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, NULL);
|
||||
glBindVertexArray(0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user