From 1abb1f39f5512b50046f8932d2b0156af94a8885 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 1 Apr 2025 21:29:00 +1100 Subject: [PATCH] OpenGL2: Avoid a division/reciprocal for linear fog calculation --- src/Graphics_GL2.c | 4 ++-- src/MapRenderer.c | 3 +-- src/Platform_Dreamcast.c | 3 ++- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Graphics_GL2.c b/src/Graphics_GL2.c index 359bfdd37..a9aa8087f 100644 --- a/src/Graphics_GL2.c +++ b/src/Graphics_GL2.c @@ -266,7 +266,7 @@ static void GenFragmentShader(const struct GLShader* shader, cc_string* dst) { else String_AppendConst(dst, " vec4 col = out_col;\n"); if (al) String_AppendConst(dst, " if (col.a < 0.5) discard;\n"); if (fm) String_AppendConst(dst, " float depth = 1.0 / gl_FragCoord.w;\n"); - if (fl) String_AppendConst(dst, " float f = clamp((fogEnd - depth) / fogEnd, 0.0, 1.0);\n"); + if (fl) String_AppendConst(dst, " float f = clamp(1.0 - depth * fogEnd, 0.0, 1.0);\n"); if (fd) String_AppendConst(dst, " float f = clamp(exp(fogDensity * depth), 0.0, 1.0);\n"); if (fm) String_AppendConst(dst, " col.rgb = mix(fogCol, col.rgb, f);\n"); @@ -402,7 +402,7 @@ static void ReloadUniforms(void) { s->uniforms &= ~UNI_FOG_COL; } if ((s->uniforms & UNI_FOG_END) && (s->features & FTR_LINEAR_FOG)) { - glUniform1f(s->locations[3], gfx_fogEnd); + glUniform1f(s->locations[3], 1.0f / gfx_fogEnd); s->uniforms &= ~UNI_FOG_END; } if ((s->uniforms & UNI_FOG_DENS) && (s->features & FTR_DENSIT_FOG)) { diff --git a/src/MapRenderer.c b/src/MapRenderer.c index 6c88d6a50..992563bbd 100644 --- a/src/MapRenderer.c +++ b/src/MapRenderer.c @@ -490,7 +490,6 @@ void MapRenderer_Refresh(void) { if (mapChunks && World.Blocks) { DeleteChunks(); - RefreshChunks(); oldCount = MapRenderer_1DUsedCount; MapRenderer_1DUsedCount = MapRenderer_UsedAtlases(); @@ -750,7 +749,7 @@ static void OnTerrainAtlasChanged(void* obj) { } static void OnBlockDefinitionChanged(void* obj) { - RefreshChunks(); + MapRenderer_Refresh(); MapRenderer_1DUsedCount = MapRenderer_UsedAtlases(); ResetPartFlags(); } diff --git a/src/Platform_Dreamcast.c b/src/Platform_Dreamcast.c index 99252e130..81e5903b4 100644 --- a/src/Platform_Dreamcast.c +++ b/src/Platform_Dreamcast.c @@ -740,4 +740,5 @@ static cc_result GetMachineID(cc_uint32* key) { Mem_Copy(key, MACHINE_KEY, sizeof(MACHINE_KEY) - 1); return 0; } -#endif \ No newline at end of file +#endif +