Fix shader time input (#8994)

Correctly sets the time input on the pixelShaderSettings struct, which was previously hard-coded to `0.0f`. 

## PR Checklist
* [x] Closes #8935
* [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA
* [x] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #8935

## Detailed Description of the Pull Request / Additional comments
I added a private field to `DxEngine` to store the timestamp for when a custom shader is first loaded. The field is initialized in `_SetupTerminalEffects()`, and the calculated time value (seconds since the timestamp) passed to the actual shader is set in `_ComputePixelShaderSettings()`. 

There remains an issue with with jerky animation due to the renderer not repainting when the window contents are not updated (see discussion in the original issue).

This is basically my first time writing C++; constructive review is enthusiastically welcomed 🙂

## Validation Steps Performed
I manually tested using a variety of simple shaders that rely on time input for animation.
This commit is contained in:
Lachlan Picking 2021-02-03 03:12:04 +10:00 committed by GitHub
parent 9d71fa817d
commit 9fb4fb2741
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View file

@ -411,6 +411,8 @@ HRESULT DxEngine::_SetupTerminalEffects()
pixelShaderSettingsBufferDesc.ByteWidth = sizeof(_pixelShaderSettings);
pixelShaderSettingsBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
_shaderStartTime = std::chrono::steady_clock::now();
_ComputePixelShaderSettings();
D3D11_SUBRESOURCE_DATA pixelShaderSettingsInitData{};
@ -454,9 +456,8 @@ void DxEngine::_ComputePixelShaderSettings() noexcept
{
try
{
// Set the time
// TODO:GH#7013 Grab timestamp
_pixelShaderSettings.Time = 0.0f;
// Set the time (seconds since the shader was loaded)
_pixelShaderSettings.Time = std::chrono::duration_cast<std::chrono::duration<float>>(std::chrono::steady_clock::now() - _shaderStartTime).count();
// Set the UI Scale
_pixelShaderSettings.Scale = _scale;

View file

@ -246,6 +246,8 @@ namespace Microsoft::Console::Render
std::wstring _pixelShaderPath;
bool _pixelShaderLoaded{ false };
std::chrono::steady_clock::time_point _shaderStartTime;
// DX resources needed for terminal effects
::Microsoft::WRL::ComPtr<ID3D11RenderTargetView> _renderTargetView;
::Microsoft::WRL::ComPtr<ID3D11VertexShader> _vertexShader;