Skip to content

Commit

Permalink
Convert fogball calculations from sRGB to linear
Browse files Browse the repository at this point in the history
  • Loading branch information
MrRaveYard committed Jan 10, 2024
1 parent 62be7a5 commit 4858dea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/rendering/hwrenderer/scene/hw_sprites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion wadsrc/static/shaders/scene/fogball.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

0 comments on commit 4858dea

Please sign in to comment.