More consistent texturing code

This commit is contained in:
Joshua Barretto 2022-07-14 18:04:36 +01:00
parent f4e50d18df
commit 3c5de2991b

View File

@ -621,32 +621,31 @@ vec3 compute_attenuation_point(vec3 wpos, vec3 ray_dir, vec3 mu, float surface_a
//#endif
vec3 greedy_extract_col_light_attr(texture2D t_col_light, sampler s_col_light, vec2 f_uv_pos, out float f_light, out float f_glow, out float f_ao, out uint f_attr) {
uvec4 f_col_light = uvec4(texelFetch(sampler2D(t_col_light, s_col_light), ivec2(f_uv_pos), 0) * 255);
vec3 f_col = vec3(
float(((f_col_light.r & 0x7u) << 1u) | (f_col_light.b & 0xF0u)),
float(f_col_light.a & 0xFE),
float(((f_col_light.g & 0x7u) << 1u) | ((f_col_light.b & 0x0Fu) << 4u))
) / 255.0;
// TODO: Figure out how to use `texture` and modulation to avoid needing to do manual filtering
vec4 tex_10 = texelFetch(sampler2D(t_col_light, s_col_light), ivec2(f_uv_pos) + ivec2(1, 0), 0);
vec4 tex_01 = texelFetch(sampler2D(t_col_light, s_col_light), ivec2(f_uv_pos) + ivec2(0, 1), 0);
vec4 tex_11 = texelFetch(sampler2D(t_col_light, s_col_light), ivec2(f_uv_pos) + ivec2(1, 1), 0);
vec3 light_00 = vec3(uvec2(f_col_light.rg) >> 3u, f_col_light.a & 1u);
vec3 light_10 = vec3(uvec2(tex_10.rg * 255.0) >> 3u, uint(tex_10.a * 255.0) & 1u);
vec3 light_01 = vec3(uvec2(tex_01.rg * 255.0) >> 3u, uint(tex_01.a * 255.0) & 1u);
vec3 light_11 = vec3(uvec2(tex_11.rg * 255.0) >> 3u, uint(tex_11.a * 255.0) & 1u);
uvec4 tex_00 = uvec4(texelFetch(sampler2D(t_col_light, s_col_light), ivec2(f_uv_pos) + ivec2(0, 0), 0) * 255);
uvec4 tex_10 = uvec4(texelFetch(sampler2D(t_col_light, s_col_light), ivec2(f_uv_pos) + ivec2(1, 0), 0) * 255);
uvec4 tex_01 = uvec4(texelFetch(sampler2D(t_col_light, s_col_light), ivec2(f_uv_pos) + ivec2(0, 1), 0) * 255);
uvec4 tex_11 = uvec4(texelFetch(sampler2D(t_col_light, s_col_light), ivec2(f_uv_pos) + ivec2(1, 1), 0) * 255);
vec3 light_00 = vec3(tex_00.rg >> 3u, tex_00.a & 1u);
vec3 light_10 = vec3(tex_10.rg >> 3u, tex_10.a & 1u);
vec3 light_01 = vec3(tex_01.rg >> 3u, tex_01.a & 1u);
vec3 light_11 = vec3(tex_11.rg >> 3u, tex_11.a & 1u);
vec3 light_0 = mix(light_00, light_01, fract(f_uv_pos.y));
vec3 light_1 = mix(light_10, light_11, fract(f_uv_pos.y));
vec3 light = mix(light_0, light_1, fract(f_uv_pos.x));
// TODO: Use `texture` instead
//vec2 light = texture(t_col_light, f_uv_pos).xy / 31;
vec3 f_col = vec3(
float(((tex_00.r & 0x7u) << 1u) | (tex_00.b & 0xF0u)),
float(tex_00.a & 0xFE),
float(((tex_00.g & 0x7u) << 1u) | ((tex_00.b & 0x0Fu) << 4u))
) / 255.0;
f_ao = light.z;
f_light = light.x / 31.0;
f_glow = light.y / 31.0;
f_attr = f_col_light.g >> 3u;
f_attr = tex_00.g >> 3u;
return srgb_to_linear(f_col);
}