Skip to content

Commit

Permalink
Added customization options
Browse files Browse the repository at this point in the history
- Pixel size
- Pixel edge width
- Pixel edge opacity
  • Loading branch information
B1BU committed Nov 18, 2024
1 parent 9278823 commit 9c39a72
Showing 1 changed file with 40 additions and 8 deletions.
48 changes: 40 additions & 8 deletions Bibu_LCD_3x.hlsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
//!MAGPIE EFFECT
//!VERSION 4

//!PARAMETER
//!LABEL Pixel Size
//!DEFAULT 3
//!MIN 3
//!MAX 60
//!STEP 3
int pixelSize;

//!PARAMETER
//!LABEL Pixel Edge Width
//!DEFAULT 1
//!MIN 1
//!MAX 60
//!STEP 1
int pixelEdgeWidth;

//!PARAMETER
//!LABEL Pixel Edge Opacity
//!DEFAULT 0
//!MIN 0
//!MAX 1
//!STEP 0.025
float pixelEdgeOpacity;

//!TEXTURE
Texture2D INPUT;

Expand All @@ -19,22 +43,30 @@ float4 Pass1(float2 pos) {
// Get output size
const uint2 outputSize = GetOutputSize();

// Sample the texture color at the current position
// Sample color at current position
float4 color = INPUT.SampleLevel(sam, pos, 0);

// Initialize the output color
// Initialize output color
float4 outputColor = float4(0, 0, 0, color.a);

// Convert normalized position to pixel coordinates
int2 pixelPos = int2(pos * float2(outputSize) + 1);

// Use the pixel position to determine the color channel
if (pixelPos.x % 3 == 1) {
outputColor.r = color.r; // First third: Red only
} else if (pixelPos.x % 3 == 2) {
outputColor.g = color.g; // Second third: Green only
// Define pixel section
int2 pixelSection = (pixelPos / (pixelSize / 3)) % 3;

// Determine the color channel from pixel section
if (pixelSection.x == 1) {
outputColor.r = color.r; // First third: Red channel
} else if (pixelSection.x == 2) {
outputColor.g = color.g; // Second third: Green channel
} else {
outputColor.b = color.b; // Last third: Blue only
outputColor.b = color.b; // Last third: Blue channel
}

// Darken the bottom of every pixel
if (pixelEdgeOpacity && pixelPos.y % pixelSize < pixelEdgeWidth) {
outputColor -= pixelEdgeOpacity;
}

return outputColor;
Expand Down

0 comments on commit 9c39a72

Please sign in to comment.