You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
62 lines
2.1 KiB
Plaintext
62 lines
2.1 KiB
Plaintext
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
|
|
|
|
/*=============================================================================
|
|
TinyFontCommon.usf: TinyFont shared functions and structures.
|
|
=============================================================================*/
|
|
|
|
#ifndef __TINY_FONT_COMMON__
|
|
#define __TINY_FONT_COMMON__
|
|
|
|
Texture2D MiniFontTexture;
|
|
|
|
|
|
// for printf debugging in the shader
|
|
// @param LeftTop - is advanced, in pixels
|
|
void PrintCharacter(int2 PixelPos, inout float3 OutColor, float3 FontColor, inout int2 LeftTop, int CharacterID)
|
|
{
|
|
uint2 Rel = (uint2)(PixelPos - LeftTop);
|
|
|
|
FLATTEN if (Rel.x < 8 && Rel.y < 8)
|
|
{
|
|
OutColor = lerp(OutColor, FontColor, MiniFontTexture.Load(int3(CharacterID * 8 + Rel.x, Rel.y, 0)).r);
|
|
}
|
|
|
|
LeftTop.x += 8;
|
|
}
|
|
|
|
// only for positive numbers
|
|
// @param DigitValue - e.g. 1 for frist digit before period, 10 for second, 0.1 for first digit behind period
|
|
uint ExtractDigitFromFloat(float Number, float DigitValue)
|
|
{
|
|
uint Temp = (uint)(Number / DigitValue);
|
|
|
|
return Temp % 10;
|
|
}
|
|
|
|
|
|
// for printf debugging in the shader, has to be positive
|
|
// outputs a float number in the form: xxx.yyy
|
|
// @param LeftTop - in pixels
|
|
void PrintFloat(int2 PixelPos, inout float3 OutColor, float3 FontColor, int2 LeftTop, float Number)
|
|
{
|
|
int2 Cursor = LeftTop;
|
|
|
|
float BorderDistance = ComputeDistanceToRect(PixelPos, LeftTop, int2(7, 1) * 8 - 1);
|
|
|
|
// black border around number
|
|
// OutColor = lerp(0, OutColor, saturate(BorderDistance - 2));
|
|
|
|
// before period
|
|
PrintCharacter(PixelPos, OutColor, FontColor, Cursor, ExtractDigitFromFloat(Number, 100));
|
|
PrintCharacter(PixelPos, OutColor, FontColor, Cursor, ExtractDigitFromFloat(Number, 10));
|
|
PrintCharacter(PixelPos, OutColor, FontColor, Cursor, ExtractDigitFromFloat(Number, 1));
|
|
// period
|
|
PrintCharacter(PixelPos, OutColor, FontColor, Cursor, 512 / 8 - 3);
|
|
// after period
|
|
PrintCharacter(PixelPos, OutColor, FontColor, Cursor, ExtractDigitFromFloat(Number, 0.1));
|
|
PrintCharacter(PixelPos, OutColor, FontColor, Cursor, ExtractDigitFromFloat(Number, 0.01));
|
|
PrintCharacter(PixelPos, OutColor, FontColor, Cursor, ExtractDigitFromFloat(Number, 0.001));
|
|
}
|
|
|
|
#endif // __TINY_FONT_COMMON__
|