m Yosh moved page Rendering MSDFs to Importing and using MSDFs: more accurate title since I plan to expand the scope of this article |
more examples |
||
Line 1: | Line 1: | ||
<languages /> | <languages /> | ||
<translate> | <translate> | ||
Line 8: | Line 6: | ||
</translate> | </translate> | ||
== <translate><!--T:3--> Creating MSDFs</translate> == | |||
== <translate><!--T:3--> | |||
<translate> | <translate> | ||
<!--T:4--> | <!--T:4--> | ||
MSDFs can be created with [https://github.com/Chlumsky/msdfgen the reference implementation of the format]. This is a command line program. | MSDFs can be created with [https://github.com/Chlumsky/msdfgen the reference implementation of the format]. This is a command line program to convert vector graphic paths (most notably, SVGs) into MSDFs. | ||
</translate> | </translate> | ||
Line 34: | Line 27: | ||
<translate> | <translate> | ||
<!--T:7--> | <!--T:7--> | ||
If you find yourself needing a higher quality MSDF (for more complicated shapes), change the <code>dimensions</code> to 256, 512, whatever you need. If you find that 64 or even smaller works just as well for your shape, by all means, try to optimize! | If you find yourself needing a higher quality MSDF (for more complicated shapes), change the <code>dimensions</code> to 256, 512, whatever you need. If you find that 64 or even smaller works just as well for your shape, by all means, try to optimize! You really don't need a lot of resolution for most symbols, and 128x128 is generally good enough. | ||
</translate> | </translate> | ||
== <translate><!--T:8--> | == <translate><!--T:8--> Importing MSDFs</translate> == | ||
<translate> | <translate> | ||
<!--T:9--> | <!--T:9--> | ||
For best results | An MSDF is just like any other texture, so importing is done [[Image import|like any other image]]. For best results when rendering the MSDF, it is recommended to: | ||
</translate> | </translate> | ||
Line 47: | Line 40: | ||
* <translate><!--T:11--> Set <code>FilterMode</code> to <code>Anisotropic</code></translate> | * <translate><!--T:11--> Set <code>FilterMode</code> to <code>Anisotropic</code></translate> | ||
* <translate><!--T:12--> Set either <code>Uncompressed</code> or <code>DirectLoad</code> to true.</translate> | * <translate><!--T:12--> Set either <code>Uncompressed</code> or <code>DirectLoad</code> to true.</translate> | ||
== <translate>Rendering MSDFs</translate> | |||
<translate> | |||
<!--T:2--> | |||
To render MSDFs in Resonite, use the [[Component:TextUnlitMaterial|TextUnlitMaterial]] or [[Component:UI_TextUnlitMaterial|UI_TextUnlitMaterial]] materials. The MSDF can be placed in the <code>FontAtlas</code> field of the material. <code>TintColor</code> is used to color the actual object the MSDF represents, while <code>BackgroundColor</code> can be used to color the background of the MSDF, so long as <code>AutoBackgroundColor</code> is unchecked. <code>OutlineColor</code> can be used to give an outline color to the object. <code>FaceDilate</code> dilates the boundary of the MSDF, <code>OutlineThickness</code> controls the thickness of the outline, and <code>FaceSoftness</code> controls how soft the object looks. | |||
</translate> | |||
== <translate>Examples</translate> == | |||
[[File:MSDF rendering example.webp|thumb|left|<translate>An example of simply rendering an MSDF on a [[Component:QuadMesh|quad]]. Look at how crisp those edges are for only a 128x128 image!</translate>]] | |||
=== <translate>Simple rendering</translate> === | |||
<translate> | |||
As with any other material, the two materials that support MSDF rendering can be used in a [[Component:MeshRenderer|MeshRenderer]]. This can be used to create simple symbols or renders of the MSDF. | |||
</translate> | |||
[[File:MSDF rounded corners example.webm|thumb|<translate>A video showing rounded corners on UIX panels. The offscreen component is a [[Component:SpriteProvider|SpriteProvider]] with a null texture. The MSDF used is [[:File:MSDF circle for corners.webp]]</translate>]] | |||
=== <translate>UIX effects</translate> === | |||
<translate> | |||
By using one of the aforementioned materials in an [[Component:Image|Image]] along with a null-texture [[Component:SpriteProvider|SpriteProvider]], MSDFs can be used in [[UIX]]. For example, using MSDFs in conjunction with [[9-slice scaling]] can provide little effects on borders when messing with various values depending on the MSDF. | |||
</translate> | |||
[[Category:Tutorial]] | [[Category:Tutorial]] |
Revision as of 18:45, 27 April 2025
Multi-channel signed distance fields are how Resonite conventionally renders text. They are essentially a big lookup table of how far away a sampled point must be to be a part of some 2d object. When combined with normal image interpolation, this can result in vector-like graphics without the need for something like SVG support nor a high-resolution texture.
Creating MSDFs
MSDFs can be created with the reference implementation of the format. This is a command line program to convert vector graphic paths (most notably, SVGs) into MSDFs.
For most purposes, the following command should generate a good MSDF from an SVG for rendering:
msdfgen -svg input.svg -dimensions 128 128 -autoframe
The SVG must contain only one path that defines the object. The program will warn you if there is more than one path in the SVG. You can use a program like Inkscape to combine multiple paths into one.
If you find yourself needing a higher quality MSDF (for more complicated shapes), change the dimensions
to 256, 512, whatever you need. If you find that 64 or even smaller works just as well for your shape, by all means, try to optimize! You really don't need a lot of resolution for most symbols, and 128x128 is generally good enough.
Importing MSDFs
An MSDF is just like any other texture, so importing is done like any other image. For best results when rendering the MSDF, it is recommended to:
- Set
PreferredProfile
toLinear
- Set
FilterMode
toAnisotropic
- Set either
Uncompressed
orDirectLoad
to true.
== Rendering MSDFs
To render MSDFs in Resonite, use the TextUnlitMaterial or UI_TextUnlitMaterial materials. The MSDF can be placed in the FontAtlas
field of the material. TintColor
is used to color the actual object the MSDF represents, while BackgroundColor
can be used to color the background of the MSDF, so long as AutoBackgroundColor
is unchecked. OutlineColor
can be used to give an outline color to the object. FaceDilate
dilates the boundary of the MSDF, OutlineThickness
controls the thickness of the outline, and FaceSoftness
controls how soft the object looks.
Examples

Simple rendering
As with any other material, the two materials that support MSDF rendering can be used in a MeshRenderer. This can be used to create simple symbols or renders of the MSDF.
UIX effects
By using one of the aforementioned materials in an Image along with a null-texture SpriteProvider, MSDFs can be used in UIX. For example, using MSDFs in conjunction with 9-slice scaling can provide little effects on borders when messing with various values depending on the MSDF.