Skip to content

Commit b140299

Browse files
authored
Implement user-specified pixel shaders, redux (#8565)
Co-authored-by: mrange <[email protected]> I loved the pixel shaders in #7058, but that PR needed a bit of polish to be ready for ingestion. This PR is almost _exactly_ that PR, with some small changes. * It adds a new pre-profile setting `"experimental.pixelShaderPath"`, which lets the user set a pixel shader to use with the Terminal. - CHANGED FROM #7058: It does _not_ add any built-in shaders. - CHANGED FROM #7058: it will _override_ `experimental.retroTerminalEffect` * It adds a bunch of sample shaders in `samples/shaders`. Included: - A NOP shader as a base to build from. - An "invert" shader that inverts the colors, as a simple example - An "grayscale" shader that converts all colors to grayscale, as a simple example - An "raster bars" shader that draws some colored bars on the screen with a drop shadow, as a more involved example - The original retro terminal effects, as a more involved example - It also includes a broken shader, as an example of what heppens when the shader fails to compile - CHANGED FROM #7058: It does _not_ add the "retroII" shader we were all worried about. * When a shader fails to be found or fails to compile, we'll display an error dialog to the user with a relevant error message. - CHANGED FROM #7058: Originally, #7058 would display "error bars" on the screen. I've removed that, and had the Terminal disable the shader entirely then. * Renames the `toggleRetroEffect` action to `toggleShaderEffect`. (`toggleRetroEffect` is now an alias to `toggleShaderEffect`). This action will turn the shader OR the retro effects on/off. `toggleShaderEffect` works the way you'd expect it to, but the mental math on _how_ is a little weird. The logic is basically: ``` useShader = shaderEffectsEnabled ? (pixelShaderProvided ? pixelShader : (retroEffectEnabled ? retroEffect : null ) ) : null ``` and `toggleShaderEffect` toggles `shaderEffectsEnabled`. * If you've got both a shader and retro enabled, `toggleShaderEffect` will toggle between the shader on/off. * If you've got a shader and retro disabled, `toggleShaderEffect` will toggle between the shader on/off. References #6191 References #7058 Closes #7013 Closes #3930 "Add setting to retro terminal shader to control blur radius, color" Closes #3929 "Add setting to retro terminal shader to enable drawing scanlines" - At this point, just roll your own version of the shader.
1 parent e943785 commit b140299

36 files changed

+843
-116
lines changed

.github/actions/spell-check/dictionary/apis.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ cmdletbinding
88
COLORPROPERTY
99
CXICON
1010
CYICON
11+
D2DERR_SHADER_COMPILE_FAILED
12+
DERR
1113
environstrings
1214
EXPCMDFLAGS
1315
EXPCMDSTATE
16+
frac
1417
fullkbd
1518
futex
1619
GETDESKWALLPAPER
@@ -34,7 +37,6 @@ IObject
3437
IStorage
3538
ITab
3639
ITaskbar
37-
llabs
3840
LCID
3941
llabs
4042
localtime
@@ -64,6 +66,7 @@ semver
6466
serializer
6567
shobjidl
6668
SIZENS
69+
smoothstep
6770
GETDESKWALLPAPER
6871
snprintf
6972
spsc
@@ -83,6 +86,7 @@ UPDATEINIFILE
8386
userenv
8487
wcsstr
8588
wcstoui
89+
wpc
8690
wsregex
8791
XDocument
8892
XElement

.github/actions/spell-check/dictionary/names.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,20 @@ ekg
1212
ethanschoonover
1313
Firefox
1414
Gatta
15+
glsl
1516
Grie
1617
Griese
1718
Hernan
1819
Howett
1920
Illhardt
21+
iquilezles
2022
jantari
2123
jerrysh
2224
Kaiyu
2325
kimwalisch
2426
KMehrain
27+
KODELIFE
28+
Kodelife
2529
Kourosh
2630
kowalczyk
2731
leonmsft
@@ -30,6 +34,7 @@ lukesampson
3034
Manandhar
3135
mbadolato
3236
Mehrain
37+
menger
3338
mgravell
3439
michaelniksa
3540
michkap
@@ -43,6 +48,7 @@ nvaccess
4348
nvda
4449
oising
4550
oldnewthing
51+
opengl
4652
osgwiki
4753
paulcam
4854
pauldotknopf
@@ -51,6 +57,7 @@ Pham
5157
Rincewind
5258
rprichard
5359
Schoonover
60+
shadertoy
5461
Somuah
5562
sonph
5663
sonpham
@@ -60,8 +67,8 @@ Wirt
6067
Wojciech
6168
zadjii
6269
Zamor
63-
Zamora
6470
zamora
71+
Zamora
6572
Zoey
6673
zorio
6774
Zverovich

.github/actions/spell-check/expect/expect.txt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ ADDREF
2424
addressof
2525
ADDSTRING
2626
ADDTOOL
27-
AEnd
2827
aef
28+
AEnd
2929
AFew
3030
AFill
3131
AFX
@@ -628,6 +628,7 @@ doskey
628628
dotnet
629629
doubleclick
630630
downlevel
631+
DOWNSCALE
631632
dpg
632633
dpi
633634
DPIAPI
@@ -832,6 +833,7 @@ fuzzwrapper
832833
fwdecl
833834
fwe
834835
fwlink
836+
GAUSSIAN
835837
gb
836838
gci
837839
gcx
@@ -909,6 +911,7 @@ Goldmine
909911
gonce
910912
Google
911913
goutput
914+
GPUs
912915
Gravell's
913916
grayscale
914917
GREENSCROLL
@@ -1109,6 +1112,7 @@ INTERCEPTCOPYPASTE
11091112
INTERNALNAME
11101113
interop
11111114
interoperability
1115+
intersectors
11121116
inthread
11131117
intptr
11141118
intsafe
@@ -1207,6 +1211,7 @@ KJ
12071211
KLF
12081212
KLMNOPQRST
12091213
KLMNOPQRSTQQQQQ
1214+
Kode
12101215
KU
12111216
KVM
12121217
KX
@@ -1591,6 +1596,7 @@ OACR
15911596
oauth
15921597
objbase
15931598
ocf
1599+
ocolor
15941600
odl
15951601
oem
15961602
oemcp
@@ -1789,6 +1795,7 @@ pragma
17891795
prc
17901796
prealigned
17911797
prebuilt
1798+
precendence
17921799
precomp
17931800
prect
17941801
prefast
@@ -1834,6 +1841,7 @@ pshn
18341841
PSHNOTIFY
18351842
PSHORT
18361843
pshpack
1844+
psin
18371845
PSINGLE
18381846
psl
18391847
psldl
@@ -1882,10 +1890,12 @@ QWER
18821890
qzmp
18831891
RAII
18841892
RALT
1893+
rasterbar
18851894
rasterfont
18861895
rasterization
18871896
rawinput
18881897
RAWPATH
1898+
raytracers
18891899
razzlerc
18901900
rbar
18911901
rbegin
@@ -1956,9 +1966,11 @@ RESETCONTENT
19561966
resheader
19571967
resizable
19581968
resmimetype
1969+
reso
19591970
restrictedcapabilities
19601971
resw
19611972
resx
1973+
RETROII
19621974
retval
19631975
rfa
19641976
rfc
@@ -2029,11 +2041,14 @@ SBCSDBCS
20292041
sbi
20302042
sbiex
20312043
sbold
2044+
sbri
2045+
scanbri
20322046
scancode
20332047
scanline
20342048
schemename
20352049
SCL
20362050
scm
2051+
scol
20372052
scprintf
20382053
SCRBUF
20392054
SCRBUFSIZE
@@ -2167,6 +2182,9 @@ SOURCESDIRECTORY
21672182
SPACEBAR
21682183
spammy
21692184
spand
2185+
spe
2186+
sph
2187+
spherefunctions
21702188
splashscreen
21712189
sprintf
21722190
sqlproj
@@ -2296,6 +2314,7 @@ tellp
22962314
telnet
22972315
telnetd
22982316
templated
2317+
teraflop
22992318
terminalcore
23002319
TERMINALSCROLLING
23012320
terminfo
@@ -2544,6 +2563,7 @@ vga
25442563
vgaoem
25452564
viewkind
25462565
viewports
2566+
Viginetting
25472567
Virt
25482568
VIRTTERM
25492569
Virtualizing
@@ -2760,6 +2780,7 @@ wwaproj
27602780
WWith
27612781
wx
27622782
wxh
2783+
wz
27632784
xa
27642785
xact
27652786
xamarin
@@ -2809,7 +2830,10 @@ xutr
28092830
xvalue
28102831
XVIRTUALSCREEN
28112832
XWalk
2833+
XWV
28122834
xy
2835+
xyw
2836+
Xzn
28132837
yact
28142838
YAML
28152839
YCast
@@ -2825,6 +2849,7 @@ YVIRTUALSCREEN
28252849
Yw
28262850
YWalk
28272851
yx
2852+
yzx
28282853
Zc
28292854
ZCmd
28302855
ZCtrl

doc/cascadia/profiles.schema.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"toggleFocusMode",
104104
"toggleFullscreen",
105105
"togglePaneZoom",
106-
"toggleRetroEffect",
106+
"toggleShaderEffects",
107107
"wt",
108108
"unbound"
109109
],
@@ -936,6 +936,10 @@
936936
"description": "When set to true, enable retro terminal effects. This is an experimental feature, and its continued existence is not guaranteed.",
937937
"type": "boolean"
938938
},
939+
"experimental.pixelShaderPath": {
940+
"description": "Use to set a path to a pixel shader to use with the Terminal. Overrides `experimental.retroTerminalEffect`. This is an experimental feature, and its continued existence is not guaranteed.",
941+
"type": "string"
942+
},
939943
"fontFace": {
940944
"default": "Cascadia Mono",
941945
"description": "Name of the font face used in the profile.",

samples/PixelShaders/Broken.hlsl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Broken, can be used for explorative testing of pixel shader error handling
2+
Texture2D shaderTexture;
3+
SamplerState samplerState;
4+
5+
cbuffer PixelShaderSettings {
6+
float Time;
7+
float Scale;
8+
float2 Resolution;
9+
float4 Background;
10+
};
11+
12+
float4 main(float4 pos : SV_POSITION, float2 tex : TEXCOORD) : SV_TARGET
13+
{
14+
// OOPS; vec4 is not a hlsl but a glsl datatype!
15+
vec4 color = shaderTexture.Sample(samplerState, tex);
16+
17+
return color;
18+
}

samples/PixelShaders/Error.hlsl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Shader used to indicate something went wrong during shader loading
2+
Texture2D shaderTexture;
3+
SamplerState samplerState;
4+
5+
cbuffer PixelShaderSettings {
6+
float Time;
7+
float Scale;
8+
float2 Resolution;
9+
float4 Background;
10+
};
11+
12+
float4 main(float4 pos : SV_POSITION, float2 tex : TEXCOORD) : SV_TARGET
13+
{
14+
float4 color = shaderTexture.Sample(samplerState, tex);
15+
float bars = 0.5+0.5*sin(tex.y*100);
16+
color.x += pow(bars, 20.0);
17+
return color;
18+
}

samples/PixelShaders/Grayscale.hlsl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// A minimal pixel shader that inverts the colors
2+
3+
// The terminal graphics as a texture
4+
Texture2D shaderTexture;
5+
SamplerState samplerState;
6+
7+
// Terminal settings such as the resolution of the texture
8+
cbuffer PixelShaderSettings {
9+
// Time since pixel shader was enabled
10+
float Time;
11+
// UI Scale
12+
float Scale;
13+
// Resolution of the shaderTexture
14+
float2 Resolution;
15+
// Background color as rgba
16+
float4 Background;
17+
};
18+
19+
// A pixel shader is a program that given a texture coordinate (tex) produces a color
20+
// Just ignore the pos parameter
21+
float4 main(float4 pos : SV_POSITION, float2 tex : TEXCOORD) : SV_TARGET
22+
{
23+
// Read the color value at the current texture coordinate (tex)
24+
// float4 is tuple of 4 floats, rgba
25+
float4 color = shaderTexture.Sample(samplerState, tex);
26+
float avg = (color.x + color.y + color.z) / 3.0;
27+
// Inverts the rgb values (xyz) but don't touch the alpha (w)
28+
color.xyz = avg;
29+
30+
// Return the final color
31+
return color;
32+
}

samples/PixelShaders/Invert.hlsl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// A minimal pixel shader that inverts the colors
2+
3+
// The terminal graphics as a texture
4+
Texture2D shaderTexture;
5+
SamplerState samplerState;
6+
7+
// Terminal settings such as the resolution of the texture
8+
cbuffer PixelShaderSettings {
9+
// Time since pixel shader was enabled
10+
float Time;
11+
// UI Scale
12+
float Scale;
13+
// Resolution of the shaderTexture
14+
float2 Resolution;
15+
// Background color as rgba
16+
float4 Background;
17+
};
18+
19+
// A pixel shader is a program that given a texture coordinate (tex) produces a color
20+
// Just ignore the pos parameter
21+
float4 main(float4 pos : SV_POSITION, float2 tex : TEXCOORD) : SV_TARGET
22+
{
23+
// Read the color value at the current texture coordinate (tex)
24+
// float4 is tuple of 4 floats, rgba
25+
float4 color = shaderTexture.Sample(samplerState, tex);
26+
27+
// Inverts the rgb values (xyz) but don't touch the alpha (w)
28+
color.xyz = 1.0 - color.xyz;
29+
30+
// Return the final color
31+
return color;
32+
}

0 commit comments

Comments
 (0)