Sign in to follow this  

Shader trouble

This topic is 4490 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 just started shader programming in CG a little while ago and now I am stuck. Basically what I wanted is a shader that uses a placement texture that is used to look up which tile in the tile texture needs to go where (mmm might sound confusing). In this case I used a point sampled 8x8 texture for the placement texture. I have boiled my shader down to this: float4 PS_Test(vertexOutput IN): COLOR { //lookup new texture coordinates float2 newCoords = tex2D( placementSampler, IN.placementCoords ); // use coordinates to read color from the tile texture return tex2D( tileSet, newCoords ); } What I expect to see is a plane with 8 times 8 sharp squares with colors from the tile texture. I do see this but with the addition of a pixel wide line between tiles which makes the whole thing practically unusable. At first I thought it might be a wonky driver or video card but it doesn exactly the same on a radeon as it does on nvidia. Does anyone have any idea as to why it is doing this?

Share this post


Link to post
Share on other sites
What about the texture wrap/clamp mode?

I assume the 8x8 is repeated across the screen? If so, check your texture coordinates and be sure you are sampling texel centers ( which are different in d3d & ogl ).

Share this post


Link to post
Share on other sites
the 8x8 isn't repeated and it also doesn't make any difference wether I clamp it or not.

Below you can see the texture samplers I used and tried.

sampler tileSetSampler = sampler_state
{
texture = <tileSet>;
MIPFILTER = LINEAR; // I tried setting this to point but that doesn't change a thing
MINFILTER = LINEAR;
MAGFILTER = LINEAR;

/* I tried clamping but it still has the same problem
AddressU = CLAMP;
AddressV = CLAMP;
AddressW = CLAMP;
*/

};

sampler placementSampler = sampler_state
{
texture = <placement>;
MIPFILTER = POINT;
MINFILTER = POINT;
MAGFILTER = POINT;

/* I tried clamping but it still has the same problem
AddressU = CLAMP;
AddressV = CLAMP;
AddressW = CLAMP;
*/
};

Also worth noting is that I don't really want to clamp the placement texture because I would like it to tile on bigger surfaces.

[Edited by - _WickeD_ on August 31, 2005 10:29:34 AM]

Share this post


Link to post
Share on other sites
I suspect the problem is that at tile edges you're going to be interpolating between two tiles (and thus seeing an edge). You need to either put borders around your tiles in the tile texture, or if they are all square, you can clamp your texture read to be totally inside your tile (taking texel alignment into account of course).

Share this post


Link to post
Share on other sites
Are you using OGL or DX? If DX, then you may have to offset your sprite vertex screen space positions by (-0.5,-0.5). I am not entirely clear on the problem, but that may help out. If not, try posting a screen shot and we can probably help.

Share this post


Link to post
Share on other sites

This topic is 4490 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.

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