[background=rgb(254, 254, 254)]What I'm trying to do is use the [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(255, 235, 144)]texture[/background][/font][color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)] [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(255, 235, 144)]atlas[/background][/font][color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)] to combine multiple terrain textures into one big [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(255, 235, 144)]texture[/background][/font][color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)].[/background][/font]
[color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)]As you can see in the screenshot, the seams are clearly visible. and it gets worse when viewed from smaller angles. There are a few things I have tried.[/background][/font]
[color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)]Attempt 1:[/background][/font]
[color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)]In order to locate the [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(255, 235, 144)]problem[/background][/font][color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)], I changed to a debug [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(255, 235, 144)]texture[/background][/font][color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)] with no tiles and no [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(255, 235, 144)]texture[/background][/font][color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)] [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(255, 235, 144)]atlas[/background][/font][color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)]. Here's what I did.[/background][/font]
[color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)]when the uv calculation function was [/background][/font]
[color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)]uv = worldPos.xz;[/background][/font]
[color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)]tex2D(_DiffuseTex_0, uv);[/background][/font]
[color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)]There is no seam.[/background][/font]
[color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)]After I changed the uv calculation function to[/background][/font]
[color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)]uv = frac(worldPos.xz);[/background][/font]
[color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)]tex2D(_DiffuseTex_0, uv);[/background][/font]
[color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)]the seams would show up. (one might suspect why I would make this change because I used frac() in the full version of my uv calculation. My thinking was that because the [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(255, 235, 144)]texture[/background][/font][color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)] UV expects values ranging from [0, 1] (both 0, 1 inclusive). But frac() only outputs to [0, 1) (0 inclusive, 1 exclusive). Another observation is that even though frac() only outputs to [0, 1), when the input uv has no fraction component, the result should be 0. And 0 should tell the sampler to sample the first row/column in the sub-texture. but the screenshot shows otherwise. The simplified version of my uv calculation is 'uv = baseUV + frac(uv); '[/background][/font]
[color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)]After searching the forum, it seems other people experienced this [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(255, 235, 144)]problem[/background][/font][color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)] and categorized it as texel bleeding in the [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(255, 235, 144)]texture[/background][/font][color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)] [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(255, 235, 144)]atlas[/background][/font][color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)]' mipmaps. But after a few experiments, I still can not conclude it is a [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(255, 235, 144)]problem [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)]of mipmap. Here what I did.[/background][/font]
[color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)]Attempt 2:[/background][/font]
[color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)]I used 'Texture2D.PackTextures' in Unity to combine all the small terrain textures. According to the API documentation, it will merge their mipmaps as well. So I did. It seemed it did merge the textures and all of their mipmaps, but the outcome is exactly the same as before. [/background][/font]
[color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)]Attempt 3:[/background][/font]
[color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)]One thing did work out was disabling the mipmap generation and the seams would go away.[/background][/font]
[color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)]So Attempt 1 tells me it might have something to do with the UV mapping; yet Attempt 2 is hinting that it has nothing to do with mipmap; and Attempt 3 tells me it does relate to the [/background][/font][color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(255, 235, 144)]problem[/background][/font][color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)] of mipmap.[/background][/font]
[color=#111111][font=Helvetica, Arial, sans-serif]
[background=rgb(254, 254, 254)]Partial Shader Code:[/background][/font]
[indent=1]
/*
the texture '_DiffuseTex_0' is the final merged texture that has the size 2048 x 2048.
It contains 16 sub-textures with each being 512 x 512. There are 4 sub-textures in each row and a total of 4 rows.
baseUV is the uv coordinate calculated based on the type of terrain type.
e.g. (0,0) being the 1st terrain type,
(0,0.25) being the 2nd terrain type,
(0.75, 0.75) being the 16th terrain type.worldPos.xz is fed to the uv parameter.
*/
float4 GetDiffuseTex(float2 baseUV, float2 uv)
{
float correction = 1.0f/512.0f;
float indent = 0.0f;
uv /= _Repetition; // to scale the texture.
uv = baseUV + (correction * indent + frac(uv) * (1 - indent *2* correction) ) *_TileSize;
// Another test was using indentation to make it only sample from the inner portion of the sub-texture,
// and it didn't help neither.
//uv = (baseUV + frac(uv) *_TileSize);
//uv = frac(uv);
return tex2D(_DiffuseTex_0, uv);
}
/*
the texture '_DiffuseTex_0' is the final merged texture that has the size 2048 x 2048.
It contains 16 sub-textures with each being 512 x 512. There are 4 sub-textures in each row and a total of 4 rows.
baseUV is the uv coordinate calculated based on the type of terrain type.
e.g. (0,0) being the 1st terrain type,
(0,0.25) being the 2nd terrain type,
(0.75, 0.75) being the 16th terrain type.worldPos.xz is fed to the uv parameter.
*/
float4 GetDiffuseTex(float2 baseUV, float2 uv)
{
float correction = 1.0f/512.0f;
float indent = 0.0f;
uv /= _Repetition; // to scale the texture.
uv = baseUV + (correction * indent + frac(uv) * (1 - indent *2* correction) ) *_TileSize;
// Another test was using indentation to make it only sample from the inner portion of the sub-texture,
// and it didn't help neither.
//uv = (baseUV + frac(uv) *_TileSize);
//uv = frac(uv);
return tex2D(_DiffuseTex_0, uv);
}
[color=#111111][font=Helvetica, Arial, sans-serif]