纹理拼接后的Wrap寻址

拼接后的纹理:

纹理拼接后的Wrap寻址_第1张图片

正常的草地(不进行WRAP寻址):

纹理拼接后的Wrap寻址_第2张图片

WRAP = 5时的情况:

纹理拼接后的Wrap寻址_第3张图片

MinFilter = Linear时的情况:

纹理拼接后的Wrap寻址_第4张图片

shader实现:

sampler2D atlasTexture; float4 texRect; //(left, top, width, height) of uv float2 invSize; //(1/width, 1/height) float4 uvRange; //(left, top, right, bottom) of uv float4 ps_main( float2 tex : TEXCOORD0 ) : COLOR { // convert original uv to atlas uv's unit tex *= texRect.zw; float2 uv = tex - texRect.xy; // bring coordinates into normalized local texture coord [0..1] uv *= invSize; // if texture repeats then coords are > 1, use frc to bring // these coords back into [0, 1) interval. uv = frac(uv); // transform coords back to texture atlas coords uv = uv * texRect.zw + texRect.xy; // clamp to inside texture (to avoid bi-linear filter pulling in foreign texels) uv = clamp(uv, uvRange.xy, uvRange.zw); // use the original coords for mip-map calculation return tex2Dgrad(atlasTexture, uv, ddx(tex), ddy(tex)); } 

Reference:

ShaderX3 : Improved Batching via Texture Atlases

你可能感兴趣的:(纹理拼接后的Wrap寻址)