forked from crosire/reshade-shaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chromakey.fx
127 lines (101 loc) · 3.15 KB
/
Chromakey.fx
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
Chromakey PS v1.4.0 (c) 2018 Jacob Maximilian Fober
This work is licensed under the Creative Commons
Attribution-ShareAlike 4.0 International License.
To view a copy of this license, visit
http://creativecommons.org/licenses/by-sa/4.0/.
*/
#include "ReShade.fxh"
#include "ReShadeUI.fxh"
////////////
/// MENU ///
////////////
uniform float Threshold < __UNIFORM_SLIDER_FLOAT1
ui_min = 0.0; ui_max = 0.999; ui_step = 0.001;
ui_category = "Distance adjustment";
> = 0.5;
uniform bool RadialX <
ui_label = "Horizontally radial depth";
ui_category = "Radial distance";
> = false;
uniform bool RadialY <
ui_label = "Vertically radial depth";
ui_category = "Radial distance";
> = false;
uniform int FOV < __UNIFORM_SLIDER_INT1
ui_label = "FOV (horizontal)";
ui_tooltip = "Field of view in degrees";
#if __RESHADE__ < 40000
ui_step = 1;
#endif
ui_min = 0; ui_max = 170;
ui_category = "Radial distance";
> = 90;
uniform int Pass < __UNIFORM_RADIO_INT1
ui_label = "Keying type";
ui_items = "Background key\0Foreground key\0";
ui_category = "Direction adjustment";
> = 0;
uniform int Color < __UNIFORM_RADIO_INT1
ui_label = "Keying color";
ui_tooltip = "Ultimatte(tm) Super Blue and Green are industry standard colors for chromakey";
ui_items = "Super Blue Ultimatte(tm)\0Green Ultimatte(tm)\0Custom\0";
ui_category = "Color settings";
> = 1;
uniform float3 CustomColor < __UNIFORM_COLOR_FLOAT3
ui_label = "Custom color";
ui_category = "Color settings";
> = float3(1.0, 0.0, 0.0);
uniform bool AntiAliased <
ui_label = "Anti-aliased mask";
ui_tooltip = "Disabling this option will reduce masking gaps";
ui_category = "Color settings";
> = true;
/////////////////
/// FUNCTIONS ///
/////////////////
float MaskAA(float2 texcoord)
{
// Sample depth image
float Depth = ReShade::GetLinearizedDepth(texcoord);
// Convert to radial depth
float2 Size;
Size.x = tan(radians(FOV*0.5));
Size.y = Size.x / ReShade::AspectRatio;
if(RadialX) Depth *= length(float2((texcoord.x-0.5)*Size.x, 1.0));
if(RadialY) Depth *= length(float2((texcoord.y-0.5)*Size.y, 1.0));
// Return jagged mask
if(!AntiAliased) return step(Threshold, Depth);
// Get half-pixel size in depth value
float hPixel = fwidth(Depth)*0.5;
return smoothstep(Threshold-hPixel, Threshold+hPixel, Depth);
}
//////////////
/// SHADER ///
//////////////
float3 ChromakeyPS(float4 vois : SV_Position, float2 texcoord : TexCoord) : SV_Target
{
// Define chromakey color, Ultimatte(tm) Super Blue, Ultimatte(tm) Green, or user color
float3 Screen;
switch(Color)
{
case 0:{ Screen = float3(0.07, 0.18, 0.72); break; } // Ultimatte(tm) Super Blue
case 1:{ Screen = float3(0.29, 0.84, 0.36); break; } // Ultimatte(tm) Green
case 2:{ Screen = CustomColor; break; } // User defined color
}
// Generate depth mask
float DepthMask = MaskAA(texcoord);
if(bool(Pass)) DepthMask = 1.0-DepthMask;
return lerp(tex2D(ReShade::BackBuffer, texcoord).rgb, Screen, DepthMask);
}
//////////////
/// OUTPUT ///
//////////////
technique Chromakey < ui_tooltip = "Generate green-screen wall based of depth"; >
{
pass
{
VertexShader = PostProcessVS;
PixelShader = ChromakeyPS;
}
}