update shadows

This commit is contained in:
MihailRis
2025-07-04 18:20:41 +03:00
parent a9652327f1
commit 931f0180ef
2 changed files with 14 additions and 11 deletions
+10 -7
View File
@@ -15,23 +15,26 @@ float calc_shadow() {
float step = 1.0 / float(u_shadowsRes); float step = 1.0 / float(u_shadowsRes);
float s = pow(abs(cos(u_dayTime * PI2)), 0.25) * u_shadowsOpacity; float s = pow(abs(cos(u_dayTime * PI2)), 0.25) * u_shadowsOpacity;
vec3 normalOffset = a_realnormal * (a_distance > 64.0 ? 0.2 : 0.04); vec3 normalOffset = a_realnormal * (a_distance > 64.0 ? 0.2 : 0.04);
int shadowIdx = a_distance > 64.0 ? 1 : 0; int shadowIdx = a_distance > 80.0 ? 1 : 0;
vec4 mpos = u_shadowsMatrix[shadowIdx] * vec4(a_modelpos.xyz + normalOffset, 1.0); vec4 mpos = u_shadowsMatrix[shadowIdx] * vec4(a_modelpos.xyz + normalOffset, 1.0);
vec3 projCoords = mpos.xyz / mpos.w; vec3 projCoords = mpos.xyz / mpos.w;
projCoords = projCoords * 0.5 + 0.5; projCoords = projCoords * 0.5 + 0.5;
projCoords.z -= 0.00001; projCoords.z -= 0.00001 / u_shadowsRes;
if (shadowIdx > 0) {
projCoords.z -= 0.001;
}
float shadow = 0.0; float shadow = 0.0;
if (dot(a_realnormal, u_sunDir) < 0.0) { if (dot(a_realnormal, u_sunDir) < 0.0) {
// 5x5 kernel // 3x3 kernel
for (int y = -2; y <= 2; y++) { for (int y = -1; y <= 1; y++) {
for (int x = -2; x <= 2; x++) { for (int x = -1; x <= 1; x++) {
vec3 offset = vec3(x, y, -(abs(x) + abs(y)) * 0.1) * step * 2.0 * u_shadowsSoftness; vec3 offset = vec3(x, y, -(abs(x) + abs(y)) * 0.8) * step * 1.0 * u_shadowsSoftness;
shadow += texture(u_shadows[shadowIdx], projCoords + offset); shadow += texture(u_shadows[shadowIdx], projCoords + offset);
} }
} }
shadow /= 25.0; shadow /= 9.0;
} else { } else {
shadow = 0.5; shadow = 0.5;
} }
+4 -4
View File
@@ -364,7 +364,7 @@ void WorldRenderer::generateShadowsMap(
const auto& settings = engine.getSettings(); const auto& settings = engine.getSettings();
int resolution = shadowMap.getResolution(); int resolution = shadowMap.getResolution();
int quality = settings.graphics.shadowsQuality.get(); int quality = settings.graphics.shadowsQuality.get();
float shadowMapScale = 0.16f / (1 << glm::max(0, quality)) * scale; float shadowMapScale = 0.32f / (1 << glm::max(0, quality)) * scale;
float shadowMapSize = resolution * shadowMapScale; float shadowMapSize = resolution * shadowMapScale;
glm::vec3 basePos = glm::floor(camera.position); glm::vec3 basePos = glm::floor(camera.position);
@@ -380,7 +380,7 @@ void WorldRenderer::generateShadowsMap(
} }
t = fmod(t, 0.5f); t = fmod(t, 0.5f);
float sunCycleStep = 1.0f / 1000.0f; float sunCycleStep = 1.0f / 500.0f;
float sunAngle = glm::radians( float sunAngle = glm::radians(
90.0f - 90.0f -
((static_cast<int>(t / sunCycleStep)) * sunCycleStep + 0.25f) * 360.0f ((static_cast<int>(t / sunCycleStep)) * sunCycleStep + 0.25f) * 360.0f
@@ -439,7 +439,7 @@ void WorldRenderer::draw(
const auto& settings = engine.getSettings(); const auto& settings = engine.getSettings();
gbufferPipeline = settings.graphics.advancedRender.get(); gbufferPipeline = settings.graphics.advancedRender.get();
int shadowsQuality = settings.graphics.shadowsQuality.get(); int shadowsQuality = settings.graphics.shadowsQuality.get();
int resolution = 1024 << shadowsQuality; int resolution = 512 << shadowsQuality;
if (shadowsQuality > 0 && !shadows) { if (shadowsQuality > 0 && !shadows) {
shadowMap = std::make_unique<ShadowMap>(resolution); shadowMap = std::make_unique<ShadowMap>(resolution);
wideShadowMap = std::make_unique<ShadowMap>(resolution); wideShadowMap = std::make_unique<ShadowMap>(resolution);
@@ -473,7 +473,7 @@ void WorldRenderer::draw(
if (frameid % 2 == 0) { if (frameid % 2 == 0) {
generateShadowsMap(camera, pctx, *shadowMap, shadowCamera, 1.0f); generateShadowsMap(camera, pctx, *shadowMap, shadowCamera, 1.0f);
} else { } else {
generateShadowsMap(camera, pctx, *wideShadowMap, wideShadowCamera, 4.0f); generateShadowsMap(camera, pctx, *wideShadowMap, wideShadowCamera, 3.0f);
} }
} }
frameid++; frameid++;