-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented support for user provided pixel shaders #7058
Conversation
_pixelShaderSettings.ScaledScanLinePeriod = _scale * 1.0f; | ||
if (_pixelShaderEffect && _d3dDeviceContext && _pixelShaderSettingsBuffer) | ||
{ | ||
try |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Semantics changed so that this function now also updates the resource. This is because this is needed to be updated in more than one place now.
oh man, you gotta share screenshots |
Some TODOs remains in the code and I know the mispelling bot will complain. |
@zadjii-msft pictures added. |
Looks great! |
So I just realized this needs the Command Palette updated too. The retro Terminal is configured there and would clearly break if it wasn't adjusted to go to this new setting instead (it could also possibly give a crash if someone attempted to enable it). It can be a follow-up PR but it should be added not long afterwards so when the next release is out for Preview, we don't encounter unforeseen issues. @zadjii-msft would likely address it as the Command Palette is his creation. |
If I implement support for the old experimental flag would the command palette still work? I am also unsure where the command palette is located so any pointers are welcome. |
I would have the old setting value match the new value for 'Retro'. So |
Okay so just a heads up - it might be a few days before anyone on the team has time to really take a good look at this PR. It's an awesome idea, and I'm excited to see what's possible with it. My top-of-the-head concern is that we'd need to keep the old IMO, if the shader doesn't work, I'd probably have the renderer default to just not doing anything with the shared at all, rather than showing an error pattern. I'm not the graphics expert on the team, so someone more qualified could overrule me. As far as the command palette is concerned - the only real concern I have is the "toggleRetroEffect" action. Currently, that setting simply toggles the retro effect on/off, but with this feature, there's now a more complex matrix of features. Maybe that'll need to be similarly changed to What happens when someone hits TBH, we only introduced |
New misspellings found, please review:
To accept these changes, run the following commands
✏️ Contributor please read thisBy default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.
If the listed items are:
See the 🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The :check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉
|
@zadjii-msft Yes, it is clear to me that the old experimental feature needs to be supported. I think it being an alias for "RETRO" is fine. When it comes to When it comes to broken shader code, if there's a good way to make the user aware (and possibly a shader dev) the shader load failed that should be used instead. However, I wouldn't like a pop-up myself and would in that case prefer the background to indicate the loading failed. As a shader dev I really like the quick iteration cycles from change to seeing it (less than 1 sec typically). When I try to tinker and get my shader working with windows terminal I would like that iteration cycle to be as quick as possible. Preferably even support hot-reload on file change. Having a pop-up that I have to click away each time would irritate me. No indication at all would possibly be confusing. Did I manage to activate the feature or did it fail? At least with a failing shader background the user knows that windows terminal tried to load the shader but something happened. |
New misspellings found, please review:
To accept these changes, run the following commands
✏️ Contributor please read thisBy default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.
If the listed items are:
See the 🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The :check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉
|
Maybe you should lock the aspect ratio to 4:3 in retro mode, for a truly retro experience (lol, jk😅😅) |
bool GetRetroTerminalEffect() const noexcept; | ||
void SetRetroTerminalEffect(bool enable) noexcept; | ||
|
||
std::optional<std::wstring> GetPixelShaderEffect() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: Can noexcept
be added here when this returns a value?
I am now more "worried" over HSV2RGB functions as no license have been specified for these functions. Since the author posted it in Stackoverflow he has consented by TOS that they are licensensed under CC BY-SA 3.0 (as his post was made in 2013, see: https://stackoverflow.com/help/licensing). CC BY-SA requires Attribution (check, I think) and ShareAlike (not sure if MIT is compatible in this regard). I am not sure how "excerpts" works, the argument was a little hand-wavy by Jeff Atwood IMHO. |
Hi. I now clarfied (I hope) the licensing of the external work RetroII depends on. I think the ray sphere intersection code is in the clear as it's the same license as Windows Terminal (ie MIT). See https://www.shadertoy.com/view/4d2XWV for evidence. The HSV to RGB conversion is CC BY-SA 3.0 which I think most likely isn't compatible with MIT (not a copyright lawyer so just a cautious guess). Your legal counsel might have some good advice on how to deal with it. Depending on the advice I could:
I prefer 1 as it would simplify for users to start using RetroII. The other work is done by me and I just need to clear with my employer that I can sign the CLA (I don't foresee any problems here). |
@DHowett Just FYI; I think the ray sphere intersection code is fine but now I am more uncertain about the HSV2RGB code taken from Stackoverflow. Have you had the chance to check with copyright experts on what your stance on code from Stackoverflow is? |
I remember reading somewhere about code on StackOverflow being public domain (maybe from places like https://meta.stackexchange.com/q/12527) . But I'm not sure if Creative Common/Public Domain is good for company governance of MSFT. Come to think about it, we may want to add some kind of instruction on README, for people who wants to contribute to realize that due to the fact this is a company project and the majority of the code was originally from Windows OS source repo and will be merged back to the OS repo, the license restriction is far more strict. CC @DHowett |
I am not a copyright lawyer with FOSS specialization but AFAIK Creative Commons 0 (https://creativecommons.org/share-your-work/public-domain/cc0/) is close to public domain in spirit (no rights reserved). Creative Commons 4.0 Share-Alike with Attribution Required (https://creativecommons.org/licenses/by-sa/4.0/) is not public domain as this comes with terms (share alike and attribution required) and freedoms (alot given the terms are fulfilled). I will try to contact the author of the HSV2RGB functions and see what license he is licensing them under. If I can't reach the author or I get a negative response I will change the code to not use them. |
I've tried to reach the author of of HSV2RGB but haven't been successful so I decided to remove the functions as it's unclear if the Stackoverflow license applies and is compatible with the MIT license of Terminal. However, when I move to master I run into this. Have anyone seen it?
Happens at:
And unfortunately the callstack didn't tell anything. I checked if there was changes to README for updated dependencies but didn't find any. Has there been changes in SDK/VS requirments that hasn't been documented yet? |
Sorry about that (and for the radio silence); there’s a commit on main that is causing a failure on startup. If you want to revert it, it’s the one that “updates MUX to 2.5”. |
4a6ae40
to
17b7e25
Compare
Removed the dependency on HSV2RGB due to uncertainities if Stack overflow code can be safely mixed with MIT licensed code. The ray-sphere intersection code is confirmed to be under the MIT license from discussion with the author directly as well as seen from the examples on shadertoy. IMO (not a copyright lawyer) as this is the same license as Windows Terminal I believe it should be ok to use the code in Windows Terminal. Rebasing was difficult due to significant changes to Due to problems with commit: "Update to a newer MUX prerelease; remove workaround for compact sizing" (#7447) |
New misspellings found, please review:
To accept these changes, run the following commands
✏️ Contributor please read thisBy default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.
If the listed items are:
See the 🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The :check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉
|
17b7e25
to
199c28b
Compare
Awesome things can be done with pixel shaders that can spice up the terminal such as retro looks, fractals, raytracers or star scroller backgrounds. This commit adds the capability for the user to create their own pixel shader effects. In addition a new retro effect has been added as built-in pixel shader: "experimental.pixelShaderEffect": "RETROII" The existing retro effect is possible to enable as well: "experimental.pixelShaderEffect": "RETRO" In order to for a user to create their own pixel shader effects specify a path rather than a built-in effect: "experimental.pixelShaderEffect" : "C:\\temp\\RetroIII.hlsl" Note: The escaping of paths is needed to construct a valid JSON string. Error handling is changed so that if the shader fails to load for any reason the exception is logged normally and it defaults to an error shader showing the user a pattern that indicates that a pixel shader effect was attempted but didn't work out. Example shaders are provided under: samples/PixelShaders/ A new command has been added: toggleTerminalEffects This command turns on and off configured terminal effects, if no terminal effects are configured this command does nothing. The existing command: toggleRetroEffect is changed to have the same semantices as the new command. This is a change in behaviour that was discussed with the maintainers. The RETROII pixel shader relies on a ray-sphere intersection function developed by Inigo Quilez and released with the MIT license. For an example of the ray-sphere function in action: https://www.shadertoy.com/view/4d2XWV
199c28b
to
f5c54f1
Compare
Read the CLA more closely . It seems to indicate that I should separate the MIT licensed code that is not my original work (ray sphere intersection) in a separate PR and submit that separately. That can be done. |
Is it required to extract the MIT licensed code into a separate commit to be eligible for a merge? |
@mrange While I'm waiting for word -- sorry, the process has been slower than I had hoped -- it might be best if we restructure this code into two pull requests, yes. If we can get one that adds custom shader infrastructure and pulls out the existing retro effect, and then one that adds any additional shaders that will need individual licensing review, that would be the quickest path forward. |
This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 7 days of this comment. |
Hi. Been swamped at work with work so haven't had much chance to react to the feedback yet. |
Hey, I know it's been a while since there's been any movement on this PR. I really love it, and I want to ship it in the Terminal. I can understand being busy, this year more than ever, and I didn't want to have this work lost. If it's okay with you @mrange, I've taken the liberty of taking this PR, merging the last few months of changes, and polishing it over in #8565. Hopefully we can use that to get this feature in finally (with credit where credit is due to you @mrange). Thanks for all this! |
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.
Co-authored-by: mrange <marten_range@hotmail.com> I loved the pixel shaders in microsoft#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 microsoft#7058: It does _not_ add any built-in shaders. - CHANGED FROM microsoft#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 microsoft#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 microsoft#7058: Originally, microsoft#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 microsoft#6191 References microsoft#7058 Closes microsoft#7013 Closes microsoft#3930 "Add setting to retro terminal shader to control blur radius, color" Closes microsoft#3929 "Add setting to retro terminal shader to enable drawing scanlines" - At this point, just roll your own version of the shader.
Summary of the Pull Request
Allows users to provide pixel shader effects or pick one from a few presets such as the "retroII" preset.
Preliminary blog post on how to enable pixel shaders (private GIST): https://gist.github.com/mrange/1fdcfb7293f0299ecf994928f84d30b9
This built upon the existing experimental retro effect feature which lacked tests which means no tests were changed but none have been added (yet).
Testing was done exploratively with the different terminal settings.
References
#7013
#6191
PR Checklist
(These are not completed yet, will do obviously if the PR seems interesting)
Detailed Description of the Pull Request / Additional comments
Awesome things can be done with pixel shaders that can spice up
the terminal such as retro looks, fractals, raytracers or star
scroller backgrounds.
This feature deprecates the old retro effect config option but
supports the retro effect through the new config option:
"experimental.pixelShaderEffect": "RETRO"
A new retro effect has been added as well:
"experimental.pixelShaderEffect": "RETROII"
It's also possible for users to implement their own pixel shader
and load them like so:
"experimental.pixelShaderEffect" : "C:\temp\RetroIII.hlsl"
Note: The escaping of paths is needed to construct a valid JSON string.
Error handling is changed so that if the shader fails to load for any
reason the exception is logged normally and it defaults to an error
shader showing the user a pattern that indicates that a pixel shader
effect was attempted but didn't work out.
Some simple example shaders are provided under: samples/PixelShaders/
Validation Steps Performed
Manual steps: