Sign in to follow this  
Flimflam

(solved) Simple texture blending shader in 2D troubles

Recommended Posts

Flimflam    665
************** Edit: Problem solved! I was an idiot and forgot to define a sampler_state inside the pixel shader specifying linear filtering, instead of just using the register. ************** Hi everyone. I decided to take my texture blending pixel shader I initially designed for 3D terrain and set it up to run as the background layer of a 2D rpg-style game I decided to make with a friend. The problem I'm facing existed on the 3D version, but it really wasn't as noticeable (due to perspective and mipmapping, etc) To illustrate my issue: As you can see, the borders around the textures are very pixelated. Now, I know why this is happening--the alpha map I'm using to blend everything together is 256x256, however the thing is being rendered stretched across the screen (1024x1024). The problem is I'm not quite sure how to correct this. The obvious solution is to increase the alpha map size to something bigger, and after it's big enough, the issue would more or less go away -- but I'm trying to keep my texture resources somewhat low, and doing that really isn't plausible. Does anyone have any ideas on how to solve this problem? For the record, I'm using C# With XNA 2.0 (rolling my own system without the content pipeline and specifically targeting only win32, not using the Game interface etc) My pixel shader is as follows:
sampler texture0 : register(s0);
sampler texture1 : register(s1);
sampler texture2 : register(s2);
sampler texture3 : register(s3);

float texture_scale = 6;

float4 main(float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
{
   
   // Sample the color map, to find out what we're blending
   float4 colorvalue = tex2D(texture3, texCoord);
   float4 coloradd = {0, 0, 0, 0};

   // Compute texture scales
   float2 texScale = texCoord * texture_scale;

   // Blend everything together
   colorvalue /= colorvalue.x + colorvalue.y + colorvalue.z;
   coloradd += tex2D(texture0, texScale) * colorvalue.x;
   coloradd += tex2D(texture1, texScale) * colorvalue.y;
   coloradd += tex2D(texture2, texScale) * colorvalue.z;
   
   // Return the color multiplied by the overall tint
   return coloradd * color;
}

technique Terrain3
{
    pass Pass1
    {
        PixelShader = compile ps_2_0 main();
    }
}




[Edited by - Flimflam on February 19, 2008 2:12:25 AM]

Share this post


Link to post
Share on other sites
Gage64    1235
Quote:
As you can see, the borders around the textures are very pixelated


Actually the whole thing looks very pixelated. Are you using filtering?

Share this post


Link to post
Share on other sites
Flimflam    665
Quote:
Original post by Gage64
Quote:
As you can see, the borders around the textures are very pixelated


Actually the whole thing looks very pixelated. Are you using filtering?


For the most part, the pixelation in the grass is part of the style (I am using linear filtering on it, but the texture makes it appear otherwise). Once I have things overlayed on top of it, it will look ten times better. The main issue though is the huge block pixels you see around the corners of the texture.

Edit: I figured it out. I need to elaborate in the pixel shader:

texture alphamap;
sampler texture3 = sampler_state
{
texture = <alphamap>;
magfilter = LINEAR;
minfilter = LINEAR;
mipfilter = LINEAR;
};

And set the texture manually.

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