Shader trouble

Started by
4 comments, last by _WickeD_ 18 years, 7 months ago
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?
Advertisement
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 ).
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]
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).
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.
I found out it is a filtering issue, setting my tilesampler to MIPFILTER = NONE fixed the problem. Thanks you guys for the help.

This topic is closed to new replies.

Advertisement