feat: deferred shading (day 2)

This commit is contained in:
MihailRis
2025-07-08 23:56:22 +03:00
parent a585b52aa2
commit 0bd901d1a6
23 changed files with 236 additions and 92 deletions
+19
View File
@@ -0,0 +1,19 @@
#ifndef FOG_GLSL_
#define FOG_GLSL_
uniform float u_fogFactor;
uniform float u_fogCurve;
uniform float u_weatherFogOpacity;
uniform float u_weatherFogDencity;
uniform float u_weatherFogCurve;
float calc_fog(float depth) {
return min(
1.0,
max(pow(depth * u_fogFactor, u_fogCurve),
min(pow(depth * u_weatherFogDencity, u_weatherFogCurve),
u_weatherFogOpacity))
);
}
#endif // FOG_GLSL_
-15
View File
@@ -1,12 +1,6 @@
#ifndef LIGHTING_GLSL_
#define LIGHTING_GLSL_
uniform float u_fogFactor;
uniform float u_fogCurve;
uniform float u_weatherFogOpacity;
uniform float u_weatherFogDencity;
uniform float u_weatherFogCurve;
float calc_torch_light(vec3 normal, vec3 modelpos) {
return max(0.0, 1.0 - distance(u_cameraPos, modelpos) / u_torchlightDistance)
* max(0.0, -dot(normal, normalize(modelpos - u_cameraPos)));
@@ -16,13 +10,4 @@ vec3 calc_screen_normal(vec3 normal) {
return transpose(inverse(mat3(u_view * u_model))) * normal;
}
float calc_fog(float depth) {
return min(
1.0,
max(pow(depth * u_fogFactor, u_fogCurve),
min(pow(depth * u_weatherFogDencity, u_weatherFogCurve),
u_weatherFogOpacity))
);
}
#endif // LIGHTING_GLSL_
+5 -5
View File
@@ -10,14 +10,14 @@ uniform int u_shadowsRes;
uniform float u_shadowsOpacity;
uniform float u_shadowsSoftness;
float calc_shadow() {
float calc_shadow(vec4 modelPos, vec3 realnormal, float distance) {
#ifdef ENABLE_SHADOWS
float step = 1.0 / float(u_shadowsRes);
float s = pow(abs(cos(u_dayTime * PI2)), 0.25) * u_shadowsOpacity;
vec3 normalOffset = a_realnormal * (a_distance > 64.0 ? 0.2 : 0.04);
int shadowIdx = a_distance > 80.0 ? 1 : 0;
vec3 normalOffset = realnormal * (distance > 64.0 ? 0.2 : 0.04);
int shadowIdx = distance > 80.0 ? 1 : 0;
vec4 mpos = u_shadowsMatrix[shadowIdx] * vec4(a_modelpos.xyz + normalOffset, 1.0);
vec4 mpos = u_shadowsMatrix[shadowIdx] * vec4(modelPos.xyz + normalOffset, 1.0);
vec3 projCoords = mpos.xyz / mpos.w;
projCoords = projCoords * 0.5 + 0.5;
projCoords.z -= 0.00001 / u_shadowsRes;
@@ -26,7 +26,7 @@ float calc_shadow() {
}
float shadow = 0.0;
if (dot(a_realnormal, u_sunDir) < 0.0) {
if (dot(realnormal, u_sunDir) < 0.0) {
// 3x3 kernel
for (int y = -1; y <= 1; y++) {
for (int x = -1; x <= 1; x++) {