OpenGL2: Avoid a division/reciprocal for linear fog calculation

This commit is contained in:
UnknownShadow200 2025-04-01 21:29:00 +11:00
parent 7a39d2a4ee
commit 1abb1f39f5
3 changed files with 5 additions and 5 deletions

View File

@ -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)) {

View File

@ -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();
}

View File

@ -740,4 +740,5 @@ static cc_result GetMachineID(cc_uint32* key) {
Mem_Copy(key, MACHINE_KEY, sizeof(MACHINE_KEY) - 1);
return 0;
}
#endif
#endif