Skip to content

Commit 7bb3db0

Browse files
committed
Change msdf.hlsl function to get precomputed pixel range instead
1 parent 3638d22 commit 7bb3db0

File tree

1 file changed

+11
-12
lines changed
  • include/nbl/builtin/hlsl/text_rendering

1 file changed

+11
-12
lines changed

include/nbl/builtin/hlsl/text_rendering/msdf.hlsl

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,18 @@ This can then be processed using smoothstep to provide anti-alising when renderi
2323
@params:
2424
- msdfSample: sampled SNORM value from the MSDF texture generated by msdfgen library.
2525
26-
- msdfPixelRange: specifies the width of the range around the shape between the minimum and maximum representable signed distance in shape units or distance field pixels, respectivelly.
27-
for example if msdfPixelRange is 4, then the range of distance values are [-2, +2], and it can be computed by snormValue * MSDFPixelRange/2.0
28-
so an snorm value of 1.0 means a distance of 2 pixels outside the shape (in msdf texture space)
29-
This value is set when rendering the MSDF with MSDFgen.
30-
31-
- screenPxRangeValue: the value used to convert the distance values in the msdf texture/atlas to distance in screen space.
32-
In other words it's DistanceInScreenSpace/DistanceInMSDFTextureSpace, the larger the glyph (or more zoomed in) the larger this value is.
33-
In 2D Text Rendering it is computed by `GlyphScreenSpaceSize/GlyphTextureSpaceSize`
34-
where GlyphTextureSpaceSize is the size of the glyph inside the msdf texture/atlas
26+
- pixelRange = msdfPixelRange * screenPxRangeValue, It is the value to convert snorm distance to screen space distance
27+
- msdfPixelRange: specifies the width of the range around the shape between the minimum and maximum representable signed distance in shape units or distance field pixels, respectivelly.
28+
for example if msdfPixelRange is 4, then the range of distance values are [-2, +2], and it can be computed by snormValue * MSDFPixelRange/2.0
29+
so an snorm value of 1.0 means a distance of 2 pixels outside the shape (in msdf texture space)
30+
This value is set when rendering the MSDF with MSDFgen.
31+
- screenPxRangeValue: the value used to convert the distance values in the msdf texture/atlas to distance in screen space.
32+
In other words it's DistanceInScreenSpace/DistanceInMSDFTextureSpace, the larger the glyph (or more zoomed in) the larger this value is.
33+
In 2D Text Rendering it is computed by `GlyphScreenSpaceSize/GlyphTextureSpaceSize`
34+
where GlyphTextureSpaceSize is the size of the glyph inside the msdf texture/atlas
3535
*/
36-
float msdfDistance(float3 msdfSample, float msdfPixelRange, float screenPxRangeValue) {
37-
float texelDist = median(msdfSample.r, msdfSample.g, msdfSample.b) * msdfPixelRange / 2.0f;
38-
return texelDist * screenPxRangeValue;
36+
float msdfDistance(float3 msdfSample, float pixelRange) {
37+
return median(msdfSample.r, msdfSample.g, msdfSample.b) * pixelRange / 2.0f;
3938
}
4039

4140
}

0 commit comments

Comments
 (0)