前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >纹理拼接后的Wrap寻址

纹理拼接后的Wrap寻址

作者头像
逍遥剑客
发布2019-02-20 12:53:45
6440
发布2019-02-20 12:53:45
举报

拼接后的纹理:

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

WRAP = 5时的情况:

MinFilter = Linear时的情况:

shader实现:

代码语言:javascript
复制
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

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2008年11月03日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档