WE HAVE WORKING CASCADE SHADOWS

This commit is contained in:
FakeShemp
2016-02-25 21:21:38 +01:00
parent 8867e7ac3c
commit df2e4abb52
2 changed files with 20 additions and 19 deletions
+18 -17
View File
@@ -194,12 +194,14 @@ float CalcShadowValue(vec4 positionLightSpace, vec3 normal, vec3 lightDir, sampl
int getShadowIndex(float far_distance[MAX_SPLITS]) int getShadowIndex(float far_distance[MAX_SPLITS])
{ {
float depth = gl_FragCoord.z / gl_FragCoord.w;
int index = 2; int index = 2;
if( gl_FragCoord.z < far_distance[0] ) if( depth < far_distance[0] )
{ {
index = 0; index = 0;
} }
else if( gl_FragCoord.z < far_distance[1] && gl_FragCoord.z > far_distance[0] ) else if( depth < far_distance[1] && depth > far_distance[0] )
{ {
index = 1; index = 1;
} }
@@ -207,7 +209,7 @@ int getShadowIndex(float far_distance[MAX_SPLITS])
return index; return index;
} }
//sampler2DShadow whichDepthMap( int DepthMapIndex ) //sampler2DShadow whichDepthMap(int DepthMapIndex)
//{ //{
// if( DepthMapIndex == 0 ) // if( DepthMapIndex == 0 )
// { // {
@@ -221,7 +223,6 @@ int getShadowIndex(float far_distance[MAX_SPLITS])
// { // {
// return DepthMap2; // return DepthMap2;
// } // }
//
//} //}
void main() void main()
@@ -275,19 +276,19 @@ void main()
light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal); light_result = CalcDirectionalLightSource(V * light.Direction, light.Color, light.Intensity, viewVec, normal);
shadowFactor = CalcShadowValue(Input.PositionLightSpace[0], Input.Normal, vec3(light.Direction), DepthMap0); //shadowFactor = CalcShadowValue(Input.PositionLightSpace[0], Input.Normal, vec3(light.Direction), DepthMap0);
//if( DepthMapIndex == 0 ) if( DepthMapIndex == 0 )
//{ {
// shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap0); shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap0);
//} }
//else if( DepthMapIndex == 1 ) else if( DepthMapIndex == 1 )
//{ {
// shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap1); shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap1);
//} }
//else else
//{ {
// shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap2); shadowFactor = CalcShadowValue(Input.PositionLightSpace[DepthMapIndex], Input.Normal, vec3(light.Direction), DepthMap2);
//} }
} }
totalLighting.Diffuse += light_result.Diffuse; totalLighting.Diffuse += light_result.Diffuse;
+2 -2
View File
@@ -111,7 +111,7 @@ void ShadowPass::InitializeFrameBuffers()
for (int i = 0; i < m_CurrentNrOfSplits; i++) { for (int i = 0; i < m_CurrentNrOfSplits; i++) {
glBindTexture(GL_TEXTURE_2D, m_DepthMap[i]); glBindTexture(GL_TEXTURE_2D, m_DepthMap[i]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, resolutionSizeWidth / (1 + i), resolutionSizeHeigth + (1 + i), 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, resolutionSizeWidth / (1 /*+ i*/), resolutionSizeHeigth + (1 /*+ i*/), 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
@@ -197,7 +197,7 @@ void ShadowPass::Draw(RenderScene & scene)
GLuint shaderHandle = m_ShadowProgram->GetHandle(); GLuint shaderHandle = m_ShadowProgram->GetHandle();
m_ShadowProgram->Bind(); m_ShadowProgram->Bind();
glViewport(0, 0, resolutionSizeWidth / (1 + i), resolutionSizeHeigth); glViewport(0, 0, resolutionSizeWidth / (1/* + i*/), resolutionSizeHeigth);
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
glCullFace(GL_FRONT); glCullFace(GL_FRONT);
//state->Disable(GL_CULL_FACE); //state->Disable(GL_CULL_FACE);