Sign in to follow this  
andrew1b

Aligning texels to pixels on Cg programs (probably SOLVED)

Recommended Posts

I'm using the NVIDIA's Cg language and Direct3D 9 to draw 2D sprites with fragment shaders but I'm having some trouble trying to align the sprite pixels to the texels. I'm using an orthogonal matrix to transform the vertices and I'm also subtracting 0.5 to the vertices positions in order to achieve a correct pixel to texel mapping. It's working fine on my Radeon X series but when I run my applications on a NVIDIA card (Geforce 7300) the sprites (specially the bigger ones) look all messed up. It was all working fine when I was using the fixed funcion pipeline and the RHW vertex format. it looks something like this:
myViewMatrix = GetOrthoMatrix(1024, 768, 0.0f, 5.0f); // screen size, znear and zfar


In the shader code:
/*
the input vertex is: float3 position : POSITION
the sprite geometry looks like this:
const SPRITE_VERTEX vertices[] =
{
	// x, y, x                     u, v
	{  VECTOR3(0.0f, 1.0f, 0.0f), VECTOR2(0, 1) },
	{  VECTOR3(0.0f, 0.0f, 0.0f), VECTOR2(0, 0) },
	{  VECTOR3(1.0f, 0.0f, 0.0f), VECTOR2(1, 0) },
	{  VECTOR3(1.0f, 1.0f, 0.0f), VECTOR2(1, 1) },
};
*/
// scales the vertex according to the bitmap size
float4 newPos = newPos * float4(size,1,1);

// position the sprite according
newPos += float4(entityPos,0,0);

// inverts the y coordinate to make like in a 2D application
newPos *= float4(1,-1,1,1);

// retorns the transformed vertex
return mul(viewMatrix, newPos);


In most of the computers in wich I tested the code, it looks fine, axcept on NVIDIA's. Does anyone have any clue on what's going on? [Edited by - andrew1b on January 19, 2009 9:52:38 AM]

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