纹理拼接后的Wrap寻址

本文介绍了一种利用纹理图集进行纹理拼接的方法,并通过Shader实现纹理的高效使用。文中详细展示了如何通过转换坐标、规范化纹理坐标以及避免越界等步骤来优化纹理的加载与显示过程。

拼接后的纹理:

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

WRAP = 5时的情况:

MinFilter= Linear时的情况:

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值