Fix the skybox visual artifact bug #10

This commit is contained in:
reo 2025-12-15 17:08:51 +03:00
parent 73692b710e
commit 2a255affe4
2 changed files with 12 additions and 2 deletions

View file

@ -9,15 +9,19 @@ uniform sampler2D equirect;
const vec2 inv_atan = vec2(0.15915494309, 0.31830988618);
vec2 sample_spherical_map(vec3 v) {
vec2 uv = vec2(atan(v.z, v.x), asin(v.y));
vec2 uv = vec2(atan(v.z, v.x), asin(clamp(v.y, -1.0, 1.0)));
uv *= inv_atan;
uv += 0.5;
uv.x = fract(uv.x);
return uv;
}
void main() {
vec2 uv = sample_spherical_map(normalize(direction));
uv.y = 1.0 - uv.y;
vec2 size = vec2(textureSize(equirect, 0));
float epsY = 0.5 / max(size.y, 1.0);
uv.y = clamp(uv.y, epsY, 1.0 - epsY);
vec3 color = texture(equirect, uv).rgb;
frag_color = vec4(color, 1.0);
}