[resource] Text display
- kingeric1992
- Topic Author
Less
More
8 years 6 months ago - 8 years 6 months ago #1
by kingeric1992
[resource] Text display was created by kingeric1992
functions to draw text and float,
recommend to save as .h to utilize the functions.
Also recommend to render to smaller text box and blend to full screen later.
text texture is in 14x7 grid, 512x512 rgb8, default path is ReShade/PersonalFiles/RFX_Text.png
F1 to toggle demo.
the number is frame time, negative values also works.
recommend to save as .h to utilize the functions.
Also recommend to render to smaller text box and blend to full screen later.
text texture is in 14x7 grid, 512x512 rgb8, default path is ReShade/PersonalFiles/RFX_Text.png
F1 to toggle demo.
the number is frame time, negative values also works.
Warning: Spoiler!
//Text display
//Character indexing
#define Chr_Space float2( 0, 0) // (space)
#define Chr_Exclam float2( 1, 0) // !
#define Chr_Quote float2( 2, 0) // "
#define Chr_Pound float2( 3, 0) // #
#define Chr_Dollar float2( 4, 0) // $
#define Chr_Percent float2( 5, 0) // %
#define Chr_And float2( 6, 0) // &
#define Chr_sQuote float2( 7, 0) // '
#define Chr_rBrac_O float2( 8, 0) // (
#define Chr_rBrac_C float2( 9, 0) // )
#define Chr_Asterisk float2(10, 0) // *
#define Chr_Plus float2(11, 0) // +
#define Chr_Comma float2(12, 0) // ,
#define Chr_Minus float2(13, 0) // -
#define Chr_Dot float2( 0, 1) // .
#define Chr_Slash float2( 1, 1) // /
#define Chr_0 float2( 2, 1) // 0
#define Chr_1 float2( 3, 1) // 1
#define Chr_2 float2( 4, 1) // 2
#define Chr_3 float2( 5, 1) // 3
#define Chr_4 float2( 6, 1) // 4
#define Chr_5 float2( 7, 1) // 5
#define Chr_6 float2( 8, 1) // 6
#define Chr_7 float2( 9, 1) // 7
#define Chr_8 float2(10, 1) // 8
#define Chr_9 float2(11, 1) // 9
#define Chr_Colon float2(12, 1) // :
#define Chr_sColon float2(13, 1) // ;
#define Chr_Less float2( 0, 2) // <
#define Chr_Equals float2( 1, 2) // =
#define Chr_Greater float2( 2, 2) // >
#define Chr_Question float2( 3, 2) // ?
#define Chr_at float2( 4, 2) // @
#define Chr_A float2( 5, 2) // A
#define Chr_B float2( 6, 2) // B
#define Chr_C float2( 7, 2) // C
#define Chr_D float2( 8, 2) // D
#define Chr_E float2( 9, 2) // E
#define Chr_F float2(10, 2) // F
#define Chr_G float2(11, 2) // G
#define Chr_H float2(12, 2) // H
#define Chr_I float2(13, 2) // I
#define Chr_J float2( 0, 3) // J
#define Chr_K float2( 1, 3) // K
#define Chr_L float2( 2, 3) // L
#define Chr_M float2( 3, 3) // M
#define Chr_N float2( 4, 3) // N
#define Chr_O float2( 5, 3) // O
#define Chr_P float2( 6, 3) // P
#define Chr_Q float2( 7, 3) // Q
#define Chr_R float2( 8, 3) // R
#define Chr_S float2( 9, 3) // S
#define Chr_T float2(10, 3) // T
#define Chr_U float2(11, 3) // U
#define Chr_V float2(12, 3) // V
#define Chr_W float2(13, 3) // W
#define Chr_X float2( 0, 4) // X
#define Chr_Y float2( 1, 4) // Y
#define Chr_Z float2( 2, 4) // Z
#define Chr_sBrac_O float2( 3, 4) // [
#define Chr_Backslash float2( 4, 4) // \
#define Chr_sBrac_C float2( 5, 4) // ]
#define Chr_Caret float2( 6, 4) // ^
#define Chr_Underscore float2( 7, 4) // _
#define Chr_Punc float2( 8, 4) // `
#define Chr_a float2( 9, 4) // a
#define Chr_b float2(10, 4) // b
#define Chr_c float2(11, 4) // c
#define Chr_d float2(12, 4) // d
#define Chr_e float2(13, 4) // e
#define Chr_f float2( 0, 5) // f
#define Chr_g float2( 1, 5) // g
#define Chr_h float2( 2, 5) // h
#define Chr_i float2( 3, 5) // i
#define Chr_j float2( 4, 5) // j
#define Chr_k float2( 5, 5) // k
#define Chr_l float2( 6, 5) // l
#define Chr_m float2( 7, 5) // m
#define Chr_n float2( 8, 5) // n
#define Chr_o float2( 9, 5) // o
#define Chr_p float2(10, 5) // p
#define Chr_q float2(11, 5) // q
#define Chr_r float2(12, 5) // r
#define Chr_s float2(13, 5) // s
#define Chr_t float2( 0, 6) // t
#define Chr_u float2( 1, 6) // u
#define Chr_v float2( 2, 6) // v
#define Chr_w float2( 3, 6) // w
#define Chr_x float2( 4, 6) // x
#define Chr_y float2( 5, 6) // y
#define Chr_z float2( 6, 6) // z
#define Chr_cBrac_O float2( 7, 6) // {
#define Chr_vBar float2( 8, 6) // |
#define Chr_cBrac_C float2( 9, 6) // }
#define Chr_Tilde float2(10, 6) // ~
#define Chr_tridot float2(11, 6) // (...)
#define Chr_empty0 float2(12, 6) // (null)
#define Chr_empty1 float2(13, 6) // (null)
//Character indexing ends
texture RFX_Text < string source = "ReShade/PersonalFiles/RFX_Text.png"; > {Width = 512;Height = 512;Format = RGBA8;};
sampler RFX_TextColor { Texture = RFX_Text; };
#define Text_SIZE 10
#define Text_Ratio 5
#define Text_Hight BUFFER_HEIGHT
float Text( float2 pos, float size, float ratio, float2 tex, float2 r[Text_SIZE])
{
float text = 0;
float2 uv = (tex * Text_Hight - pos) / size;
uv.y = saturate(uv.y);
uv.x *= ratio * 0.5;
if(uv.x <= Text_SIZE && uv.x >= 0)
text = tex2D(RFX_TextColor, (frac(uv) + r[floor(uv.x)]) * float2( 0.5, 1) / 7).x;
return text;
}
float Text_Width( int count, float size, float ratio)
{
return size * count * 2 / ratio;
}
float Digit( float2 pos, float size, float ratio, float2 tex, int digit, float data)
{
float2 digits[13] = {Chr_0, Chr_1, Chr_2, Chr_3, Chr_4, Chr_5, Chr_6, Chr_7, Chr_8, Chr_9, Chr_Minus, Chr_Space, Chr_Dot};
float text = 0;
float2 uv = (tex * Text_Hight - pos) / size;
uv.y = saturate(uv.y);
uv.x *= ratio * 0.5;
float t = abs(data);
int radix = floor(log10(max(t, 0.00001)));
radix = (floor(t) == 0)? 0:radix;
float index = pow(10, floor(-uv.x) + step(1, uv.x)); //current digit
index = floor(frac(t * 0.1 / index) * 10);
index = lerp(lerp(10, 11, step(0, data)), index, step(-radix-1, uv.x));
index = (uv.x > 0 && uv.x < 1)? 12:index;
if(uv.x <= digit && uv.x >= -radix-2)
text = tex2D(RFX_TextColor, (frac(uv) + digits[index]) * float2( 0.5, 1) / 7).x;
return text;
}
float4 RFX_PS_TestDemo(in float4 position : SV_Position, in float2 texcoord : TEXCOORD0) : SV_Target0
{
float test = RFX_frametime;
float2 Text_0[Text_SIZE] = { Chr_D, Chr_e, Chr_m, Chr_o, Chr_T, Chr_e, Chr_x, Chr_t, Chr_Space, Chr_b}; //Test
float2 Text_1[Text_SIZE] = { Chr_y, Chr_Colon, Chr_K, Chr_i, Chr_n, Chr_g, Chr_E, Chr_r, Chr_i, Chr_c}; //Test
float4 res = Text(float2(0, 800) , 32, Text_Ratio, texcoord.xy, Text_0);
res += Text(float2(Text_Width(10, 32, Text_Ratio), 800), 32, Text_Ratio, texcoord.xy, Text_1);
res += Digit(float2(Text_Width(8, 32, Text_Ratio), 832), 32, Text_Ratio, texcoord.xy, 5, test);
return res;
}
technique Text_Demo < enabled = false; toggle = VK_F1;>
{
pass
{
VertexShader = RFX_VS_PostProcess;
PixelShader = RFX_PS_TestDemo;
}
}
Last edit: 8 years 6 months ago by kingeric1992.
The following user(s) said Thank You: Ganossa
Please Log in or Create an account to join the conversation.