fixed shadows, fixed bad viewport when using shadows

This commit is contained in:
Anselme 2016-12-19 13:49:36 +01:00
parent 73d8c4a0e6
commit 7cafed3e67
4 changed files with 11 additions and 6 deletions

View File

@ -16,12 +16,11 @@ void main()
if(texture(alphaMask, varTexCoord).r < 0.5)
discard;
#endif
/*
#ifdef POINT_LIGHT
//gl_FragDepth = float(fcolor_idx)/6;
gl_FragDepth = length(fragPos.xyz)/far_plane;
#else
gl_FragDepth = gl_FragCoord.z;
#endif*/
gl_FragDepth = 0.5;
#endif
}

View File

@ -105,6 +105,8 @@ void DeferredPipeline::renderGL(Scene *scene)
if(m_renderTarget == NULL)
return;
glViewport(0, 0, m_width, m_height);
// GEOMETRY PASS
std::vector<GeometryNode*> mesh2D;
m_gBuffer->bindFBO();

View File

@ -109,10 +109,13 @@ void DirectionnalLight::initShadowMap(int resolution, bool isCascaded)
m_shaders[0] = source.compile(Mesh::MESH_3D, flag);
m_shaders[1] = source.compile(Mesh::MESH_3D & Mesh::MATERIAL_ALPHA_MASK, flag);
// not ready yet
/*
source.setSource(shaderMap["shaders/shadow.geom.glsl"], ShaderSource::GEOMETRY);
flag |= 1 << CASCADED_FLAG;
m_shaders[2] = source.compile(Mesh::MESH_3D, flag);
m_shaders[3] = source.compile(Mesh::MESH_3D & Mesh::MATERIAL_ALPHA_MASK, flag);
*/
}
if(!m_shadowCaster)
++m_shaderRefCounter;
@ -157,7 +160,7 @@ void DirectionnalLight::destroyShadowMap()
--m_shaderRefCounter;
if(m_shaderRefCounter == 0)
{
for(int i=0; i<4; ++i)
for(int i=0; i<2; ++i) // TODO replace 2 by 4 when cascaded shadowmaps shaders are ready
delete m_shaders[i];
}
if(m_shadowMap != NULL)

View File

@ -69,6 +69,7 @@ public:
virtual LightType getType() { return DIRECTIONNAL; }
virtual void bindAttributes(Shader *shader, Camera *camera);
virtual unsigned int getFlags();
virtual bool isShadowCaster() { return m_shadowCaster; }
void initShadowMap(int resolution, bool isCascaded = false);
void destroyShadowMap();