From 087f5657001047527d34de148626366835eab814 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Tue, 6 Sep 2022 23:13:48 +0200 Subject: [PATCH] LibSoftGPU: Divide texture coordinates by Q Up until now, we have only dealt with games that pass Q = 1 for their texture coordinates. PrBoom+, however, relies on proper homogenous texture coordinates for its relatively complex sky rendering, which means that we should perform this per-fragment division. --- Userland/Libraries/LibSoftGPU/Device.cpp | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/Userland/Libraries/LibSoftGPU/Device.cpp b/Userland/Libraries/LibSoftGPU/Device.cpp index 8ef5618c4e..e353036750 100644 --- a/Userland/Libraries/LibSoftGPU/Device.cpp +++ b/Userland/Libraries/LibSoftGPU/Device.cpp @@ -633,18 +633,6 @@ void Device::rasterize_point_antialiased(GPU::Vertex& point) void Device::rasterize_point(GPU::Vertex& point) { - // Divide texture coordinates R, S and T by Q - for (size_t i = 0; i < GPU::NUM_TEXTURE_UNITS; ++i) { - auto& tex_coord = point.tex_coords[i]; - auto one_over_w = 1 / tex_coord.w(); - tex_coord = { - tex_coord.x() * one_over_w, - tex_coord.y() * one_over_w, - tex_coord.z() * one_over_w, - tex_coord.w(), - }; - } - if (m_options.point_smooth) rasterize_point_antialiased(point); else @@ -1188,7 +1176,8 @@ ALWAYS_INLINE void Device::shade_fragments(PixelQuad& quad) continue; auto const& sampler = m_samplers[i]; - auto texel = sampler.sample_2d(quad.texture_coordinates[i].xy()); + // OpenGL 2.0 ΒΆ 3.5.1 states (in a roundabout way) that texture coordinates must be divided by Q + auto texel = sampler.sample_2d(quad.texture_coordinates[i].xy() / quad.texture_coordinates[i].w()); texture_stage_texel[i] = texel; INCREASE_STATISTICS_COUNTER(g_num_sampler_calls, 1);