Shader system for rendering cards (TCG). A TCG card with 1 material slot, 1 quad, configurable text using SDF encoding to stay sharp.
Currently only used for cards for the Exploreurs Imaginaires community.
Github repository in case you found this documentation from an installed package.
Explorer/card.fbx mesh for cards. Its aspect ratio matches the design the shader expect, a normal quad will not work correctly.Material using the Lereldarion/Card/Explorer shader. Some properties will be filled by default (font).
Explorer/Lereldarion_Card_Explorer_Template material, which has some example text.The card UI design is done using a signed distance function (SDF) to generate a sharp UI (https://iquilezles.org/articles/distfunctions2d/). See the explorer card as an example.
Sharp text is done using the MSDF strategy. A TTF font can be converted to an MSDF texture grid of glyphs, that is then sampled and combined to form the final card SDF.
Text lines are encoded in an R32G32B32A32_SFloat 2D texture, one line per row, with 1 control pixel followed by glyph references (4 per pixel). A custom MaterialPropertyDrawer provides a convenient GUI to edit the text ; it reads and regenerates the encoding texture.
[LereldarionCardTextLines(_Font_MSDF_Atlas_Texture, _Font_MSDF_Atlas_Config, _Text_LineCount)] _Text_Encoding_Texture("Text lines", 2D) = "" {}
[HideInInspector] _Text_LineCount("Text line count", Integer) = 0 // Auto-generated text metadata
[NoScaleOffset] _Font_MSDF_Atlas_Texture("Font texture (MSDF)", 2D) = "" {} // Font choice
[HideInInspector] _Font_MSDF_Atlas_Config("Font config", Vector) = (0, 0, 0, 0) // Auto-generated font metadata
Text editor features :
path/to/material.text_encoding_property_name.asset to ensure that it is unique per material.See the explorer card as an example of use, and the material drawer code for technical details.
The text line system requires an MSDF font in uniform grid mode. The explorer card uses Orbitron, and was generated using this command :
./msdf-atlas-gen.exe -font Orbitron-Regular.ttf -charset charset.txt -imageout orbitron.png -json orbitron.metrics.json -potr -uniformgrid
You can generate your own font and use it with the system
msdf-atlas-gen.-potr)msdf-atlas-gen defaults for other options work well in my experience : texture size selection, and texture SDF range (default = 2px)font_texture.metrics.json file is required by the MaterialPropertyDrawer to be able to understand the font texture. It must have the same path as the texture with extension replaced by .metrics.json : path/to/orbitron.png → path/to/orbitron.metrics.json.The text system supports fonts with kerning.
However msdf-atlas-gen only supports older kerning data format (https://github.com/Chlumsky/msdf-atlas-gen/issues/4).
If your font kerning is not working, the solution is to open the font with fontforge, export it with legacy kern data, and run msdf-atlas-gen on it.
Check if the generated metrics.json contains a non empty kernings JSON field.
v1 with explorer card released.
Maybe TODO
Make an instanced version of the shader for deck/collection of cards ?
lereldarion.card-system
https://github.com/lereldarion/card-system
1.0.0
2022.3 or later
No dependencies
No dependencies
No legacy packages