-
-
Notifications
You must be signed in to change notification settings - Fork 962
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
feat: added outline support for TextBlock #2582
Conversation
added the possibility to add outline to you text block OutlineColor to change the color and OutlineThickness to change Thickness
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.
Thanks for the contribution ! This should be good for rasterized fonts, SDF could be a lot faster by changing the font shader instead, where the outline is just another sample of the sdf texture with a higher cutoff.
var borderColor = textBlock.RenderOpacity * textBlock.OutlineColor; | ||
|
||
|
||
Vector2[] offsets = |
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.
This array could be stackalloc'ated instead or replace the loop below with a loop going fromx -1 -> +1
and an inner one y -1 -> +1
.
Improves perfs and reduce GC hit.
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.
Thanks for the suggestion I will try to work on that tomorrow
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.
so i changed the code to
- use nested loops instead of a Vector2 array
- the code a lot cleaner and easier to read
- Old: Pre-calculated array of positions
- New: Calculated on-the-fly using nested loops
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.
it's true that changing the font shader would be more accurate and i guess faster my current knowledge base still didn't reach that level but i am improving i might work on it on future but this feature could be as a placeholder until i or someone else implement a better solution i am learning more about ui rendering and i might practice sometimes or even contribute to stride ui since it does need some features
- No array allocation (Vector2[]) - reduces garbage collection pressure - More efficient memory usage - uses stack instead of heap
Are you refering to SignedDistanceFieldFont.sdsl? Because it seems to already support outlines. |
i found an issue i will try to find a fix for it but any suggestion is good the issue is that the outline thickness should not exced
if it exceed that number it get's broken like in this video 2024-12-26.12-00-01.mp4 |
a possible fix that i found is having a max outline thickness variable that limit the outline thickness to the |
This is expected behavior when doing anything with a kernel pattern like so. The explanation you found is unrelated to the problem at hand; the limitations of an sdf outline would show as a filled up quad behind the character being outlined, while yours shows up as a gap between each kernel copies as the offset grows larger. One way to fix your issue is to increase the size of your kernel based on the width, cost would increase exponentially though, best keep it like so for rasterized fonts and push users towards using an sdf one instead. @bj-rn yes, although the shader used for the font passes in a constant for the border variables, so one would need to create a new one reading from some other vertex attribute to set the border color and width |
so i just need to leave it like that how can i push users to use sdf font should it be added to documentation or inside the editor also what about the idea of limiting the outline thickness to text size / 10 and is this code i wrote worthy to be merged if not i am not complaining i am just learning also thanks for the review and the suggestions sorry for asking a lot of question |
Oh, yeah, no, that's on me ! |
hmm i think what could be possible is to merge this so that people can try it have more opinion and yes i am still learning more things so it's better to wait and i will open an issue like you said for the sdf font linking the outline is usable now i have used it in my current project so i will try to learn more about ui rendering and shaders and see how can i improve it more so i opened an issue for this problem here #2584 so that i can work on it in future or someone can help |
Thanks ! |
no problem, this is my biggest contribution i learned a lot and i love how good and easy to work with stride rendering api since the engine is made using c# it's easier for me to work with than something made in c++ so thanks for keeping this engine alive i will gain more knowledge and maybe focus and work more on improving ui rendering and features in stride i just need time to learn thanks |
PR Details
Summary
Added support for text outlines in
TextBlock
with two new properties:OutlineColor
: (Color) Specifies the color of the outline.OutlineThickness
: (float) Determines the thickness of the outline.When
OutlineThickness
is set to0
orOutlineColor
isnull
, the text will render normally without any outline.Related Issue
Fixes #2581
Changes
OutlineColor
andOutlineThickness
properties in theTextBlock
class.Types of Changes
Checklist
Additional Notes