Convert fogball calculations from sRGB to linear

This commit is contained in:
RaveYard 2024-01-10 13:10:26 +01:00 committed by Nash Muhandes
commit 7f7363e30b
2 changed files with 8 additions and 2 deletions

View file

@ -774,7 +774,7 @@ void HWSprite::Process(HWDrawInfo *di, FRenderState& state, AActor* thing, secto
Fogball fogball;
fogball.Position = FVector3(thing->Pos());
fogball.Radius = (float)thing->args[3];
fogball.Color = FVector3(thing->args[0] * (1.0f / 255.0f), thing->args[1] * (1.0f / 255.0f), thing->args[2] * (1.0f / 255.0f));
fogball.Color = FVector3(powf(thing->args[0] * (1.0f / 255.0f), 2.2), powf(thing->args[1] * (1.0f / 255.0f), 2.2), powf(thing->args[2] * (1.0f / 255.0f), 2.2));
fogball.Fog = (float)thing->Alpha;
di->Fogballs.Push(fogball);
return;

View file

@ -40,8 +40,14 @@ float FogSphereDensity(vec3 rayOrigin, vec3 rayDirection, vec3 sphereCenter, flo
return (i2 - i1) * (3.0f / 4.0f);
}
// Approximate sRGB/linear conversion
vec3 ToLinear(vec3 c) { return pow(c, vec3(2.2)); }
vec3 FromLinear(vec3 c) { return pow(c, vec3(1.0 / 2.2)); }
vec4 ProcessFogBalls(vec4 light)
{
light.rgb = ToLinear(light.rgb);
vec3 rayOrigin = uCameraPos.xyz;
float dbuffer = distance(pixelpos.xyz, uCameraPos.xyz);
vec3 rayDirection = normalize(pixelpos.xyz - uCameraPos.xyz);
@ -59,5 +65,5 @@ vec4 ProcessFogBalls(vec4 light)
light.rgb = mix(light.rgb, fogcolor * density, alpha);
}
return light;
return vec4(FromLinear(light.rgb), light.a);
}