slightly faster bilinear interpolation #33

Merged
embeddedt merged 4 commits from rdh/celeritas:ao-better into stonecutter 2026-08-18 20:00:03 -04:00
2 changed files with 5 additions and 8 deletions
Showing only changes of commit b8be6ac0bc - Show all commits

No files matched your search

@@ -5,7 +5,6 @@
in vec4 v_Color;
in vec4 v_RdhFactor;
in vec2 v_QuadCoord;
in vec3 v_LightColor;
in vec2 v_TexCoord;
#if defined(USE_FOG) && defined(CHUNK_FADE_IN_DURATION_MS) && CHUNK_FADE_IN_DURATION_MS > 0
@@ -63,9 +62,7 @@ void main() {
// Apply correction factor to make the resulting color very close to what true bilinear interpolation would obtain
float correctionWeight = min(v_QuadCoord.x, v_QuadCoord.y)
* (1.0 - max(v_QuadCoord.x, v_QuadCoord.y));
vec4 correction = v_RdhFactor * correctionWeight;
correction.rgb *= v_LightColor;
m_color += correction;
m_color += v_RdhFactor * correctionWeight;
#ifdef USE_VANILLA_COLOR_FORMAT
// Apply per-vertex color. AO shade is applied ahead of time on the CPU.
@@ -97,4 +94,4 @@ void main() {
#else
fragColor = diffuseColor;
#endif
}
}
@@ -8,7 +8,6 @@
out vec4 v_Color;
out vec4 v_RdhFactor;
out vec2 v_QuadCoord;
out vec3 v_LightColor;
out vec2 v_TexCoord;
#if defined(USE_FOG) && defined(CHUNK_FADE_IN_DURATION_MS) && CHUNK_FADE_IN_DURATION_MS > 0
@@ -63,13 +62,14 @@ void main() {
// Add the light color to the vertex color, and pass the texture coordinates to the fragment shader
#ifdef CELERITAS_NO_LIGHTMAP
v_Color = _vert_color;
v_LightColor = vec3(1.0);
#else
vec4 lightColor = _sample_lightmap(u_LightTex, _vert_tex_light_coord);
v_Color = _vert_color * lightColor;
v_LightColor = lightColor.rgb;
#endif
v_RdhFactor = _vert_rdh_factor * 2.0;
#ifndef CELERITAS_NO_LIGHTMAP
v_RdhFactor.rgb *= lightColor.rgb;
#endif
int corner = gl_VertexID & 3;
v_QuadCoord = vec2(corner >= 2 ? 1.0 : 0.0,
corner == 1 || corner == 2 ? 1.0 : 0.0);