You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
125 lines
3.8 KiB
Plaintext
125 lines
3.8 KiB
Plaintext
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
|
|
|
|
/*=============================================================================
|
|
TinyFontCommon.usf: TinyFont shared functions and structures.
|
|
=============================================================================*/
|
|
|
|
#ifndef __TINY_FONT_COMMON__
|
|
#define __TINY_FONT_COMMON__
|
|
|
|
Texture2D MiniFontTexture;
|
|
|
|
// useful with PrintCharacter
|
|
#define _0_ 0
|
|
#define _1_ 1
|
|
#define _2_ 2
|
|
#define _3_ 3
|
|
#define _4_ 4
|
|
#define _5_ 5
|
|
#define _6_ 6
|
|
#define _7_ 7
|
|
#define _8_ 8
|
|
#define _9_ 9
|
|
#define _A_ 10
|
|
#define _B_ 11
|
|
#define _C_ 12
|
|
#define _D_ 13
|
|
#define _E_ 14
|
|
#define _F_ 15
|
|
#define _G_ 16
|
|
#define _H_ 17
|
|
#define _I_ 18
|
|
#define _J_ 19
|
|
#define _K_ 20
|
|
#define _L_ 21
|
|
#define _M_ 22
|
|
#define _N_ 23
|
|
#define _O_ 24
|
|
#define _P_ 25
|
|
#define _Q_ 26
|
|
#define _R_ 27
|
|
#define _S_ 28
|
|
#define _T_ 29
|
|
#define _U_ 30
|
|
#define _V_ 31
|
|
#define _W_ 32
|
|
#define _X_ 33
|
|
#define _Y_ 34
|
|
#define _Z_ 35
|
|
|
|
// 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);
|
|
|
|
#if ES2_PROFILE
|
|
// Integer modulo/remainder is not an allowed operation on ES 2
|
|
// todo: move function to central spot, here we assume unsigned
|
|
return Temp - (Temp / 10) * 10;
|
|
#else
|
|
return Temp % 10;
|
|
#endif
|
|
}
|
|
|
|
|
|
// 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));
|
|
}
|
|
|
|
// for printf debugging in the shader, has to be positive
|
|
// outputs a float number in the form: xxx.yyy
|
|
// @param LeftTop - in pixels
|
|
void PrintFloatNoFraction(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, 10000));
|
|
PrintCharacter(PixelPos, OutColor, FontColor, Cursor, ExtractDigitFromFloat(Number, 1000));
|
|
PrintCharacter(PixelPos, OutColor, FontColor, Cursor, ExtractDigitFromFloat(Number, 100));
|
|
PrintCharacter(PixelPos, OutColor, FontColor, Cursor, ExtractDigitFromFloat(Number, 10));
|
|
PrintCharacter(PixelPos, OutColor, FontColor, Cursor, ExtractDigitFromFloat(Number, 1));
|
|
}
|
|
|
|
#endif // __TINY_FONT_COMMON__
|