Unity shader Programming (3) UV operation

Source: Internet
Author: User
Tags cos sin

Unity shader Programming (3) UV operation

1, shader





2, UV common operation

① Scaling

Shader "Custom/newshader" {Properties {_maintex ("Base (RGB)", 2D) = "White" {}_scalex ("ScaleX", float) =1//x direction _scaley (" ScaleY ", float) =1//y direction}subshader {Tags {" rendertype "=" Opaque "}lod 200cgprogram#pragma Surface Surf lambertsampler2d _ Maintex;float _scalex;float _scaley;struct Input {float2 uv_maintex;};  void Surf (Input in, InOut surfaceoutput o) {float2 UV = In.uv_maintex;uv = Uv*float2 (1.0/_scalex,1.0/_scaley);//Zoom HALF4 C = tex2d (_maintex, UV); O. Albedo = C.rgb;o. Alpha = C.A;} ENDCG} FallBack "Diffuse"}


② panning

Shader "Custom/newshader" {Properties {_maintex ("Base (RGB)", 2D) = "White" {}//_scalex ("ScaleX", float) =1//x direction//_ ScaleY ("ScaleY", float) =1//y direction _px ("px", float) = 0//pan}subshader {Tags {"rendertype" = "Opaque"}lod 200cgprogram#pragma Surface Surf lambertsampler2d _maintex;//float _scalex;//float _scaley;float _px;struct Input {float2 uv_maintex;}; void Surf (Input in, InOut surfaceoutput o) {float2 UV = In.uv_maintex;//uv = Uv*float2 (1.0/_scalex,1.0/_scaley);//Scaling Uvs = UV + FLOAT2 (_px,0);//pan Half4 C = tex2d (_maintex, UV); O. Albedo = C.rgb;o. Alpha = C.A;} ENDCG} FallBack "Diffuse"}


③ rotation

Shader "Custom/newshader" {Properties {_maintex ("Base (RGB)", 2D) = "White" {}//_scalex ("ScaleX", float) =1//x direction//_ ScaleY ("ScaleY", float) =1//y direction//_px ("px", float) = 0//pan _angle ("angle", float) = 0}subshader {Tags {"Rendertype" = " Opaque "}lod 200cgprogram#pragma surface surf lambertsampler2d _maintex;//float _scalex;//float _scaley;//float _px; Float _angle;struct Input {float2 uv_maintex;}; void Surf (Input in, InOut surfaceoutput o) {float2 UV = In.uv_maintex;//uv = Uv*float2 (1.0/_scalex,1.0/_scaley);//Zoom//UV = UV + FLOAT2 (_px,0);//Pan UV =FLOAT2 ((cos (_angle) *uv.x-sin (_angle) *uv.y), (cos (_angle) *uv.y+sin (_angle) *uv.x); Half4 c = tex2d (_maintex, UV); O. Albedo = C.rgb;o. Alpha = C.A;} ENDCG} FallBack "Diffuse"}



====================================================================================

End.

Unity shader Programming (3) UV operation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.