what is the hell of uv's tiling and offset

i reference the website :http://blog.csdn.net/kfqcome/article/details/19343323

the picture i use is :
这里写图片描述

now we give the shader which use the texture to decorate the plane.

Shader "Course/SimpleSurface"
{
    Properties
    {
        _MainTex("Main Texture", 2D)="white"{} 
    }
    SubShader
    {
        CGPROGRAM
        #pragma surface surf Lambert 

        struct Input
        {
            float2 uv_MainTex;
        };

        sampler2D _MainTex;

        void surf(Input IN, inout SurfaceOutput o)
        {
            half4 tex = tex2D(_MainTex, IN.uv_MainTex);
            o.Albedo += tex.rgb;
        }
        ENDCG
    }
}

we then drag the pic to the unity project. the default wrap mode of the picture is repeat.
这里写图片描述

we choose the type of clamp. what does the clamp means? i will introduce in this blog later.

now then, create a plane, and a material, assign the mater to the materal. then use drag the materal to the plane. we will see.
这里写图片描述

we can see the default setting of tiling and offset for the pic in the inspector panel.
这里写图片描述

tiling’s value is x=1 and y=1
offset’s value is x=0 and y=0

we can use a drawing to explain the problem.
这里写图片描述

it clearly shows that we use the red rectangle of of the picture to render the plane.
the effect in unity is that:
这里写图片描述

there will some bias, as i draw the picture not exactly by the scale 0.2 and 0.8 percent.

yeap, if you read the blog here, you will know that, the offset is like the let-bottom point and the tiling is the point of the right-top point of the rectangle.
so, do not confused by the tiling meaning. because the this world is the explanation of the end effect, but not means the geometry meanings. we just take it as the left-bottom point and top-right point of the pic. then we cut this rectangle to render our object, here, our object is a plane.

next, i will explain the question in the begining of the blog. we set the picture wrap mode to clamp. what is the effect wrap mode effect. if you set the tiling value to (1,1), we will not seet the effect. but if we set the tiling value to be (1.1,1), what the effect is :
这里写图片描述

这里写图片描述

we just see the the horse x scale to more narrow.
now, let me color the right edge of the picture.

这里写图片描述

i render it in window’s drawing app. and set the tiling value to (2,1). the effect is :
这里写图片描述

now, you will clearly understand the clamp means. when i set the tiling to (2,1). the right 2 overceed the max uv coordinate 1. how to sample a color when the uv coordiante overceed the 1. clamp mode will the edge color of 1 to render the obejct. this is why render the right edge of the picture to red. because u can see the clear effect.

so now, you can proudly to teach others who are puzzled with this question. what’s uv, and what tiling and offset , and wrap mode clamp means.
uv, is like x,y
tiling is like width and height.
you can also kown that the offset is bottom left point and tiling is right top point.

over over !

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值