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();
}
}
Thank you!

Bastian Born