shader多图叠加变换

本文介绍了如何使用Unity3D的Shader技术,结合C#脚本,实现3D场景中多张图片的叠加及动态变换效果,详细探讨了Shader语言的应用和关键代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

shader 

Shader "Paint3D/AddTexture"
{
    Properties
	{		
	    _MainTex ("Main Texture", 2D) = "white" {}
        _MainColor("Main Color", Color)=(1,1,1,1) 
        _AddTex0 ("Texture0", 2D) = "white" {}
        _AddTex1 ("Texture1", 2D) = "white" {}
        _offsetX("offsetX",Range(-5,5)) = 0
        _offsetY("offsetY",Range(-5,5)) = 0
        _oftX("oftX",Range(-5,5)) = -0.67
        _deg("scaleZ",Range(-360,360)) = 0
        _Color("AddColor",Color)= (1,1,1,1) 
        _imageSize("ImageSize整体",float)=10
        _expendSize("Expend拖拽拉伸",float)=1
        _size("Size粗细",float)=1
        _isShow("isShow",float)=0
        _height("Screeheight暂时无用",float)=1536
        _Imgwidth("Imgwidth暂时无用",float)=200
        _Imgheight("Imgheight暂时无用",float)=200
	}
	SubShader
	{
		Tags { "Queue"="AlphaTest"  "RenderType"="Transparent" }
		LOD 200
        Cull Off
        Lighting Off
        ZWrite Off
        ZTest [unity_GUIZTestMode]
        Blend SrcAlpha OneMinusSrcAlpha
 
		Pass
		{
			CGPROGRAM
			#pragma vertex vert
            #pragma fragment frag
            #pragma target 2.0
            #pragma multi_compile_fog
           // #pragma surface Surf Standard alphatest:_Cutoff addshadow
            #include "UnityCG.cginc"
 
            struct appdata_t {
                float4 vertex : POSITION;
                float2 texcoord : TEXCOORD0;
                UNITY_VERTEX_INPUT_INSTANCE_ID
            };
 
            struct v2f {
                float4 vertex : SV_POSITION;
                float2 texcoord : TEXCOORD0;
                UNITY_FOG_COORDS(1)
                UNITY_VERTEX_OUTPUT_STEREO
            };
 
            sampler2D _MainTex;
            sampler2D _AddTex0;
            sampler2D _AddTex1;
            float4 _MainTex_ST;
			fixed4 _Color;
            fixed4 _MainColor;
            float _offsetX;
            float _offsetY;
            float _oftX;
            float _deg;
            float _isShow;
            float _height;
            float _Imgwidth;
            float _Imgheight;
            float _imageSize;
            float _expendSize;
            float _size;
 
            v2f vert (appdata_t v)
            {
                v2f o;
                UNITY_SETUP_INSTANCE_ID(v);
                UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
                UNITY_TRANSFER_FOG(o,o.vertex);
                return o;
            }
          
            fixed4 frag (v2f i) : SV_Target
            {
                fixed4 texCol ;
                if(_isShow==0){
                      texCol = tex2D(_MainTex, i.texcoord);
                      return texCol*_MainColor;
                }

                float3 uvw0= float3(i.texcoord.x,i.texcoord.y,1);
                float3 uvw1= float3(i.texcoord.x,i.texcoord.y,1);
             
                float3x3 transla0=float3x3(float3(1,0,-_offsetX),float3(0,1,-_offsetY),float3(0,0,1));
                float3x3 transla1=float3x3(float3(1,0,-_offsetX),float3(0,1,-_offsetY),float3(0,0,1));
                
                uvw0 =mul(transla0, uvw0);
                uvw1 =mul(transla1, uvw1);

                float rad=radians(_deg);
                float3x3 rotate=float3x3(float3(cos(rad),-sin(rad),0),float3(sin(rad),cos(rad),0),float3(0,0,1));
                
                uvw0 =mul(rotate, uvw0);
                uvw1 =mul(rotate, uvw1);

                float3x3 scale0=float3x3(float3(_imageSize/_expendSize,0,-0.5),float3(0,_imageSize*_size,0),float3(0,0,1));
                float3x3 scale1=float3x3(float3(_imageSize,0,-_expendSize),float3(0,_imageSize*_size,0),float3(0,0,1));

                //float3x3 scale=float3x3(float3(_width/_imageSize/_expendSize,0,0),float3(0,_height/_imageSize,0),float3(0,0,1));
               
                uvw0 =mul(scale0 ,uvw0);
                uvw1 =mul(scale1 ,uvw1);

               

                float2 uv0=float2(uvw0.x,uvw0.y);
                float2 uv1=float2(uvw1.x,uvw1.y);
                uv0+=0.5;
                uv1+=0.5;
        
                 texCo
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

李一民001

创作不易,如有帮助,不胜荣幸

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值