1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 08:44:58 +00:00
serenity/Userland/Libraries/LibSoftGPU/PixelQuad.h
Jelle Raaijmakers 37dd10fbbe 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.
2022-03-07 11:00:45 +01:00

28 lines
657 B
C++

/*
* Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/SIMD.h>
#include <LibGfx/Vector2.h>
#include <LibGfx/Vector3.h>
#include <LibGfx/Vector4.h>
#include <LibSoftGPU/Config.h>
namespace SoftGPU {
struct PixelQuad final {
Vector2<AK::SIMD::f32x4> screen_coordinates;
Vector3<AK::SIMD::f32x4> barycentrics;
AK::SIMD::f32x4 depth;
Vector4<AK::SIMD::f32x4> vertex_color;
Array<Vector4<AK::SIMD::f32x4>, NUM_SAMPLERS> texture_coordinates;
Vector4<AK::SIMD::f32x4> out_color;
AK::SIMD::f32x4 fog_depth;
AK::SIMD::i32x4 mask;
};
}