refactor shaders

This commit is contained in:
MihailRis
2025-05-09 23:51:34 +03:00
parent 36e5ff2472
commit 30a0b81680
9 changed files with 128 additions and 88 deletions
+27
View File
@@ -0,0 +1,27 @@
#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 modelpos) {
return max(0.0, 1.0 - distance(u_cameraPos, modelpos.xyz) / u_torchlightDistance);
}
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_
+32
View File
@@ -0,0 +1,32 @@
#ifndef SHADOWS_GLSL_
#define SHADOWS_GLSL_
float calc_shadow() {
float shadow = 1.0;
if (u_enableShadows) {
vec4 mpos = u_shadowsMatrix * vec4(a_modelpos.xyz + a_realnormal * 0.08, 1.0);
vec3 projCoords = mpos.xyz / mpos.w;
projCoords = projCoords * 0.5 + 0.5;
projCoords.z -= 0.0001;
shadow = 0.0;
if (dot(a_realnormal, u_sunDir) < 0.0) {
for (int x = -1; x <= 1; x++) {
for (int y = -1; y <= 1; y++) {
shadow += texture(u_shadows, projCoords.xyz + vec3(
x * (1.0 / u_shadowsRes),
y * (1.0 / u_shadowsRes), 0.0
));
}
}
shadow /= 9;
shadow = shadow * 0.5 + 0.5;
} else {
shadow = 0.5;
}
}
return shadow;
}
#endif // SHADOWS_GLSL_