您的位置:首页 > 其它

what is the hell of uv's tiling and offset

2018-02-02 16:30 531 查看
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 !
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  deep understanding of offset a
相关文章推荐