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