From 57b86bec6b05a395e988b5c93148ab018a09303d Mon Sep 17 00:00:00 2001 From: papadanku Date: Sat, 7 Sep 2024 20:01:37 -0700 Subject: [PATCH] cCircles, cEnsor: Fixed >SM3 bugs, updated prepass --- shaders/cCircles.fx | 72 ++++++++++++++++++++++++--------------------- shaders/cEnsor.fx | 56 ++++++++++++++++++----------------- 2 files changed, 67 insertions(+), 61 deletions(-) diff --git a/shaders/cCircles.fx b/shaders/cCircles.fx index 2fbc4d0..897c1bd 100644 --- a/shaders/cCircles.fx +++ b/shaders/cCircles.fx @@ -145,8 +145,8 @@ uniform float3 _BackColor < [Textures and Samplers] */ -CREATE_TEXTURE_POOLED(TempTex0_RGBA8, BUFFER_SIZE_0, RGBA8, 8) -CREATE_SRGB_SAMPLER(SampleTempTex0, TempTex0_RGBA8, LINEAR, MIRROR, MIRROR, MIRROR) +CREATE_TEXTURE_POOLED(TempTex0_RGBA8_8, BUFFER_SIZE_0, RGBA8, 8) +CREATE_SRGB_SAMPLER(SampleTempTex0, TempTex0_RGBA8_8, LINEAR, MIRROR, MIRROR, MIRROR) sampler2D CShade_SampleColorTexMirror { @@ -226,70 +226,69 @@ float GetTileCircleLength(Tile Input) [Pixel Shaders] */ -float4 PS_Blit(CShade_VS2PS_Quad Input) : SV_TARGET0 -{ - return tex2D(CShade_SampleColorTex, Input.Tex0); -} - #if ENABLE_MONO - float4 PS_Circles(CShade_VS2PS_Quad Input) : SV_TARGET0 + float4 PS_Blit(CShade_VS2PS_Quad Input) : SV_TARGET0 { - // Precalculate our needed LOD for all channels - float2 TexSize = CShade_GetScreenSizeFromTex(Input.Tex0); - float LOD = max(0.0, log2(max(TexSize.x, TexSize.y) / _CircleAmount)); - - // Create tiles - Tile MainTiles = GetTiles(Input.Tex0.xy, _Offset); - - // Get texture information - float4 Blocks = tex2Dlod(SampleTempTex0, float4(GetBlockTex(MainTiles.Index), 0.0, LOD)); - Blocks = (Blocks * _InputMultiplier) + _InputBias; - - float Feature = 0.0; - + float4 Color = tex2D(CShade_SampleColorTex, Input.Tex0); switch(_Select) { case 0: - Feature = CColor_GetHSVfromRGB(Blocks.rgb).r; + Color.a = CColor_GetHSVfromRGB(Color.rgb).r; break; case 1: - Feature = CColor_GetHSVfromRGB(Blocks.rgb).g; + Color.a = CColor_GetHSVfromRGB(Color.rgb).g; break; case 2: - Feature = CColor_GetHSVfromRGB(Blocks.rgb).b; + Color.a = CColor_GetHSVfromRGB(Color.rgb).b; break; case 3: - Feature = CColor_GetHSLfromRGB(Blocks.rgb).r; + Color.a = CColor_GetHSLfromRGB(Color.rgb).r; break; case 4: - Feature = CColor_GetHSLfromRGB(Blocks.rgb).g; + Color.a = CColor_GetHSLfromRGB(Color.rgb).g; break; case 5: - Feature = CColor_GetHSLfromRGB(Blocks.rgb).b; + Color.a = CColor_GetHSLfromRGB(Color.rgb).b; break; case 6: - Feature = CColor_GetHSIfromRGB(Blocks.rgb).r; + Color.a = CColor_GetHSIfromRGB(Color.rgb).r; break; case 7: - Feature = CColor_GetHSIfromRGB(Blocks.rgb).g; + Color.a = CColor_GetHSIfromRGB(Color.rgb).g; break; case 8: - Feature = CColor_GetHSIfromRGB(Blocks.rgb).b; + Color.a = CColor_GetHSIfromRGB(Color.rgb).b; break; default: - Feature = 0.0; + Color.a = 1.0; break; } + return Color; + } + + float4 PS_Circles(CShade_VS2PS_Quad Input) : SV_TARGET0 + { + // Precalculate our needed LOD for all channels + float2 TexSize = CShade_GetScreenSizeFromTex(Input.Tex0); + float LOD = max(0.0, log2(max(TexSize.x, TexSize.y) / _CircleAmount)); + + // Create tiles + Tile MainTiles = GetTiles(Input.Tex0.xy, _Offset); + + // Get texture information + float4 Blocks = tex2Dlod(SampleTempTex0, float4(GetBlockTex(MainTiles.Index), 0.0, LOD)); + Blocks.a = (Blocks.a * _InputMultiplier) + _InputBias; + // Create the UV for the circles float CircleDist = GetTileCircleLength(MainTiles); // Create the circle - float Circles = smoothstep(0.89 - fwidth(CircleDist), 0.9, CircleDist + Feature); + float Circles = smoothstep(0.89 - fwidth(CircleDist), 0.9, CircleDist + Blocks.a); // Mix colors together float3 OutputColor = lerp(_FrontColor, _BackColor, Circles); - OutputColor = lerp(OutputColor, _BackColor, saturate(Feature)); + OutputColor = lerp(OutputColor, _BackColor, saturate(Blocks.a)); // Crop the image OutputColor = lerp(_BackColor, OutputColor, MainTiles.Value.x > _Crop.x); @@ -300,6 +299,11 @@ float4 PS_Blit(CShade_VS2PS_Quad Input) : SV_TARGET0 return CBlend_OutputChannels(float4(OutputColor.rgb, _CShadeAlphaFactor)); } #else + float4 PS_Blit(CShade_VS2PS_Quad Input) : SV_TARGET0 + { + return tex2D(CShade_SampleColorTex, Input.Tex0); + } + float4 PS_Circles(CShade_VS2PS_Quad Input) : SV_TARGET0 { // Precalculate our needed LOD for all channels @@ -357,7 +361,7 @@ technique CShade_Circles < ui_tooltip = "Creates circles based on image features { VertexShader = CShade_VS_Quad; PixelShader = PS_Blit; - RenderTarget = TempTex0_RGBA8; + RenderTarget = TempTex0_RGBA8_8; } pass diff --git a/shaders/cEnsor.fx b/shaders/cEnsor.fx index ed91c8d..742b56c 100644 --- a/shaders/cEnsor.fx +++ b/shaders/cEnsor.fx @@ -36,61 +36,63 @@ uniform int _DisplayMode < #include "shared/cShade.fxh" #include "shared/cBlend.fxh" -CREATE_TEXTURE_POOLED(TempTex0_RGBA8, BUFFER_SIZE_0, RGBA8, 8) -CREATE_SRGB_SAMPLER(SampleTempTex0, TempTex0_RGBA8, POINT, MIRROR, MIRROR, MIRROR) +CREATE_TEXTURE_POOLED(TempTex0_RGBA8_8, BUFFER_SIZE_0, RGBA8, 8) +CREATE_SRGB_SAMPLER(SampleTempTex0, TempTex0_RGBA8_8, POINT, MIRROR, MIRROR, MIRROR) float4 PS_Blit(CShade_VS2PS_Quad Input) : SV_TARGET0 -{ - return float4(tex2D(CShade_SampleColorTex, Input.Tex0).rgb, 1.0); -} - -float4 PS_Censor(CShade_VS2PS_Quad Input) : SV_TARGET0 { float4 Color = tex2D(CShade_SampleColorTex, Input.Tex0); - float4 Pixel = tex2Dlod(SampleTempTex0, float4(Input.Tex0, 0.0, _Blockiness)); - - // Initialize variables - float4 Feature = 0.0; - bool4 Mask = false; - float4 OutputColor = 0.0; switch(_DetectionMode) { case 0: - Feature = Pixel; + Color.a = 1.0; break; case 1: - Feature = CColor_GetHSVfromRGB(Pixel.rgb).r; + Color.a = CColor_GetHSVfromRGB(Color.rgb).r; break; case 2: - Feature = CColor_GetHSVfromRGB(Pixel.rgb).g; + Color.a = CColor_GetHSVfromRGB(Color.rgb).g; break; case 3: - Feature = CColor_GetHSVfromRGB(Pixel.rgb).b; + Color.a = CColor_GetHSVfromRGB(Color.rgb).b; break; case 4: - Feature = CColor_GetHSLfromRGB(Pixel.rgb).r; + Color.a = CColor_GetHSLfromRGB(Color.rgb).r; break; case 5: - Feature = CColor_GetHSLfromRGB(Pixel.rgb).g; + Color.a = CColor_GetHSLfromRGB(Color.rgb).g; break; case 6: - Feature = CColor_GetHSLfromRGB(Pixel.rgb).b; + Color.a = CColor_GetHSLfromRGB(Color.rgb).b; break; case 7: - Feature = CColor_GetHSIfromRGB(Pixel.rgb).r; + Color.a = CColor_GetHSIfromRGB(Color.rgb).r; break; case 8: - Feature = CColor_GetHSIfromRGB(Pixel.rgb).g; + Color.a = CColor_GetHSIfromRGB(Color.rgb).g; break; case 9: - Feature = CColor_GetHSIfromRGB(Pixel.rgb).b; + Color.a = CColor_GetHSIfromRGB(Color.rgb).b; break; default: - Feature = 0.0; + Color.a = 1.0; break; } + return Color; +} + +float4 PS_Censor(CShade_VS2PS_Quad Input) : SV_TARGET0 +{ + float4 Color = tex2D(CShade_SampleColorTex, Input.Tex0); + float4 Blocks = tex2Dlod(SampleTempTex0, float4(Input.Tex0, 0.0, _Blockiness)); + + // Initialize variables + float3 Feature = (_DetectionMode == 0) ? Blocks.rgb : Blocks.aaa; + bool3 Mask = false; + float3 OutputColor = 0.0; + switch (_Comparison) { case 0: @@ -119,10 +121,10 @@ float4 PS_Censor(CShade_VS2PS_Quad Input) : SV_TARGET0 } else { - OutputColor = lerp(Color, Pixel, Mask); + OutputColor = lerp(Color.rgb, Blocks.rgb, Mask); } - return CBlend_OutputChannels(float4(OutputColor.rgb, _CShadeAlphaFactor)); + return CBlend_OutputChannels(float4(OutputColor, _CShadeAlphaFactor)); } technique CShade_Censor < ui_tooltip = "Pixelates the screen based on features"; > @@ -131,7 +133,7 @@ technique CShade_Censor < ui_tooltip = "Pixelates the screen based on features"; { VertexShader = CShade_VS_Quad; PixelShader = PS_Blit; - RenderTarget = TempTex0_RGBA8; + RenderTarget = TempTex0_RGBA8_8; } pass