-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Make sure the inverted cursor is always readable (#3647) #13748
Conversation
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.
I'm cool with this, thanks for doing it!
@msftbot make sure @lhecker signs off |
Hello @DHowett! Because you've given me some instructions on how to help merge this pull request, I'll be modifying my merge approach. Here's how I understand your requirements for merging this pull request:
If this doesn't seem right to you, you can tell me to cancel these instructions and use the auto-merge policy that has been configured for this repository. Try telling me "forget everything I just told you". |
Original PR comment:
|
src/renderer/atlas/shader_ps.hlsl
Outdated
color = float4(1 - color.rgb, 1); | ||
|
||
// Make sure the cursor is always readable (see gh-3647) | ||
color = float4((((uint3(color.rgb * 255) ^ 0x3f) & 0xff) / 255.0).rgb, 1); |
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.
I've been thinking about whether this can be expressed in floating point since GPUs prefer floating point over integer operations and because it would allow us to retain the full "color accuracy" up to the end of the shader. Here's what I came up with:
color = float4(1 - color.rgb, 1); | |
// Make sure the cursor is always readable (see gh-3647) | |
color = float4((((uint3(color.rgb * 255) ^ 0x3f) & 0xff) / 255.0).rgb, 1); | |
// Make sure the cursor is always readable (see gh-3647) | |
// If we imagine color to be in 0-255 instead of 0-1, | |
// this effectively XORs color with 63. | |
float3 ip; // integral part | |
float3 frac = modf(color.rgb * (255.0f / 64.0f), ip); | |
color = float4((3.0f - ip + frac) * (64.0f / 255.0f), 1); |
If you're curious, this is how it changes the assembly to be more compact:
@alabuzhev I've pushed a change which fixes the color inversion for AtlasEngine. Here's how it looks like: Let me know what you think, if you get a chance. I hope you didn't mind this! 🙂 |
Looks interesting. I played with it a bit here: Note that I amended both versions:
The results are very close, except for the corner cases at 64, 128 and 192, where the floats version flips just a bit later:
Of course I don't mind, that's the whole point of "Allow edits from maintainers" :) Thank you.
Supposedly it uses it literally and
So, LTGRAY_BRUSH ^ 0x0C = 0xC0 ^ 0x0C = 0xCC. |
The algorithm I built yesterday was a bit flawed and the one I pushed into your branch today should not be off by 1 anymore. 🙂 I'm not sure about it, but I think the As an aside, I'm a bit worried that this PR might pose a bit of a visual regression for conhost, due to the worse ClearType rendering in GdiEngine: I'm not 100% sure what to do about that yet. |
|
🎉 Handy links: |
Currently "Inverse Cursor" is actually simply bitwise inversed.
It works fine, except when it does not, namely in the middle of the spectrum:
Anything close enough to dark grey (index 8, RGB(128, 128, 128) in the
classic palette) will for obvious reasons become almost the same dark grey
again after the inversion.
The issue is addressed by additionally
XOR
ing the inverted color withRGB(63, 63, 63). This distorts the result enough to avoid collisions
in the middle. Ultimately this restores the behavior that was in
Windows Console since the Middle Ages (and still exists in ConhostV1.dll).
PR Checklist
Validation Steps Performed
color 80
to see black text on dark grey background.