-
Notifications
You must be signed in to change notification settings - Fork 36
/
transparent.hlsl
86 lines (71 loc) · 2.33 KB
/
transparent.hlsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// This shader helps to add transparency for vim themes that use xterm colors.
// Define map for PS input
struct PSInput {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
// The terminal graphics as a texture
Texture2D shaderTexture : register(t0);
SamplerState samplerState : register(s0);
// Terminal settings such as the resolution of the texture
cbuffer PixelShaderSettings : register(b0) {
// The number of seconds since the pixel shader was enabled
float Time;
// UI Scale
float Scale;
// Resolution of the shaderTexture
float2 Resolution;
// Background color as rgba
float4 Background;
};
// Settings - Debug
#define DEBUG 0
#define DEBUG_ROTATION 0.25
#define DEBUG_SEGMENTS 1
#define DEBUG_OFFSET 0.425
#define DEBUG_WIDTH 0.15
#define SHOW_UV 0
#define SHOW_POS 0
#if SHADERed
// Must be inlined to the shader or it breaks single-step debugging
PSInput patchCoordinates(PSInput pin);
struct DebugOut {
bool show;
float4 color;
};
DebugOut debug(float4 pos, float2 uv);
#endif
// Set the color that is supposed to be transparent
static const float3 chromaKey = float3(8.0f / 0xFF, 8.0f / 0xFF, 8.0f / 0xFF);
float4 main(PSInput pin) : SV_TARGET
{
// Use pos and uv in the shader the same as we might use
// Time, Scale, Resolution, and Background. Unlike those,
// they are local variables in this implementation and should
// be passed to any functions using them.
float4 pos = pin.pos;
float2 uv = pin.uv;
#if SHADERed
// Must be inlined to the shader or it breaks single-step debugging
// Patches the pin pos and uv
PSInput patchedPin = patchCoordinates(pin);
pos = patchedPin.pos;
uv = patchedPin.uv;
// Patches in the UV Debug output
DebugOut debugOut = debug(pos, uv);
if (debugOut.show) { return debugOut.color; }
#endif
//-- Shader goes here --//
float4 color = shaderTexture.Sample(samplerState, uv);
// Filter by chroma key
if(color.r == chromaKey.r && color.g == chromaKey.g && color.b == chromaKey.b)
{
return float4(0.0f, 0.0f, 0.0f, 0.0f);
}
return color;
//-- Shader goes here --//
}
#if SHADERed
#include "SHADERed/PS-DebugPatch.hlsl"
#include "SHADERed/PS-CoordinatesPatch.hlsl"
#endif