From dc48deaeccc41a3e86d5c63523e712f4bb8618c2 Mon Sep 17 00:00:00 2001 From: Dwayne Slater Date: Wed, 8 Nov 2017 20:42:25 -0500 Subject: [PATCH 1/3] Round primary color inputs in software rasterizer OpenGL version coming soon. --- src/video_core/swrasterizer/rasterizer.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/video_core/swrasterizer/rasterizer.cpp b/src/video_core/swrasterizer/rasterizer.cpp index 533ee6f01..2ee28ed53 100644 --- a/src/video_core/swrasterizer/rasterizer.cpp +++ b/src/video_core/swrasterizer/rasterizer.cpp @@ -293,18 +293,18 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve }; Math::Vec4 primary_color{ - (u8)( + static_cast(round( GetInterpolatedAttribute(v0.color.r(), v1.color.r(), v2.color.r()).ToFloat32() * - 255), - (u8)( + 255)), + static_cast(round( GetInterpolatedAttribute(v0.color.g(), v1.color.g(), v2.color.g()).ToFloat32() * - 255), - (u8)( + 255)), + static_cast(round( GetInterpolatedAttribute(v0.color.b(), v1.color.b(), v2.color.b()).ToFloat32() * - 255), - (u8)( + 255)), + static_cast(round( GetInterpolatedAttribute(v0.color.a(), v1.color.a(), v2.color.a()).ToFloat32() * - 255), + 255)), }; Math::Vec2 uv[3]; From 350082ab753134f642884d1e1a69b44c37332b51 Mon Sep 17 00:00:00 2001 From: Dwayne Slater Date: Wed, 8 Nov 2017 22:50:42 -0500 Subject: [PATCH 2/3] Fix logic ops not being enabled in the OpenGL renderer --- src/video_core/renderer_opengl/gl_rasterizer.cpp | 2 ++ src/video_core/renderer_opengl/gl_state.cpp | 5 +---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 16f0726ad..599e6e2af 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -168,6 +168,8 @@ RasterizerOpenGL::RasterizerOpenGL() : shader_dirty(true) { glActiveTexture(TextureUnits::ProcTexDiffLUT.Enum()); glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, proctex_diff_lut_buffer.handle); + glEnable(GL_BLEND); + // Sync fixed function OpenGL state SyncClipEnabled(); SyncClipCoef(); diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cpp index 5770ae08f..9fa353fe4 100644 --- a/src/video_core/renderer_opengl/gl_state.cpp +++ b/src/video_core/renderer_opengl/gl_state.cpp @@ -33,7 +33,7 @@ OpenGLState::OpenGLState() { stencil.action_depth_pass = GL_KEEP; stencil.action_stencil_fail = GL_KEEP; - blend.enabled = false; + blend.enabled = true; blend.rgb_equation = GL_FUNC_ADD; blend.a_equation = GL_FUNC_ADD; blend.src_rgb_func = GL_ONE; @@ -148,9 +148,6 @@ void OpenGLState::Apply() const { if (blend.enabled != cur_state.blend.enabled) { if (blend.enabled) { glEnable(GL_BLEND); - - cur_state.logic_op = GL_COPY; - glLogicOp(cur_state.logic_op); glDisable(GL_COLOR_LOGIC_OP); } else { glDisable(GL_BLEND); From fcc141a32738996143bce430dd73c85050e33a0a Mon Sep 17 00:00:00 2001 From: Dwayne Slater Date: Wed, 29 Nov 2017 16:49:04 -0500 Subject: [PATCH 3/3] Maintain the PICA's 8 bits of color precision when using the interpolated primary color This matches the software renderer by using round. The actual hardware rounds the results up instead of flooring. --- src/video_core/renderer_opengl/gl_shader_gen.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp index 531247d2a..9a61c0cfc 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.cpp +++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp @@ -234,7 +234,7 @@ static void AppendSource(std::string& out, const PicaShaderConfig& config, using Source = TevStageConfig::Source; switch (source) { case Source::PrimaryColor: - out += "primary_color"; + out += "rounded_primary_color"; break; case Source::PrimaryFragmentColor: out += "primary_fragment_color"; @@ -1100,8 +1100,11 @@ float LookupLightingLUTSigned(int lut_index, float pos) { if (config.state.proctex.enable) AppendProcTexSampler(out, config); + // We round the interpolated primary color to the nearest 1/255th + // This maintains the PICA's 8 bits of precision out += R"( void main() { +vec4 rounded_primary_color = round(primary_color * 255.0) / 255.0; vec4 primary_fragment_color = vec4(0.0); vec4 secondary_fragment_color = vec4(0.0); )";