mirror of
https://github.com/microsoft/terminal.git
synced 2025-12-19 18:11:39 -05:00
Added experimental.pixelShaderImagePath (#14073)
I realize I might be one of the few developers that care about custom shader support in terminal but I thought it's worth proposing it and see what you think. This is to support custom shaders with custom textures. I was thinking of exposing the background image to the shader but that felt complicated after looking into it. I have tested exploratively. I think the texture loader is possible to unit test so that is a possible improvement. The error reporting (as with other custom pixel shader code) is not very good. That is also an area that I could improve upon. I do think the risk of adding this is rather low as the new code is only executed when experimental.pixelShaderImagePath is set. ### Details Only added to the Atlas engine. Instead I load the texture using WIC into a shader resource view. When binding shader resources I test for presence of custom texture and bind it to register t1. The image loading code was found in [the D3D Texture documentation]. It's a mouthful but seems rather robust. Tested setting: "experimental.pixelShaderImagePath" 1. Tested not specifying it. 2. Tested setting it. 3. Tested changing it (the changes are picked up) 4. Tested invalid path 5. Tested a custom shader that made use of the custom texture. [the D3D Texture documentation]: https://learn.microsoft.com/en-us/windows/win32/direct3d11/overviews-direct3d-11-resources-textures-how-to Co-authored-by: Mike Griese <migrie@microsoft.com> Co-authored-by: Leonard Hecker <lhecker@microsoft.com>
This commit is contained in:
23
samples/PixelShaders/BackgroundImage.hlsl
Normal file
23
samples/PixelShaders/BackgroundImage.hlsl
Normal file
@@ -0,0 +1,23 @@
|
||||
// Demo shader to show passing in an image using
|
||||
// experimental.pixelShaderImagePath. This shader simply displays the Terminal
|
||||
// contents on top of the given image.
|
||||
//
|
||||
// The image loaded by the terminal will be placed into the `image` texture.
|
||||
|
||||
SamplerState samplerState;
|
||||
Texture2D shaderTexture : register(t0);
|
||||
Texture2D image : register(t1);
|
||||
|
||||
cbuffer PixelShaderSettings {
|
||||
float Time;
|
||||
float Scale;
|
||||
float2 Resolution;
|
||||
float4 Background;
|
||||
};
|
||||
|
||||
float4 main(float4 pos : SV_POSITION, float2 tex : TEXCOORD) : SV_TARGET
|
||||
{
|
||||
float4 terminalColor = shaderTexture.Sample(samplerState, tex);
|
||||
float4 imageColor = image.Sample(samplerState, tex);
|
||||
return lerp(imageColor, terminalColor, terminalColor.a);
|
||||
}
|
||||
Reference in New Issue
Block a user