欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

what is the hell of uv's tiling and offset

程序员文章站 2022-03-11 21:06:05
...

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

the picture i use is :
what is the hell of uv's tiling and offset

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.
what is the hell of uv's tiling and offset

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.
what is the hell of uv's tiling and offset

we can see the default setting of tiling and offset for the pic in the inspector panel.
what is the hell of uv's tiling and offset

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.
what is the hell of uv's tiling and offset

it clearly shows that we use the red rectangle of of the picture to render the plane.
the effect in unity is that:
what is the hell of uv's tiling and offset

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 :
what is the hell of uv's tiling and offset

what is the hell of uv's tiling and offset

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

what is the hell of uv's tiling and offset

i render it in window’s drawing app. and set the tiling value to (2,1). the effect is :
what is the hell of uv's tiling and offset

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 !