text helper
- kingeric1992
- Topic Author
Less
More
6 years 9 months ago - 6 years 9 months ago #1
by kingeric1992
text helper was created by kingeric1992
a header file for drawing text
demo usage:
Result:
[hr]
github link
demo usage:
Warning: Spoiler!
uniform int textSize < ui_type = "drag"; ui_min = 5; ui_max = 100; > = 0;
#include "drawtext.fxh"
float4 main_fragment( float4 position : POSITION,
float2 txcoord : TEXCOORD) : COLOR {
float res = 0.0;
int line0[9] = { __D, __e, __m, __o, __Space, __T, __e, __x, __t }; //Demo Text
int line1[15] = { __b, __y, __Space, __k, __i, __n, __g, __e, __r, __i, __c, __1, __9, __9, __2 }; //by kingeric1992
int line2[6] = { __S, __i, __z, __e, __Colon, __Space }; // Size: %d.
DrawText_String(float2(100.0 , 100.0), 32, 1, txcoord, line0, 9, res);
DrawText_String(float2(100.0 , 134.0), textSize, 1, txcoord, line1, 15, res);
DrawText_String(DrawText_Shift(float2(100.0 , 134.0), int2(0, 1), textSize, 1), 18, 1, txcoord, line2, 6, res);
DrawText_Digit(DrawText_Shift(DrawText_Shift(float2(100.0 , 134.0), int2(0, 1), textSize, 1), int2(8, 0), 18, 1),
18, 1, txcoord, 0, textSize, res);
return res;
}
Result:
[hr]
github link
Last edit: 6 years 9 months ago by kingeric1992.
The following user(s) said Thank You: WLHM15
Please Log in or Create an account to join the conversation.
- BlueSkyKnight
Less
More
6 years 9 months ago - 6 years 9 months ago #2
by BlueSkyKnight
Replied by BlueSkyKnight on topic text helper
Neat... Looks like I did it the hard/tedious way. since I didn't want to use any external texture.
github.com/BlueSkyDefender/Depth3D/blob/...t_Sharp.fx#L316-L452
Your solution is better and easier. Since it allows for much more freedom.
github.com/BlueSkyDefender/Depth3D/blob/...t_Sharp.fx#L316-L452
Your solution is better and easier. Since it allows for much more freedom.
Last edit: 6 years 9 months ago by BlueSkyKnight.
Please Log in or Create an account to join the conversation.
- kingeric1992
- Topic Author
Less
More
6 years 9 months ago - 6 years 9 months ago #3
by kingeric1992
Replied by kingeric1992 on topic text helper
yeah, I don't think ppl would ever use this, but it is kind of handy as a utility header.
another approach would be the 3x5 char like in the ascii sahder.and it is possible to add a AA func to upscale the text to x2 scale or x3 scale.
another approach would be the 3x5 char like in the ascii sahder.
//3x5 num/char text
int getTextBit( int id ) {
int cText[10] = {
31599, 9362, 29671, 29647, 23497,//0,1,2,3,4
31183, 31215, 31305, 31727, 31689 //5,6,7,8,9
//expand char here
};
return cText[max(id, 9)];
}
float text(float2 uv, int n){
uv = 1.0 - uv;
float bit = pow(2.0, floor(uv.x*3.0) + 3.0*floor(uv.y*5.0));
uv = abs(uv - 0.5);
return step( 0.5, floor(float(getTextBit(n))/bit) % 2.0)*
step(uv.x, 0.499)*step(uv.y, 0.499);
}
Last edit: 6 years 9 months ago by kingeric1992.
Please Log in or Create an account to join the conversation.
- Marty McFly
Less
More
This might come in handy
btw: pow(2,x) -> exp2(x)
btw: pow(2,x) -> exp2(x)
Please Log in or Create an account to join the conversation.
- kingeric1992
- Topic Author
Less
More
should be fine as long as gl/hlsl compilers are doing constant folding.
pow(2, x) --> exp2( x * log2(2) ) ---> exp2(x)
though, not the same for the case of pow(x, 2)
where hlsl would resolve to x*x and gl might not.
pow(2, x) --> exp2( x * log2(2) ) ---> exp2(x)
though, not the same for the case of pow(x, 2)
where hlsl would resolve to x*x and gl might not.
Please Log in or Create an account to join the conversation.
- hunt1hunt
Less
More
@kingeric1992:text helper.fx(44, 1): error X3000: syntax error: unexpected 'identifier'
Please Log in or Create an account to join the conversation.
- hunt1hunt
Less
More
thanks,!Why i use the shader can't this show text?
Please Log in or Create an account to join the conversation.
- hunt1hunt
Less
More
6 years 20 hours ago - 5 years 11 months ago #8
by hunt1hunt
Replied by hunt1hunt on topic text helper
kingeric1992,hi,Why i use the shader can't this show text? i use reshade322,yes can show text now
Warning: Spoiler!
uniform int textSize < ui_type = "drag"; ui_min = 5; ui_max = 100; > = 0;
//3x5 num/char text
int getTextBit( int id ) {
int cText[10] = {
31599, 9362, 29671, 29647, 23497,//0,1,2,3,4
31183, 31215, 31305, 31727, 31689 //5,6,7,8,9
//expand char here
};
return cText[max(id, 9)];
}
float text(float2 uv, int n){
uv = 1.0 - uv;
float bit = pow(2.0, floor(uv.x*3.0) + 3.0*floor(uv.y*5.0));
uv = abs(uv - 0.5);
return step( 0.5, floor(float(getTextBit(n))/bit) % 2.0)*
step(uv.x, 0.499)*step(uv.y, 0.499);
}
#include "drawtext.fxh"
#include "ReShade.fxh"
float4 main_fragment( float4 position : POSITION,
float2 txcoord : TEXCOORD) : COLOR {
float res = 0.0;
int line0[9] = { __D, __e, __m, __o, __Space, __T, __e, __x, __t }; //Demo Text
int line1[15] = { __b, __y, __Space, __k, __i, __n, __g, __e, __r, __i, __c, __1, __9, __9, __2 }; //by kingeric1992
int line2[6] = { __S, __i, __z, __e, __Colon, __Space }; // Size: %d.
DrawText_String(float2(100.0 , 100.0), 32, 1, txcoord, line0, 9, res);
DrawText_String(float2(100.0 , 134.0), textSize, 1, txcoord, line1, 15, res);
DrawText_String(DrawText_Shift(float2(100.0 , 134.0), int2(0, 1), textSize, 1), 18, 1, txcoord, line2, 6, res);
DrawText_Digit(DrawText_Shift(DrawText_Shift(float2(100.0 , 134.0), int2(0, 1), textSize, 1), int2(8, 0), 18, 1),
18, 1, txcoord, 0, textSize, res);
return res;
}
technique Default //< enabled = true; >
{
pass
{
VertexShader = PostProcessVS;
PixelShader = main_fragment;
}
}
//3x5 num/char text
int getTextBit( int id ) {
int cText[10] = {
31599, 9362, 29671, 29647, 23497,//0,1,2,3,4
31183, 31215, 31305, 31727, 31689 //5,6,7,8,9
//expand char here
};
return cText[max(id, 9)];
}
float text(float2 uv, int n){
uv = 1.0 - uv;
float bit = pow(2.0, floor(uv.x*3.0) + 3.0*floor(uv.y*5.0));
uv = abs(uv - 0.5);
return step( 0.5, floor(float(getTextBit(n))/bit) % 2.0)*
step(uv.x, 0.499)*step(uv.y, 0.499);
}
#include "drawtext.fxh"
#include "ReShade.fxh"
float4 main_fragment( float4 position : POSITION,
float2 txcoord : TEXCOORD) : COLOR {
float res = 0.0;
int line0[9] = { __D, __e, __m, __o, __Space, __T, __e, __x, __t }; //Demo Text
int line1[15] = { __b, __y, __Space, __k, __i, __n, __g, __e, __r, __i, __c, __1, __9, __9, __2 }; //by kingeric1992
int line2[6] = { __S, __i, __z, __e, __Colon, __Space }; // Size: %d.
DrawText_String(float2(100.0 , 100.0), 32, 1, txcoord, line0, 9, res);
DrawText_String(float2(100.0 , 134.0), textSize, 1, txcoord, line1, 15, res);
DrawText_String(DrawText_Shift(float2(100.0 , 134.0), int2(0, 1), textSize, 1), 18, 1, txcoord, line2, 6, res);
DrawText_Digit(DrawText_Shift(DrawText_Shift(float2(100.0 , 134.0), int2(0, 1), textSize, 1), int2(8, 0), 18, 1),
18, 1, txcoord, 0, textSize, res);
return res;
}
technique Default //< enabled = true; >
{
pass
{
VertexShader = PostProcessVS;
PixelShader = main_fragment;
}
}
Last edit: 5 years 11 months ago by hunt1hunt.
Please Log in or Create an account to join the conversation.