Merge pull request #1255 from timgott/smooth_shadows_gl21

Smooth shadows in gl21
fix-quicksave-sim-speed-crash
Mateusz Przybył 2020-07-21 20:55:47 +02:00 committed by GitHub
commit 2d32e3a798
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 6 deletions

View File

@ -409,6 +409,7 @@ bool CGL21Device::Create()
uni.fogColor = glGetUniformLocation(m_normalProgram, "uni_FogColor"); uni.fogColor = glGetUniformLocation(m_normalProgram, "uni_FogColor");
uni.shadowColor = glGetUniformLocation(m_normalProgram, "uni_ShadowColor"); uni.shadowColor = glGetUniformLocation(m_normalProgram, "uni_ShadowColor");
uni.shadowTexelSize = glGetUniformLocation(m_normalProgram, "uni_ShadowTexelSize");
uni.lightCount = glGetUniformLocation(m_normalProgram, "uni_LightCount"); uni.lightCount = glGetUniformLocation(m_normalProgram, "uni_LightCount");
uni.ambientColor = glGetUniformLocation(m_normalProgram, "uni_Material.ambient"); uni.ambientColor = glGetUniformLocation(m_normalProgram, "uni_Material.ambient");
@ -459,6 +460,7 @@ bool CGL21Device::Create()
glUniform4f(uni.fogColor, 0.8f, 0.8f, 0.8f, 1.0f); glUniform4f(uni.fogColor, 0.8f, 0.8f, 0.8f, 1.0f);
glUniform1f(uni.shadowColor, 0.5f); glUniform1f(uni.shadowColor, 0.5f);
glUniform1f(uni.shadowTexelSize, 0.5f);
glUniform1i(uni.lightCount, 0); glUniform1i(uni.lightCount, 0);
} }
@ -1448,6 +1450,7 @@ void CGL21Device::SetRenderState(RenderState state, bool enabled)
} }
else if (state == RENDER_STATE_SHADOW_MAPPING) else if (state == RENDER_STATE_SHADOW_MAPPING)
{ {
glUniform1f(m_uniforms[m_mode].shadowTexelSize, 1.0/m_currentTextures[TEXTURE_SHADOW].size.x);
SetTextureEnabled(TEXTURE_SHADOW, enabled); SetTextureEnabled(TEXTURE_SHADOW, enabled);
return; return;

View File

@ -195,6 +195,8 @@ struct UniformLocations
//! Shadow color //! Shadow color
GLint shadowColor = -1; GLint shadowColor = -1;
//! Shadow texel size
GLint shadowTexelSize = -1;
// Number of enabled lights // Number of enabled lights
GLint lightCount = -1; GLint lightCount = -1;

View File

@ -35,6 +35,7 @@ uniform vec2 uni_FogRange;
uniform vec4 uni_FogColor; uniform vec4 uni_FogColor;
uniform float uni_ShadowColor; uniform float uni_ShadowColor;
uniform float uni_ShadowTexelSize;
struct LightParams struct LightParams
{ {
@ -99,13 +100,11 @@ void main()
if (uni_TextureEnabled[2]) if (uni_TextureEnabled[2])
{ {
#ifdef CONFIG_QUALITY_SHADOWS #ifdef CONFIG_QUALITY_SHADOWS
float offset = 0.00025f;
float value = (1.0f / 5.0f) * (shadow2D(uni_ShadowTexture, pass_TexCoord2).x float value = (1.0f / 5.0f) * (shadow2D(uni_ShadowTexture, pass_TexCoord2).x
+ shadow2D(uni_ShadowTexture, pass_TexCoord2 + vec3( offset, 0.0f, 0.0f)).x + shadow2D(uni_ShadowTexture, pass_TexCoord2 + vec3( uni_ShadowTexelSize, 0.0f, 0.0f)).x
+ shadow2D(uni_ShadowTexture, pass_TexCoord2 + vec3(-offset, 0.0f, 0.0f)).x + shadow2D(uni_ShadowTexture, pass_TexCoord2 + vec3(-uni_ShadowTexelSize, 0.0f, 0.0f)).x
+ shadow2D(uni_ShadowTexture, pass_TexCoord2 + vec3( 0.0f, offset, 0.0f)).x + shadow2D(uni_ShadowTexture, pass_TexCoord2 + vec3( 0.0f, uni_ShadowTexelSize, 0.0f)).x
+ shadow2D(uni_ShadowTexture, pass_TexCoord2 + vec3( 0.0f, -offset, 0.0f)).x); + shadow2D(uni_ShadowTexture, pass_TexCoord2 + vec3( 0.0f, -uni_ShadowTexelSize, 0.0f)).x);
shadow = mix(uni_ShadowColor, 1.0f, value); shadow = mix(uni_ShadowColor, 1.0f, value);
#else #else