Original Post
I've written a little shader to draw fonts with but it's got a huge problem, for some reason it decides to skip an entire chunk of code. Here is what I have-
uniform int sString[256]; //the string being rendered atm
uniform float4x4 mProj; //projection matrix
uniform float4x4 mWorld; //world matrix
uniform int nCurIndex; //the current index in the string
const float3 Colors[9]={{1,1,1}/*WHITE*/,{0,0,0}/*BLACK*/,{0.5f,0.5f,0.5f},/*GREY*/
{1,0,0}/*BRIGHT RED*/,{0,1,0}/*BRIGHT GREEN*/,{0,0,1}/*BRIGHT BLUE*/,
{0.5f,0,0/*DARK RED*/},{0,0.5f,0}/*DARK GREEN*/,{0,0,0.5f}/*DARK BLUE*/};
uniform int nCurColor; //the current color
uniform int nCurSetIndex; //the current vertex index in the set, incremented each vertex, once it reaches 5 it goes to 0 again, and the character to render is incremented
uniform float fFontSize; //the size in pixels of each character on the character sheet
struct VSInput{
float4 pos : POSITION;
float2 texcoord : TEXCOORD0;
};
struct VSOutput{
float4 pos : POSITION;
float2 texcoord : TEXCOORD0;
float4 color : COLOR;
};
VSOutput FontShader(VSInput input){
VSOutput output;
output.pos=mul(input.pos,mWorld);
output.pos=mul(output.pos,mProj);
output.texcoord.x=(int(sString[nCurIndex]-32)%10*fFontSize+(fFontSize*input.texcoord.x))/1280;
output.texcoord.y=(int(sString[nCurIndex]-32)/10*fFontSize+(fFontSize*input.texcoord.y))/1024;
output.color=float4(Colors[nCurColor],1);
nCurSetIndex=nCurSetIndex+1;
if(nCurSetIndex>5){
nCurSetIndex=0;
nCurIndex=nCurIndex+4;
if(sString[nCurIndex]==94){
nCurIndex=nCurIndex+4;
nCurColor=sString[nCurIndex]-48;
nCurIndex=nCurIndex+4;
}
}
return output;
}
technique FontEffect{
pass P0{
VertexShader=compile vs_2_0 FontShader();
}
} After it sets the output.color, it skips everything else until the return statement. Meaning that instead of drawing a nice string, it just displays the first letter everytime since it is not incrementing the string index counter. I'm not getting any errors on compilation, and I can step through the shader fine, other than it skipping all those lines of course. Another thing I noticed was that the nCurSetIndex variable tells me it's an expression that can't be evaluated, though every other global variable I have seems to, no clue why that is. I've come across this problem before where it would just skip lines of code, someone said it might be because DX removed the statement because it detected it didn't have any effect on the output, but I can't see how that could be in this case since there are several operations that will clearly change the values of some of the variables. I'm using VS 2003, the April 2006 SDK, the shader is compiled from the .fx file with the D3DXSHADER_SKIPOPTIMIZATION and D3DXSHADER_DEBUG flags, oh and I'm aware that the position isn't being multiplied by the view matrix, this is in a 2D app so my view matrix is just the identity. So yah, any help or suggestions you could give me would be greatly appreciated. :)