Sign in to follow this  
Jon_Snow

Lines with Orthographic Vertex shader

Recommended Posts

So I am writing a 2D game for fun and I am drawing circles in the 'background' using line strips, I had it working perfectly fine using transformed vertices, but I figured since I wasn't using the video card for anything much I'd go ahead and offload the circle calculations to a vertex shader, but now of course, I don't see anything. I am using an othographic projection matrix (1024x768), and both the world and view matrices are the identity. The line color is different than the clear color, and I've gone through other things trying to figure out what was wrong, but maybe I just need a different perspective on it. Here is the shader code:
uniform float4x4 mProjMat; //the projection matrix
uniform float2 vCenter; //the center of the current circle
uniform int nNumPoints; //the number of points in the current circle

struct VSInput{
	float3 vPos : POSITION;
	float fRadius : PSIZE;
	float4 nColor : COLOR;
};

struct VSOutput{
	float4 vPos : POSITION;
	float4 color : COLOR;
};

VSOutput VertShader(VSInput input){
	VSOutput output;
	
	int nNumPoint=int(input.nColor.b*256); //get the point index from the blue value
		
	float fDeg=(float)(nNumPoint)/float((nNumPoints-1));
	input.vPos.x=vCenter.x+(cos(6.2831f*fDeg)*input.fRadius);
	input.vPos.y=vCenter.y+(sin(6.2831f*fDeg)*input.fRadius);
	output.color.b=input.nColor.a;
	output.color.r=input.nColor.r;
	output.color.g=input.nColor.g;
	output.color.a=(float)nNumPoints+1-nNumPoints;
	output.vPos=mul(input.vPos,mProjMat);
	output.vPos=float4(input.vPos.xy,(float)nNumPoints+0.5f-nNumPoints,(float)nNumPoints-nNumPoints);
	
	return output;
};
The number of points I'm using for testing is 64, the circle's center is set at 512,384 (resolution is 1024x768). I've stepped through it, and it seems to be getting correct output values for both the position and the color, I set the z value to 0.5 and the w value to 1. I also have this if statement:
if(!bool(nNumPoints-nNumPoint-1))
{
	nNumPoint=0;
}
I'm trying to get the last point to get set to the same position as the first point, but it resolves to true and sets nNumpoint to 0 no matter what, even when I make a bool that is equal to false it STILL resolves to true, I just don't get it. Any help would be much appreciated.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this