Jump to content
  • Advertisement
Sign in to follow this  
Jon_Snow

Lines with Orthographic Vertex shader

This topic is 4276 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!