-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement user-specified pixel shaders, redux (#8565)
Co-authored-by: mrange <marten_range@hotmail.com> 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.
- Loading branch information
1 parent
e943785
commit b140299
Showing
36 changed files
with
843 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Broken, can be used for explorative testing of pixel shader error handling | ||
Texture2D shaderTexture; | ||
SamplerState samplerState; | ||
|
||
cbuffer PixelShaderSettings { | ||
float Time; | ||
float Scale; | ||
float2 Resolution; | ||
float4 Background; | ||
}; | ||
|
||
float4 main(float4 pos : SV_POSITION, float2 tex : TEXCOORD) : SV_TARGET | ||
{ | ||
// OOPS; vec4 is not a hlsl but a glsl datatype! | ||
vec4 color = shaderTexture.Sample(samplerState, tex); | ||
|
||
return color; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Shader used to indicate something went wrong during shader loading | ||
Texture2D shaderTexture; | ||
SamplerState samplerState; | ||
|
||
cbuffer PixelShaderSettings { | ||
float Time; | ||
float Scale; | ||
float2 Resolution; | ||
float4 Background; | ||
}; | ||
|
||
float4 main(float4 pos : SV_POSITION, float2 tex : TEXCOORD) : SV_TARGET | ||
{ | ||
float4 color = shaderTexture.Sample(samplerState, tex); | ||
float bars = 0.5+0.5*sin(tex.y*100); | ||
color.x += pow(bars, 20.0); | ||
return color; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// A minimal pixel shader that inverts the colors | ||
|
||
// The terminal graphics as a texture | ||
Texture2D shaderTexture; | ||
SamplerState samplerState; | ||
|
||
// Terminal settings such as the resolution of the texture | ||
cbuffer PixelShaderSettings { | ||
// Time since pixel shader was enabled | ||
float Time; | ||
// UI Scale | ||
float Scale; | ||
// Resolution of the shaderTexture | ||
float2 Resolution; | ||
// Background color as rgba | ||
float4 Background; | ||
}; | ||
|
||
// A pixel shader is a program that given a texture coordinate (tex) produces a color | ||
// Just ignore the pos parameter | ||
float4 main(float4 pos : SV_POSITION, float2 tex : TEXCOORD) : SV_TARGET | ||
{ | ||
// Read the color value at the current texture coordinate (tex) | ||
// float4 is tuple of 4 floats, rgba | ||
float4 color = shaderTexture.Sample(samplerState, tex); | ||
float avg = (color.x + color.y + color.z) / 3.0; | ||
// Inverts the rgb values (xyz) but don't touch the alpha (w) | ||
color.xyz = avg; | ||
|
||
// Return the final color | ||
return color; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// A minimal pixel shader that inverts the colors | ||
|
||
// The terminal graphics as a texture | ||
Texture2D shaderTexture; | ||
SamplerState samplerState; | ||
|
||
// Terminal settings such as the resolution of the texture | ||
cbuffer PixelShaderSettings { | ||
// Time since pixel shader was enabled | ||
float Time; | ||
// UI Scale | ||
float Scale; | ||
// Resolution of the shaderTexture | ||
float2 Resolution; | ||
// Background color as rgba | ||
float4 Background; | ||
}; | ||
|
||
// A pixel shader is a program that given a texture coordinate (tex) produces a color | ||
// Just ignore the pos parameter | ||
float4 main(float4 pos : SV_POSITION, float2 tex : TEXCOORD) : SV_TARGET | ||
{ | ||
// Read the color value at the current texture coordinate (tex) | ||
// float4 is tuple of 4 floats, rgba | ||
float4 color = shaderTexture.Sample(samplerState, tex); | ||
|
||
// Inverts the rgb values (xyz) but don't touch the alpha (w) | ||
color.xyz = 1.0 - color.xyz; | ||
|
||
// Return the final color | ||
return color; | ||
} |
Oops, something went wrong.