Cleanup and improvement of shadow map quality

simple_math_single_header
Martin Felis 2018-03-15 23:00:53 +01:00
parent f27a354226
commit 3c5e281900
4 changed files with 11 additions and 19 deletions

View File

@ -19,21 +19,18 @@ float ShadowCalculation(vec4 frag_pos_light_space) {
projected_coordinates = projected_coordinates * 0.5 + 0.5; projected_coordinates = projected_coordinates * 0.5 + 0.5;
float closest_depth = texture(uShadowMap, projected_coordinates.xy).r; float closest_depth = texture(uShadowMap, projected_coordinates.xy).r;
// float closest_depth = texture(uAlbedoTexture, projected_coordinates.xy).r;
float current_depth = projected_coordinates.z; float current_depth = projected_coordinates.z;
// return current_depth; float bias = max(0.05 * (1.0 - dot(ioFragNormal, uLightDirection)), 0.005);
// return closest_depth; bias = 0.0;
float bias = 0.005;
return current_depth - bias > closest_depth ? 1.0 : 0.0; return current_depth - bias > closest_depth ? 1.0 : 0.0;
// return current_depth;
} }
void main() { void main() {
vec4 albedo_color = texture(uAlbedoTexture, ioFragTexCoords) * ioFragColor * uColor; vec4 albedo_color = texture(uAlbedoTexture, ioFragTexCoords) * ioFragColor * uColor;
// ambient lighting // ambient lighting
float ambient_strength = 0.1; float ambient_strength = 0.2;
vec4 ambient = ambient_strength * albedo_color; vec4 ambient = ambient_strength * albedo_color;
// diffuse lighting // diffuse lighting

View File

@ -2,17 +2,10 @@
uniform vec4 uColor; uniform vec4 uColor;
in vec4 fragmentColor; in vec4 ioFragmentColor;
out vec3 outColor; out vec4 outColor;
void main() { void main() {
outColor = vec3( outColor = vec4(ioFragmentColor.xyz * uColor.xyz * ioFragmentColor.w * uColor.w, 1.0);
uColor.r * fragmentColor.r,
uColor.g * fragmentColor.g,
uColor.b * fragmentColor.b
);
outColor = fragmentColor.rgb + uColor.rgb - uColor.rgb;
} }

View File

@ -8,9 +8,9 @@ in vec4 inColor;
uniform mat4 uModelViewProj; uniform mat4 uModelViewProj;
out vec4 fragmentColor; out vec4 ioFragmentColor;
void main() { void main() {
gl_Position = uModelViewProj * inCoord; gl_Position = uModelViewProj * inCoord;
fragmentColor = inColor; ioFragmentColor = inColor;
} }

View File

@ -411,6 +411,7 @@ void Renderer::RenderGl() {
mLight.UpdateMatrices(); mLight.UpdateMatrices();
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glCullFace(GL_FRONT);
glUseProgram(mLight.mShadowMapProgram.mProgramId); glUseProgram(mLight.mShadowMapProgram.mProgramId);
if (mLight.mShadowMapProgram.SetMat44("uLightSpaceMatrix", mLight.mLightSpaceMatrix) == -1) { if (mLight.mShadowMapProgram.SetMat44("uLightSpaceMatrix", mLight.mLightSpaceMatrix) == -1) {
gLog ("Warning: Uniform %s not found!", "uLightSpaceMatrix"); gLog ("Warning: Uniform %s not found!", "uLightSpaceMatrix");
@ -418,6 +419,7 @@ void Renderer::RenderGl() {
RenderScene(mLight.mShadowMapProgram, mLight.mCamera); RenderScene(mLight.mShadowMapProgram, mLight.mCamera);
mLight.mShadowMapTarget.RenderToLinearizedDepth(mLight.mCamera.mNear, mLight.mCamera.mFar, mLight.mCamera.mIsOrthographic); mLight.mShadowMapTarget.RenderToLinearizedDepth(mLight.mCamera.mNear, mLight.mCamera.mFar, mLight.mCamera.mIsOrthographic);
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
glCullFace(GL_BACK);
// Regular rendering // Regular rendering
glEnable(GL_LINE_SMOOTH); glEnable(GL_LINE_SMOOTH);
@ -465,7 +467,7 @@ void Renderer::RenderGl() {
* mCamera.mViewMatrix * mCamera.mViewMatrix
* mCamera.mProjectionMatrix; * mCamera.mProjectionMatrix;
mSimpleProgram.SetMat44("uModelViewProj", model_view_projection); mSimpleProgram.SetMat44("uModelViewProj", model_view_projection);
mSimpleProgram.SetVec4("uColor", Vector4f (1.0f, 0.0f, 0.0f, 1.0f)); mSimpleProgram.SetVec4("uColor", Vector4f (1.0f, 1.0f, 1.0f, 0.4f));
gVertexArray.Bind(); gVertexArray.Bind();
gXZPlaneGrid.Draw(GL_LINES); gXZPlaneGrid.Draw(GL_LINES);