improve shading & enable disabled elements

This commit is contained in:
MihailRis
2025-05-09 21:52:29 +03:00
parent c1608fe8e2
commit 657b4304b4
9 changed files with 70 additions and 45 deletions
+1 -1
View File
@@ -58,5 +58,5 @@ function on_hud_open()
local slot = gfx.posteffects.index("core:default")
gfx.posteffects.set_effect(slot, "ssao")
--gfx.posteffects.set_intensity(slot, 1.0)
gfx.posteffects.set_intensity(slot, 1.0)
end
+1 -1
View File
@@ -7,7 +7,7 @@ uniform samplerCube u_cubemap;
void main(){
vec3 dir = normalize(v_coord);
f_position = vec4(0.0, 0.0, 0.0, 1e9);
f_position = vec4(0.0, 0.0, 0.0, 0.0);
f_normal = vec4(0.0);
f_color = texture(u_cubemap, dir);
}
+5 -3
View File
@@ -1,6 +1,6 @@
uniform vec3 u_ssaoSamples[64];
int kernelSize = 32;
int kernelSize = 16;
float radius = 0.25;
float bias = 0.025;
@@ -32,8 +32,10 @@ vec4 effect() {
float rangeCheck = smoothstep(0.0, 1.0, radius / abs(position.z - sampleDepth));
occlusion += (sampleDepth >= samplePos.z + bias ? 1.0 : 0.0) * rangeCheck;
}
occlusion = 1.1 - (occlusion / kernelSize);
occlusion = min(1.0, 1.05 - (occlusion / kernelSize));
}
return vec4(color * occlusion, 1.0);
float z = -position.z * 0.02;
z = max(0.0, 1.0 - z);
return vec4(color * mix(1.0, occlusion, z), 1.0);
}
+17 -9
View File
@@ -14,6 +14,8 @@ in vec4 a_modelpos;
uniform sampler2D u_texture0;
uniform samplerCube u_cubemap;
uniform sampler2DShadow u_shadows;
uniform vec3 u_sunDir;
uniform int u_shadowsRes;
// flags
uniform bool u_alphaClip;
@@ -28,21 +30,27 @@ const int BLUR_SAMPLES = 6;
void main() {
float shadow = 1.0;
if (u_enableShadows) {
vec4 mpos = u_shadowsMatrix * vec4(a_modelpos.xyz, 1.0);
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;
for (int i = 0; i < BLUR_SAMPLES; i++) {
shadow += texture(u_shadows, projCoords.xyz + vec3(
-0.002*(i%2==0?1:0)*i/BLUR_SAMPLES / 4.0,
-0.002*(i%2==0?0:1)*i/BLUR_SAMPLES / 4.0,
-0.0005 * i/BLUR_SAMPLES));
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;
}
shadow /= BLUR_SAMPLES;
shadow = shadow * 0.5 + 0.5;
}
vec3 fogColor = texture(u_cubemap, a_dir).rgb;
@@ -63,7 +71,7 @@ void main() {
}
f_color = a_color * texColor;
f_color.rgb *= shadow;
f_color = mix(f_color, vec4(fogColor,1.0), a_fog);
f_color = mix(f_color, vec4(fogColor, 1.0), a_fog);
f_color.a = alpha;
f_position = vec4(a_position, 1.0);
f_normal = vec4(a_normal, 1.0);
+3 -3
View File
@@ -37,11 +37,11 @@ void main() {
vec3 pos3d = modelpos.xyz-u_cameraPos;
modelpos.xyz = apply_planet_curvature(modelpos.xyz, pos3d);
a_realnormal = v_normal.xyz;
a_realnormal = v_normal.xyz * 2.0 - 1.0;
mat3 normalMatrix = transpose(inverse(mat3(u_view * u_model)));
a_normal = v_normal.xyz * 2.0 - 1.0;
a_normal = a_realnormal;
a_normal = normalMatrix * (false ? -a_normal : a_normal);
//a_normal = v_normal.xyz * 2.0 - 1.0;
//a_normal = a_realnormal;
vec3 light = v_light.rgb;
float torchlight = max(0.0, 1.0-distance(u_cameraPos, modelpos.xyz) /