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;
float closest_depth = texture(uShadowMap, projected_coordinates.xy).r;
// float closest_depth = texture(uAlbedoTexture, projected_coordinates.xy).r;
float current_depth = projected_coordinates.z;
// return current_depth;
// return closest_depth;
float bias = 0.005;
float bias = max(0.05 * (1.0 - dot(ioFragNormal, uLightDirection)), 0.005);
bias = 0.0;
return current_depth - bias > closest_depth ? 1.0 : 0.0;
// return current_depth;
}
void main() {
vec4 albedo_color = texture(uAlbedoTexture, ioFragTexCoords) * ioFragColor * uColor;
// ambient lighting
float ambient_strength = 0.1;
float ambient_strength = 0.2;
vec4 ambient = ambient_strength * albedo_color;
// diffuse lighting

View File

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

View File

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

View File

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