UV常用操作

1.UV旋转

          float2 rotate(float degree, float2 coord)
          {
                float theta = radians(degree);
                float2 offset = float2(_OffsetX, _OffsetY);
                
                float2x2 rotationMatrix = float2x2(cos(theta), -sin(theta),
                                                   sin(theta),  cos(theta));
                return mul(rotationMatrix, coord - offset) + offset;
            }
            
            float2 rotateWithOffset(float degree, float2 coord)
            {
                coord.x -= _OffsetX;
                coord.y -= _OffsetY;
                
                float t = radians(degree);
                float c = cos(t);
                float s = sin(t);
                float2 n;
                n.x = c * coord.x + -s * coord.y + _OffsetX;
                n.y = s * coord.x + c * coord.y + _OffsetY;
                return n;
            }

2.屏幕空间的贴图
i.pos来自屏幕裁剪空间
return tex2D(_MainTex, i.pos.xy / _ScreenParams.x);
或者这样
pos = UnityObjectToClipPos(v.vertex);
screenPos = ComputeScreenPos(o.pos);
tex2D(_ScreenTex, float2(screenPos.xy / screenPos.w))

你可能感兴趣的:(Shader,Unity3D)