1
0
forked from 0ad/0ad

Reduces shadow biases for landscape shaders.

Tested By: Stan, wraitii
Differential Revision: https://code.wildfiregames.com/D3457
This was SVN commit r24777.
This commit is contained in:
Vladislav Belov 2021-01-23 19:40:58 +00:00
parent 93a352ad16
commit ae18a5474c
7 changed files with 21 additions and 8 deletions

View File

@ -13,9 +13,8 @@
#endif #endif
#endif #endif
float get_shadow() float getShadowImpl(float shadowBias)
{ {
float shadowBias = 0.003;
#if USE_SHADOW && !DISABLE_RECEIVE_SHADOWS #if USE_SHADOW && !DISABLE_RECEIVE_SHADOWS
float biasedShdwZ = v_shadow.z - shadowBias; float biasedShdwZ = v_shadow.z - shadowBias;
#if USE_SHADOW_SAMPLER #if USE_SHADOW_SAMPLER
@ -41,4 +40,16 @@ float get_shadow()
#endif #endif
} }
float getShadow()
{
float shadowBias = 0.003;
return getShadowImpl(shadowBias);
}
float getShadowOnLandscape()
{
float shadowBias = 0.0005;
return getShadowImpl(shadowBias);
}
#endif // INCLUDED_SHADOWS_FRAGMENT #endif // INCLUDED_SHADOWS_FRAGMENT

View File

@ -153,7 +153,7 @@ void main()
specular.rgb = sunColor * specCol * pow(max(0.0, dot(normalize(normal), v_half)), specPow); specular.rgb = sunColor * specCol * pow(max(0.0, dot(normalize(normal), v_half)), specPow);
#endif #endif
vec3 color = (texdiffuse * sundiffuse + specular.rgb) * get_shadow(); vec3 color = (texdiffuse * sundiffuse + specular.rgb) * getShadow();
vec3 ambColor = texdiffuse * ambient; vec3 ambColor = texdiffuse * ambient;
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_AO #if (USE_INSTANCING || USE_GPU_SKINNING) && USE_AO

View File

@ -83,7 +83,7 @@ void main()
specular = pow(max(0.0, ndoth), 150.0f) * sunColor * specularStrength; specular = pow(max(0.0, ndoth), 150.0f) * sunColor * specularStrength;
#if USE_SHADOW #if USE_SHADOW
float shadow = get_shadow(); float shadow = getShadowOnLandscape();
float fresShadow = mix(fresnel, fresnel*shadow, dot(sunColor, vec3(0.16666))); float fresShadow = mix(fresnel, fresnel*shadow, dot(sunColor, vec3(0.16666)));
#else #else
float fresShadow = fresnel; float fresShadow = fresnel;

View File

@ -32,7 +32,7 @@ void main()
vec3 specular = sunColor * specularColor * pow(max(0.0, dot(normalize(v_normal), v_half)), specularPower); vec3 specular = sunColor * specularColor * pow(max(0.0, dot(normalize(v_normal), v_half)), specularPower);
vec3 color = (texdiffuse.rgb * v_lighting + specular) * get_shadow(); vec3 color = (texdiffuse.rgb * v_lighting + specular) * getShadowOnLandscape();
color += texdiffuse.rgb * ambient; color += texdiffuse.rgb * ambient;
color *= getLOS(); color *= getLOS();

View File

@ -169,7 +169,7 @@ void main()
specular.rgb = sunColor * specCol * pow(max(0.0, dot(normalize(normal), v_half)), specPow); specular.rgb = sunColor * specCol * pow(max(0.0, dot(normalize(normal), v_half)), specPow);
#endif #endif
vec3 color = (texdiffuse * sundiffuse + specular.rgb) * get_shadow() + texdiffuse * ambient; vec3 color = (texdiffuse * sundiffuse + specular.rgb) * getShadowOnLandscape() + texdiffuse * ambient;
#if USE_SPECULAR_MAP && USE_SELF_LIGHT #if USE_SPECULAR_MAP && USE_SELF_LIGHT
color = mix(texdiffuse, color, specular.a); color = mix(texdiffuse, color, specular.a);

View File

@ -296,7 +296,7 @@ void main()
vec3 specular = getSpecular(normal, eyeVec); vec3 specular = getSpecular(normal, eyeVec);
#if USE_SHADOW #if USE_SHADOW
float shadow = get_shadow(); float shadow = getShadowOnLandscape();
fresnel = mix(fresnel, fresnel * shadow, 0.05 + murkiness * 0.2); fresnel = mix(fresnel, fresnel * shadow, 0.05 + murkiness * 0.2);
#else #else
float shadow = 1.0; float shadow = 1.0;

View File

@ -444,11 +444,13 @@ public:
CPreprocessorWrapper preprocessor([&newFileDependencies](const CStr& includePath, CStr& out) -> bool { CPreprocessorWrapper preprocessor([&newFileDependencies](const CStr& includePath, CStr& out) -> bool {
const VfsPath includeFilePath(L"shaders/glsl/" + wstring_from_utf8(includePath)); const VfsPath includeFilePath(L"shaders/glsl/" + wstring_from_utf8(includePath));
// Add dependencies anyway to reload the shader when the file is
// appeared.
newFileDependencies.push_back(includeFilePath);
CVFSFile includeFile; CVFSFile includeFile;
if (includeFile.Load(g_VFS, includeFilePath) != PSRETURN_OK) if (includeFile.Load(g_VFS, includeFilePath) != PSRETURN_OK)
return false; return false;
out = includeFile.GetAsString(); out = includeFile.GetAsString();
newFileDependencies.push_back(includeFilePath);
return true; return true;
}); });
preprocessor.AddDefines(m_Defines); preprocessor.AddDefines(m_Defines);