Now I'm working on getting this to work with the latest ogre, and I've been debugging a lot, but have not found a solution yet.
It seems to be as if the mesh object itself, and mesh for 'letters' are working, they show up looking as it should, and gets updated when the
text is changed, like this:
Also the font used is loaded fine.
We set the vertex\fragment program through code when the moveable text is created:
Code: Select all
mpMaterial->getBestTechnique()->getPass(0)->setVertexProgram(vertexProgramName);
mpMaterial->getBestTechnique()->getPass(0)->setFragmentProgram(fragmentProgramName);
This is what I know the least about in the whole process, so I wanted to ask here, and maybe some one of you who knows more about it can
enlighten me if there is something wrong with it (that has to do with ogre 2.1).
TextBox.program :
Code: Select all
vertex_program TextBox_vs hlsl
{
target vs_4_0
source TextBox.hlsl
entry_point TextBox_vs
default_params
{
param_named_auto wvpMat worldviewproj_matrix
param_named_auto wMatInv inverse_world_matrix
param_named arrowTargetWS float4 0.0 0.0 0.0 0.0
}
}
fragment_program TextBox_ps hlsl
{
target ps_4_0
source TextBox.hlsl
entry_point TextBox_ps
default_params
{
param_named rowsAlphaOffset float 0.0
}
}
Code: Select all
float4 TextBox_vs
(
in float4 inPosOS : POSITION,
in float2 inUV : TEXCOORD0,
in float4 inColor : COLOR,
uniform float4x4 wvpMat,
uniform float4x4 wMatInv,
uniform float4 arrowTargetWS,
out float2 outUV : TEXCOORD0,
out float4 outPosOS : TEXCOORD1,
out float4 outColor : COLOR
)
: SV_Position
{
// If this is the arrow target (uv == 3.5) and we have a target (arrowTargetWS.w != 0.0), move this point to the target position.
if(inUV.x > 3.4 && inUV.x < 3.6 && arrowTargetWS.w != 0.0)
{
inPosOS = mul(wMatInv, arrowTargetWS); //float4(0.0, 5.0, 0.0, 1.0));
}
outPosOS = inPosOS;
outUV = inUV;
outColor = inColor;
float4 outPosSS = mul(wvpMat, inPosOS);
return outPosSS;
}
Texture2D fontMap : register(t0);
SamplerState fontSampler : register(s0);
float4 TextBox_ps
(
in float2 inUV : TEXCOORD0,
in float4 inPosOO : TEXCOORD1,
in float4 inColor : COLOR,
uniform float rowsAlphaOffset
)
: SV_TARGET
{
float4 outColor = float4(0, 0, 0, 1);
if(inUV.x >= 1.0 && inUV.y >= 1.0) // This is the background if UV is outside range [0, 1)
{
outColor = inColor;
// Rows with slightly different color
if(rowsAlphaOffset > 0.0)
{
if((int)((inPosOO.y + 1000.0) * 4.0) % 2 == 0)
{
outColor.a += rowsAlphaOffset;
}
else
{
outColor.a -= rowsAlphaOffset;
}
}
}
else // Else, it is font
{
outColor = fontMap.Sample(fontSampler, inUV) * inColor;
}
return outColor;
}
And when I use 'RenderDoc' to debug, I see that the fontmap is loaded in and referenced in the mesh's material.
It looks like this:
(This is why I suspect that there is something wrong in the shader code above causing the uv's not to align the way they should.)
In the debugger I see the uv's for each letter is set, so the mesh itself has them.