diff --git a/src/core/gpu_hw_shadergen.cpp b/src/core/gpu_hw_shadergen.cpp index 47788bb01..3de476be4 100644 --- a/src/core/gpu_hw_shadergen.cpp +++ b/src/core/gpu_hw_shadergen.cpp @@ -167,8 +167,9 @@ std::string GPU_HW_ShaderGen::GenerateBatchVertexShader(bool textured) void GPU_HW_ShaderGen::WriteBatchTextureFilter(std::stringstream& ss, GPUTextureFilter texture_filter) { // JINC2 and xBRZ shaders originally from beetle-psx, modified to support filtering mask channel. - if (texture_filter == GPUTextureFilter::Bilinear) + if (texture_filter == GPUTextureFilter::Bilinear || texture_filter == GPUTextureFilter::BilinearBinAlpha) { + DefineMacro(ss, "BINALPHA", texture_filter == GPUTextureFilter::BilinearBinAlpha); ss << R"( void FilteredSampleFromVRAM(uint4 texpage, float2 coords, float4 uv_limits, out float4 texcol, out float ialpha) @@ -200,11 +201,16 @@ void FilteredSampleFromVRAM(uint4 texpage, float2 coords, float4 uv_limits, // Compensate for partially transparent sampling. if (ialpha > 0.0) texcol.rgb /= float3(ialpha, ialpha, ialpha); + +#if BINALPHA + ialpha = (ialpha >= 0.5) ? 1.0 : 0.0; +#endif } )"; } - else if (texture_filter == GPUTextureFilter::JINC2) + else if (texture_filter == GPUTextureFilter::JINC2 || texture_filter == GPUTextureFilter::JINC2BinAlpha) { + DefineMacro(ss, "BINALPHA", texture_filter == GPUTextureFilter::JINC2BinAlpha); ss << R"( CONSTANT float JINC2_WINDOW_SINC = 0.44; CONSTANT float JINC2_SINC = 0.82; @@ -347,11 +353,16 @@ void FilteredSampleFromVRAM(uint4 texpage, float2 coords, float4 uv_limits, // Compensate for partially transparent sampling. if (ialpha > 0.0) texcol.rgb /= float3(ialpha, ialpha, ialpha); + +#if BINALPHA + ialpha = (ialpha >= 0.5) ? 1.0 : 0.0; +#endif } )"; } - else if (texture_filter == GPUTextureFilter::xBR) + else if (texture_filter == GPUTextureFilter::xBR || texture_filter == GPUTextureFilter::xBRBinAlpha) { + DefineMacro(ss, "BINALPHA", texture_filter == GPUTextureFilter::xBRBinAlpha); ss << R"( CONSTANT int BLEND_NONE = 0; CONSTANT int BLEND_NORMAL = 1; @@ -626,6 +637,10 @@ void FilteredSampleFromVRAM(uint4 texpage, float2 coords, float4 uv_limits, // Compensate for partially transparent sampling. if (ialpha > 0.0) texcol.rgb /= float3(ialpha, ialpha, ialpha); + +#if BINALPHA + ialpha = (ialpha >= 0.5) ? 1.0 : 0.0; +#endif } #undef P @@ -1172,7 +1187,7 @@ std::string GPU_HW_ShaderGen::GenerateVRAMCopyFragmentShader() { // TODO: This won't currently work because we can't bind the texture to both the shader and framebuffer. const bool msaa = false; - + std::stringstream ss; WriteHeader(ss); WriteCommonFunctions(ss); diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 945308742..ffa1dc155 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -513,10 +513,13 @@ const char* Settings::GetRendererDisplayName(GPURenderer renderer) return s_gpu_renderer_display_names[static_cast(renderer)]; } -static constexpr auto s_texture_filter_names = make_array("Nearest", "Bilinear", "JINC2", "xBR"); +static constexpr auto s_texture_filter_names = + make_array("Nearest", "Bilinear", "BilinearBinAlpha", "JINC2", "JINC2BinAlpha", "xBR", "xBRBinAlpha"); static constexpr auto s_texture_filter_display_names = make_array(TRANSLATABLE("GPUTextureFilter", "Nearest-Neighbor"), TRANSLATABLE("GPUTextureFilter", "Bilinear"), - TRANSLATABLE("GPUTextureFilter", "JINC2"), TRANSLATABLE("GPUTextureFilter", "xBR")); + TRANSLATABLE("GPUTextureFilter", "Bilinear (No Edge Blending)"), TRANSLATABLE("GPUTextureFilter", "JINC2"), + TRANSLATABLE("GPUTextureFilter", "JINC2 (No Edge Blending)"), TRANSLATABLE("GPUTextureFilter", "xBR"), + TRANSLATABLE("GPUTextureFilter", "xBR (No Edge Blending)")); std::optional Settings::ParseTextureFilterName(const char* str) { diff --git a/src/core/types.h b/src/core/types.h index 700df5c4b..90f2cef82 100644 --- a/src/core/types.h +++ b/src/core/types.h @@ -67,8 +67,11 @@ enum class GPUTextureFilter : u8 { Nearest, Bilinear, + BilinearBinAlpha, JINC2, + JINC2BinAlpha, xBR, + xBRBinAlpha, Count };