Jump to content
  • Advertisement
Sign in to follow this  

Aligning texels to pixels on Cg programs (probably SOLVED)

This topic is 3536 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

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
I solved this problem by using linear filtering instead of point (nearest) filtering. I'm not sure if that's the best way to do it but it worked.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!