1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 22:57:44 +00:00

LibSoftGPU: Use float instead of int for triangle screen coords

This replaces the fixed point subpixel precision logic.

GLQuake now effectively renders artifact-free. Previously white/gray
pixels would sometimes be visible at triangle edges, caused by slightly
misaligned triangle edges as a result of converting the vertex window
coordinates to `int`. These artifacts were reduced by the introduction
of subpixel precision, but not completely eliminated.

Some interesting changes in this commit:

* Applying the top-left rule for our counter-clockwise vertices is now
  done with simpler conditions: every vertex that has a Y coordinate
  lower than or equal to the previous vertex' Y coordinate is counted
  as a top or left edge. A float epsilon is used to emulate a switch
  between `> 0` and `>= 0` comparisons.

* Fog depth calculation into a `f32x4` is now done once per triangle
  instead of once per fragment, and only if fog is enabled.

* The `one_over_area` value was previously calculated as `1.0f / area`,
  where `area` was an `int`. This resulted in a lower quality
  reciprocal value whereas we can now retain floating point precision.
  The effect of this can be seen in Tux Racer, where the ice reflection
  is noticeably smoother.
This commit is contained in:
Jelle Raaijmakers 2022-03-06 18:50:04 +01:00 committed by Andreas Kling
parent 6133acb8c0
commit 37dd10fbbe
3 changed files with 58 additions and 68 deletions

View file

@ -17,7 +17,6 @@ namespace SoftGPU {
static constexpr bool ENABLE_STATISTICS_OVERLAY = false;
static constexpr int NUM_SAMPLERS = 2;
static constexpr int MILLISECONDS_PER_STATISTICS_PERIOD = 500;
static constexpr int SUBPIXEL_BITS = 5;
static constexpr int NUM_LIGHTS = 8;
// See: https://www.khronos.org/opengl/wiki/Common_Mistakes#Texture_edge_color_problem