Skip to content

Instantly share code, notes, and snippets.

@runewake2
Created February 27, 2023 05:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save runewake2/b9e6749262d0db4de68ab875fe71c93b to your computer and use it in GitHub Desktop.
Save runewake2/b9e6749262d0db4de68ab875fe71c93b to your computer and use it in GitHub Desktop.
A windows terminal shader that can render different animated pride flags as a background.
// Flag Shader for Windows Terminal
// By: Sam Wronski - worldofzero.com
//
// A quick flag/line rendering shader for the Windwos Terminal
// Customize it below by modifying the settings
//
// To enable shaders in Windows Terminal (an experimental feautre currently):
// "profiles": {
// "defaults": {
// "experimental.pixelShaderPath": "The Path to Your Shader"
// },
// }
// Inputs from the Terminal
Texture2D shaderTexture;
SamplerState samplerState;
cbuffer PixelShaderSettings {
float Time;
float Scale;
float2 Resolution;
float4 Background;
};
// Settings
// Select a flag and then past your selection below inside the `flagColor` function.
static float3 PrideFlag[6] = { // 🏳️‍🌈
float3(0.95,0,0),
float3(1,141.0/255,0),
float3(1,0.95,0),
float3(0,129.0/255,33.0/255),
float3(0,76.0/255,1),
float3(118.0/255, 1.0/255, 136.0/255)
};
static float3 TransFlag[5] = { // 🏳️‍⚧️
float3(0.33,0.8,0.95),
float3(0.97,0.6,0.675),
float3(1.0,1.0,1.0),
float3(0.97,0.6,0.675),
float3(0.33,0.8,0.95)
};
static float3 NonBinaryFlag[4] = {
float3(250.0/255, 243.0/255, 0),
float3(1.0, 1.0, 1.0),
float3(152.0/255, 90.0/255, 212.0/255),
float3(44.0/255, 44.0/255, 44.0/255)
};
// Flag Strength is the opacity of the flag (1.0 is completely opaque)
#define FLAGSTRENGTH 0.125
// Control the sin wave length and strength of the flag wave
#define PERIOD1POSITION 10
#define PERIOD2POSITION 5.5
#define PERIOD1STRENGTH 0.15
#define PERIOD2STRENGTH 0.2
#define PERIOD1TIME 2.5
#define PERIOD2TIME 2
float4 flagColor(float position) {
// Replace these first two lines with the flag you have chosen to use (see above)
// Important! This should equal the size of the flag color buffer you use
float3 flag[] = PrideFlag;
float colorCount = 6;
float3 result = flag[clamp(floor(position * colorCount), 0 , colorCount-1)];
return float4(result.rgb, 1.0);
}
float4 main(float4 pos : SV_POSITION, float2 tex : TEXCOORD) : SV_TARGET
{
float2 correctedCoordinate = (pos - 0.5 * Resolution.xy) / Resolution.y;
float height = pos.y;
height += sin(Time * PERIOD1TIME + pos.x / Resolution.x * PERIOD1POSITION ) / PERIOD1STRENGTH;
height += sin(Time * PERIOD2TIME + pos.x / Resolution.x * PERIOD2POSITION ) / PERIOD2STRENGTH;
return flagColor(height / Resolution.y) * FLAGSTRENGTH + shaderTexture.Sample(samplerState, tex);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment