HLSL-Texturesplatting-> Strange Lines

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Barratator
Posts: 30
Joined: Fri Jan 08, 2010 3:30 pm

HLSL-Texturesplatting-> Strange Lines

Post by Barratator »

Hello,
sorry for my bad english.
I tried to write an texturesplatting-shader in HLSL for 12 textures (+4 Alphatextures) on one texture-layer.

There is one big texture whitch is cutted into 4x4 quadrate.
In the first 4 textures (0/0, 1/0, 2/0, 3/0) you can find the alphatexture, which says, how strong you should see the "real" textures.

Here is an sample-texture: http://www.pic-upload.de/view-4354538/terrain.png.html (Only the first 3 textures are used.)

But there is some failure: At the seam between two tiled textures are big lines: http://www.pic-upload.de/view-4342565/sh1.png.html
The lines are pixel who mapped at the false position (you can see a red line from the alphatexture and a black from the non-texture-area).

Here is my shader:

Code: Select all

float4x4 matViewProjection : ViewProjection;

sampler tex0;

struct VS_INPUT
{
   float4 Position : POSITION0;
   float2 alphamap : TEXCOORD0;
   float2 tex : TEXCOORD1;
};

struct VS_OUTPUT
{
   float4 Position : POSITION0;
   float2 alphamap : TEXCOORD0;
   float2 tex : TEXCOORD1;
};

struct PS_OUTPUT
{
   float4 diffuse : COLOR0;
};


VS_OUTPUT vs_main( VS_INPUT Input )
{
   VS_OUTPUT Output;
   Output.Position = mul( Input.Position, matViewProjection );
   Output.alphamap = Input.alphamap;
   Output.tex = Input.tex;

   return( Output );
}

float4 getpixel(int2 id , float2 pos)
{
   float2 size  = float2(0.25 , 0.25);
   pos = pos % 1.0;
   return tex2D(tex0  , pos*size  +  id*size);
}



PS_OUTPUT ps_main(in VS_OUTPUT input)
{
   float texScale = 10.0;
   
   PS_OUTPUT output = (PS_OUTPUT)0;
   float4 a1 = getpixel(int2(0,0) , input.tex);
   float4 a2 = getpixel(int2(1,0) , input.tex);
   float4 a3 = getpixel(int2(2,0) , input.tex);
   float4 a4 = getpixel(int2(3,0) , input.tex);

   float2 tp = input.tex * texScale;
   
   float4 img1a = getpixel(int2(0,1) , tp) * a1.r;
   float4 img1b = getpixel(int2(1,1) , tp) * a2.r;
   float4 img1c = getpixel(int2(2,1) , tp) * a3.r;
   float4 img1d = getpixel(int2(3,1) , tp) * a4.r;
   
   float4 img2a = getpixel(int2(0,2) , tp) * a1.g;
   float4 img2b = getpixel(int2(1,2) , tp) * a2.g;
   float4 img2c = getpixel(int2(2,2) , tp) * a3.g;
   float4 img2d = getpixel(int2(3,2) , tp) * a4.g;
   
   float4 img3a = getpixel(int2(0,3) , tp) * a1.b;
   float4 img3b = getpixel(int2(1,3) , tp) * a2.b;
   float4 img3c = getpixel(int2(2,3) , tp) * a3.b;
   float4 img3d = getpixel(int2(3,3) , tp) * a4.b;
   
   float4 img1 = img1a + img1b + img1c + img1d;
   float4 img2 = img2a + img2b + img2c + img2d;
   float4 img3 = img3a + img3b + img3c + img3d;

   output.diffuse = img1 + img2 + img3;
   
   return output;
}

technique Default_DirectX_Effect
{
   pass Pass_0
   {
      VertexShader = compile vs_2_0 vs_main();
      PixelShader = compile ps_2_0 ps_main();
   }
}
Do you have some advices?

Thank you! :-)



Bastian Born
Last edited by Barratator on Sun Jan 24, 2010 11:10 am, edited 1 time in total.
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

maybe mipmapping error?

or, (i don't really know shaders, but) you arent using the 0,0 pixel, maybe that causing this?

this is what i used, and worked for me:

Code: Select all

float4x4 matViewProjection;
struct VS_INPUT 
{
   float4 Position : POSITION0;
   float2 TexCoord : TEXCOORD0;
   
};

struct VS_OUTPUT 
{
   float4 Position : POSITION0;
   float2 TexCoord : TEXCOORD0;
};

VS_OUTPUT vertexMain( VS_INPUT Input )
{
   VS_OUTPUT Output;

   Output.Position = mul( Input.Position, matViewProjection );
   Output.TexCoord = Input.TexCoord;
   return( Output );
   
}

sampler2D Alpha;
sampler2D Tex1;
sampler2D Tex2;
sampler2D Tex3;

struct PS_INPUT
{
   float2 TexCoord : TEXCOORD0;
};

float4 pixelMain(PS_INPUT Input) : COLOR0
{   
   float4 alpha = tex2D(Alpha, Input.TexCoord);
   float4 tex0 = tex2D(Tex1, Input.TexCoord);
   float4 tex1 = tex2D(Tex2, Input.TexCoord);
   float4 tex2 = tex2D(Tex3, Input.TexCoord);
   
   float inverse = 1.0f / (alpha.r + alpha.g + alpha.b);
   
   // Multiply with alpha texture
   tex0 *= alpha.r * inverse;
   tex1 *= alpha.g * inverse;
   tex2 *= alpha.b * inverse;

   float4 texColor = (tex0 + tex1 + tex2);
   return texColor;   
}
Image
Image
Barratator
Posts: 30
Joined: Fri Jan 08, 2010 3:30 pm

Post by Barratator »

Oh yes! Without mipmapping it looks better :-)
But the big lines are stil there... :(

What do you mean, that i don't use Pixel 0/0 ?



Thanks!

Bastian
Barratator
Posts: 30
Joined: Fri Jan 08, 2010 3:30 pm

Post by Barratator »

It works! The bilinear-filtering has been wrapped the texture :P

But now, I can't use the mipmapping and when I'm going to far away the rendering-process is to slow. Can I remake the effect on my own? Or can I use the real mipmapping without the strange lines? :P


Greetz,
Bastian


EDIT: I think it's the Moiré-Effect?
Post Reply