diff --git a/src/video_core/renderer_vulkan/vk_shader_gen.cpp b/src/video_core/renderer_vulkan/vk_shader_gen.cpp index 8286e1068..37aac4dd9 100644 --- a/src/video_core/renderer_vulkan/vk_shader_gen.cpp +++ b/src/video_core/renderer_vulkan/vk_shader_gen.cpp @@ -1693,6 +1693,7 @@ std::string GenerateTrivialVertexShader(bool use_clip_planes) { out += UniformBlockDef; out += R"( +const float EPSILON_Z = 0.00000001f; void main() { primary_color = vert_color; @@ -1702,13 +1703,17 @@ void main() { texcoord0_w = vert_texcoord0_w; normquat = vert_normquat; view = vert_view; - gl_Position = vec4(vert_position.x, vert_position.y, -vert_position.z, vert_position.w); + vec4 vtx_pos = vert_position; + if (abs(vtx_pos.z) < EPSILON_Z) { + vtx_pos.z = 0.f; + } + gl_Position = vec4(vtx_pos.x, vtx_pos.y, -vtx_pos.z, vtx_pos.w); )"; if (use_clip_planes) { out += R"( - gl_ClipDistance[0] = -vert_position.z; // fixed PICA clipping plane z <= 0 + gl_ClipDistance[0] = -vtx_pos.z; // fixed PICA clipping plane z <= 0 if (enable_clip1) { - gl_ClipDistance[1] = dot(clip_coef, vert_position); + gl_ClipDistance[1] = dot(clip_coef, vtx_pos); } else { gl_ClipDistance[1] = 0; } @@ -1808,6 +1813,7 @@ layout (set = 0, binding = 0, std140) uniform vs_config { return "0.0"; }; + out += "const float EPSILON_Z = 0.00000001f;\n\n"; out += "vec4 GetVertexQuaternion() {\n"; out += " return vec4(" + semantic(VSOutputAttributes::QUATERNION_X) + ", " + semantic(VSOutputAttributes::QUATERNION_Y) + ", " + @@ -1820,6 +1826,9 @@ layout (set = 0, binding = 0, std140) uniform vs_config { semantic(VSOutputAttributes::POSITION_Y) + ", " + semantic(VSOutputAttributes::POSITION_Z) + ", " + semantic(VSOutputAttributes::POSITION_W) + ");\n"; + out += " if (abs(vtx_pos.z) < EPSILON_Z) {\n"; + out += " vtx_pos.z = 0.f;\n"; + out += " }\n"; out += " gl_Position = vec4(vtx_pos.x, vtx_pos.y, -vtx_pos.z, vtx_pos.w);\n"; if (config.use_clip_planes) { out += " gl_ClipDistance[0] = -vtx_pos.z;\n"; // fixed PICA clipping plane z <= 0 @@ -1894,6 +1903,7 @@ struct Vertex { return "0.0"; }; + out += "const float EPSILON_Z = 0.00000001f;\n\n"; out += "vec4 GetVertexQuaternion(Vertex vtx) {\n"; out += " return vec4(" + semantic(VSOutputAttributes::QUATERNION_X) + ", " + semantic(VSOutputAttributes::QUATERNION_Y) + ", " + @@ -1906,6 +1916,9 @@ struct Vertex { semantic(VSOutputAttributes::POSITION_Y) + ", " + semantic(VSOutputAttributes::POSITION_Z) + ", " + semantic(VSOutputAttributes::POSITION_W) + ");\n"; + out += " if (abs(vtx_pos.z) < EPSILON_Z) {\n"; + out += " vtx_pos.z = 0.f;\n"; + out += " }\n"; out += " gl_Position = vec4(vtx_pos.x, vtx_pos.y, -vtx_pos.z, vtx_pos.w);\n"; if (use_clip_planes) { out += " gl_ClipDistance[0] = -vtx_pos.z;\n"; // fixed PICA clipping plane z <= 0 diff --git a/src/video_core/renderer_vulkan/vk_shader_gen_spv.cpp b/src/video_core/renderer_vulkan/vk_shader_gen_spv.cpp index 9656a2db3..f1efcf86f 100644 --- a/src/video_core/renderer_vulkan/vk_shader_gen_spv.cpp +++ b/src/video_core/renderer_vulkan/vk_shader_gen_spv.cpp @@ -53,7 +53,7 @@ void FragmentModule::Generate() { combiner_buffer = ConstF32(0.f, 0.f, 0.f, 0.f); next_combiner_buffer = GetShaderDataMember(vec_ids.Get(4), ConstS32(27)); - last_tex_env_out = ConstF32(0.f, 0.f, 0.f, 0.f); + last_tex_env_out = rounded_primary_color; // Write shader bytecode to emulate PICA TEV stages for (std::size_t index = 0; index < config.state.tev_stages.size(); ++index) {