From cb77c1ff974fcb1f031f9fc3a6d1e12714533917 Mon Sep 17 00:00:00 2001 From: FakeShemp Date: Wed, 10 Feb 2016 16:16:41 +0100 Subject: [PATCH] Working pcf, not optimized --- include/Engine/Rendering/ShadowPass.h | 4 ++-- resources/Shaders/ForwardPlus.frag.glsl | 9 ++++----- src/Engine/Rendering/ShadowPass.cpp | 6 +++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/include/Engine/Rendering/ShadowPass.h b/include/Engine/Rendering/ShadowPass.h index 5acc376e..7c93fcd8 100644 --- a/include/Engine/Rendering/ShadowPass.h +++ b/include/Engine/Rendering/ShadowPass.h @@ -58,8 +58,8 @@ private: glm::mat4 m_LightView; glm::mat4 m_LightSpaceMatrix; - GLuint resolutionSizeWidth = 2048 * 4; - GLuint resolutionSizeHeigth = 2048 * 4; + GLuint resolutionSizeWidth = 2048 * 2; + GLuint resolutionSizeHeigth = 2048 * 2; bool m_ShadowOn = true; }; diff --git a/resources/Shaders/ForwardPlus.frag.glsl b/resources/Shaders/ForwardPlus.frag.glsl index 170a9d5a..ce71be28 100644 --- a/resources/Shaders/ForwardPlus.frag.glsl +++ b/resources/Shaders/ForwardPlus.frag.glsl @@ -121,16 +121,15 @@ float CalcShadowValue(vec4 positionLightSpace, vec3 normal, vec3 lightDir, sampl //float bias = max(0.05 * (1.0 - dot(normal, lightDir)), 0.005); //float bias = 0.005 * tan(acos(clamp(dot(normal, lightDir), 0,1))); bias = clamp(bias, 0,0.01); - vec3 projCoords = positionLightSpace.xyz / positionLightSpace.w; + vec3 projCoords = vec3(positionLightSpace.xy, positionLightSpace.z + bias) / positionLightSpace.w; projCoords = projCoords * 0.5 + 0.5; //float shadowMapDepth = texture(depthTexture, projCoords.xy).r; - float shadowMapDepth = 1.0 - texture(depthTexture, projCoords); + float shadowMapDepth = texture(depthTexture, projCoords); float geometryDepth = projCoords.z; //float shadow = geometryDepth - bias > shadowMapDepth ? 1.0 : 0.0; - //float shadow = geometryDepth - bias > shadowMapDepth ? 0.0 : 1.0; - float shadow = shadowMapDepth; + //float shadow = 1.0 - bias > shadowMapDepth ? 0.0 : 1.0; - //float shadow = 0.0; + float shadow = 1.0 - shadowMapDepth; //vec2 texelSize = 1.0 / textureSize(depthTexture, 0); //for(int x = -1; x <= 1; x++) diff --git a/src/Engine/Rendering/ShadowPass.cpp b/src/Engine/Rendering/ShadowPass.cpp index 5ffd553f..fbf25219 100644 --- a/src/Engine/Rendering/ShadowPass.cpp +++ b/src/Engine/Rendering/ShadowPass.cpp @@ -33,7 +33,7 @@ void ShadowPass::InitializeFrameBuffers() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); - glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY); + //glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY); m_DepthBuffer.AddResource(std::shared_ptr(new Texture2D(&m_DepthMap, GL_DEPTH_ATTACHMENT))); @@ -71,7 +71,7 @@ void ShadowPass::Draw(RenderScene & scene) glViewport(0, 0, resolutionSizeWidth, resolutionSizeHeigth); - //glCullFace(GL_FRONT); + glCullFace(GL_FRONT); //state->Disable(GL_CULL_FACE); ImGui::DragFloat4("ShadowMapCam", m_LRBT, 1.f, -1000.f, 1000.f); @@ -121,7 +121,7 @@ void ShadowPass::Draw(RenderScene & scene) glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height); - //glCullFace(GL_BACK); + glCullFace(GL_BACK); m_ShadowProgram->Unbind();