Skip to content

Commit

Permalink
Overhual cCircles.fx
Browse files Browse the repository at this point in the history
  • Loading branch information
papadanku committed Jul 13, 2024
1 parent 19de0bf commit 19ef953
Showing 1 changed file with 82 additions and 37 deletions.
119 changes: 82 additions & 37 deletions shaders/cCircles.fx
Original file line number Diff line number Diff line change
@@ -1,62 +1,107 @@

#include "shared/cGraphics.fxh"
#include "shared/cMacros.fxh"
#include "shared/cColorSpaces.fxh"

/*
[Shader Options]
*/

uniform float _TileAmount <
ui_label = "Amount";
uniform int _Select <
ui_label = "Search Feature";
ui_type = "combo";
ui_items = "HSV: Hue\0HSV: Saturation\0HSV: Value\0HSL: Hue\0HSL: Saturation\0HSL: Lightness\0HSI: Hue\0HSI: Saturation\0HSI: Intensity\0";
> = 2;

uniform int _CircleAmount <
ui_label = "Number of Circles";
ui_type = "slider";
ui_min = 1;
ui_max = 100;
> = 50;

uniform float3 _FrontColor <
ui_label = "Foreground Color";
ui_type = "color";
ui_min = 0.0;
ui_max = 64.0;
> = 8.0;
ui_max = 1.0;
> = float3(1.0, 1.0, 1.0);

uniform float _TileRadius <
ui_label = "Radius";
ui_type = "slider";
uniform float3 _BackColor <
ui_label = "Background Color";
ui_type = "color";
ui_min = 0.0;
ui_max = 0.5;
> = 0.45;
ui_max = 1.0;
> = float3(0.0, 0.0, 0.0);


/*
[Pixel Shaders]
*/

float2 GetTiles(float2 Tex)
{
Tex *= _TileAmount;

// Get tex's row index
float RowIndex = step(1.0, GetMod(Tex.y, 2.0));

// Offset every odd row by 0.5
Tex.x += (RowIndex * 0.5);
Tex.x = (RowIndex == 1.0) ? -Tex.x : Tex.x;

return frac(Tex);
}

float4 PS_Circles(VS2PS_Quad Input) : SV_TARGET0
{
Input.Tex0 = Input.Tex0 * 2.0 - 1.0;
// Shrink the UV so [-1, 1] fills a square
float2 Tiles = (Input.Tex0.xy * _CircleAmount);
float2 Tex = floor(Tiles) / _CircleAmount;

// Stretch the image to 1:1 aspect ratio
float2 BSize = float2(BUFFER_WIDTH, BUFFER_HEIGHT);
float2 Tex = (Input.Tex0.xy * BSize) / min(BSize.x, BSize.y);
// Get pixelated color information
float4 Color = tex2D(CShade_SampleColorTex, Tex);
float Feature = 0.0;

// Tile data
float2 TexTiles = GetTiles(Tex);
float TileDist = distance(TexTiles, 0.5);
float EdgeAA = fwidth(TileDist);

// Display data
float3 Texture = tex2D(CShade_SampleColorTex, TexTiles).rgb;
float CircleMask = smoothstep(_TileRadius - EdgeAA, _TileRadius, TileDist);
CircleMask = saturate(1.0 - CircleMask);
switch(_Select)
{
case 0:
Feature = GetHSVfromRGB(Color.rgb).r;
break;
case 1:
Feature = GetHSVfromRGB(Color.rgb).g;
break;
case 2:
Feature = GetHSVfromRGB(Color.rgb).b;
break;
case 3:
Feature = GetHSLfromRGB(Color.rgb).r;
break;
case 4:
Feature = GetHSLfromRGB(Color.rgb).g;
break;
case 5:
Feature = GetHSLfromRGB(Color.rgb).b;
break;
case 6:
Feature = GetHSIfromRGB(Color.rgb).r;
break;
case 7:
Feature = GetHSIfromRGB(Color.rgb).g;
break;
case 8:
Feature = GetHSIfromRGB(Color.rgb).b;
break;
default:
Feature = 0.0;
break;
}

return float4(Texture * CircleMask, 1.0);
// Create the UV for the circles
float2 CircleTiles = frac(Tiles) * 2.0 - 1.0;
// Shrink the UV so [-1, 1] fills a square
#if BUFFER_WIDTH > BUFFER_HEIGHT
CircleTiles.x *= ASPECT_RATIO;
#else
CircleTiles.y *= ASPECT_RATIO;
#endif
float CircleDist = length(CircleTiles);

// Create the circle
float FeatureFactor = lerp(0.5, 1.0, Feature);
float Circles = smoothstep(0.8 * (1.0 - FeatureFactor), 0.5, CircleDist * FeatureFactor);

// Mix colors together
float3 OutputColor = lerp(Circles, _BackColor, Feature);
OutputColor = lerp(_BackColor, _FrontColor, Circles);

return float4(OutputColor, 1.0);
}

technique CShade_Circles
Expand Down

0 comments on commit 19ef953

Please sign in to comment.