Skip to content

Commit

Permalink
cCircles, cEnsor: Fixed >SM3 bugs, updated prepass
Browse files Browse the repository at this point in the history
  • Loading branch information
papadanku committed Sep 8, 2024
1 parent 4cc4500 commit 57b86be
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 61 deletions.
72 changes: 38 additions & 34 deletions shaders/cCircles.fx
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
56 changes: 29 additions & 27 deletions shaders/cEnsor.fx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"; >
Expand All @@ -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
Expand Down

0 comments on commit 57b86be

Please sign in to comment.