zoukankan      html  css  js  c++  java
  • Shader 入门(一)

    Shader "Unlit/贴图的平移缩放"
    {
    	Properties
    	{
    	_MainTex("Texture", 2D) = "white" {}
    	_UA("旋转中心x",Float) = 0.5
    	_UB("旋转中心y",Float) = 0.5
    	_CenterX("平移x",float) = 0
    	_CenterY("平移y",float) = 0
    	_Scale("缩放",Float) = 10
    	_RotateNum("旋转角度",Range(-360,360)) = 0
    	}
    		SubShader
    	{
    	Tags { "RenderType" = "Opaque" }
    	LOD 100
    	Pass
    	{
    	CGPROGRAM
    	#pragma vertex vert
    	#pragma fragment frag
    	#include "UnityCG.cginc"
    
    	sampler2D _MainTex;
    	float4 _MainTex_ST; 
    	float _UA;
    	float _UB;
    	float _RA;
    	float _Scale;
    	float _RotateNum;
    	float _CenterX;
    	float _CenterY;
    
    	struct v2f
    	{
    		float2 uv : TEXCOORD0;
    		float4 pos : SV_POSITION;
    	};
    
    	v2f vert(appdata_full v)
    	{
    		v2f o;
    		o.pos = UnityObjectToClipPos(v.vertex);
    		o.uv = v.texcoord;
    		return o;
    	}
    
    	fixed4 frag(v2f i) : SV_Target
    	{
    		//将角度转化为弧度             
    		float Rote = (_RotateNum * 3.1415926) / 180;
    		float sinNum = sin(Rote);
    		float cosNum = cos(Rote);
    
    		
    		float2 di = float2(_UA,_UB);
    		
    		//计算平移之后的坐标,需要乘平移矩阵   
    		float2 uv = mul(float3(i.uv - di,1),float3x3(1,0,0,0,1,0,_CenterX,_CenterY,1)).xy;
    		
    		//计算缩放之后的坐标,需要乘缩放矩阵
    		uv = mul(uv,float2x2(_Scale,0,0,_Scale));
    		
    		//计算旋转之后的坐标,需要乘旋转矩阵
    		uv = mul(uv,float2x2(cosNum,-sinNum,sinNum,cosNum)) + di;
    		fixed4 col;
    		
    		//用最终的坐标来采样当前的纹理,就ok了
    		col = tex2D(_MainTex,TRANSFORM_TEX(uv,_MainTex));;
    		return col;
    		}
    		ENDCG
    		}
    	}
    }
    

      

  • 相关阅读:
    PAT 字符串-02 删除字符串中的子串
    带滚动条的文本文件
    PAT IO-04 混合类型数据格式化输入(5)
    PAT IO-03 整数均值
    PAT IO-02 整数四则运算
    linux 之shell
    linux 软件包安装-脚本安装
    Linux 关闭防火墙命令
    linux RPM包管理-yum在线管理
    linux 软件包管理
  • 原文地址:https://www.cnblogs.com/chenggg/p/11704441.html
Copyright © 2011-2022 走看看