美术生零基础转行TA中(第7天)

202404010 学习目标:

  • 刷课至4.4

学习内容:

4.3 片段的舍弃 Clip

  • Clip(x):如果X<0,则舍弃掉此片段

  • 溶解效果

  • 修改溶解效果的Tilling Offset

Shader "taecg/Character Unlit"
{
    properties
    {
    [ Header (Base) ]
    [NoScaleOffset] _MainTex ( "MainTex" , 2D ) = "White" { }
    _Color ( "Color",color ) = (0,0,0,0)
    
    [ Space (10) ]
    [ Header (Dissolve) ]
    _DissovlveTex(DissolveTex(R)", 2D ) = "White" { }
    _Clip ( "Clip",Range(0,1)) = 0

    }
    SubShader
    {
        pass
        {
            CGPROGRAM
            #pragma vertex vert
             #pragma fragment frag
             #include "UnityCG/cginc"
             
             spmpler 2D _MainTex;
             fixed4 _color ;
             sampler2D _DissolveTex;float4_DissolveTex_ST;
             fixed _Clip;
             
             struct appdata
             {
                 float4 vertex : POSITION ;
                 float4 uv       : TEXCOORD1;
             } ;
             
             struct v2f
             {
                 float4 pos : SV_POSITION ;
                 float4 uv    : TEXCOORD;
             } ;
             
             v2f vert (appdata v)
             {
                 v2f o ;
                 o.pos = UnityObjectToClipPos ( v.vertex ) ;
                 o.uv.xy = v.uv.xy ;
                 // o.uv.zw = v.uv * DissolveTex_ST.xy+_DissolveTex_ST.zw ; 
                 o.uv.zw = TRANSFORM_TEX( v.uv , _DissolveTex );
                 return 0 ;
             }
             
             fixed4 frag (v2f i) : sv_TARGET
             {                 
                 fixed4 c;
                 fixed4 tex = tex2D( _MainTex, i.uv.xy);
                 c = tex ;
                 c + = _Color;
                 
                 fixed4 dissolveTex = tex2D( _DissolveTex,i.uv.zw);
                 Clip( dissolveTex .r - _Clip );
                 return c;
             }
             
             ENGCG

        }
    
    }

}

4.4 图形计算器

  • www.desmos.com
  • www.geogebra.org/graphing(用的人比较多)
    在这里插入图片描述

4.4 优化溶解效果

  • 希望体现火烧效果

  • 溶解边缘有不同颜色变化

  • smoothstep ( min, max, x ) 在两个值之间进行平滑过渡 高消耗

    • 如果x比min小,返回0
    • 如果x比max大,返回1
    • 如果x处于范围 [min,max] 中间,则范围0和1之间的平滑值
  • saturate (x)线性过渡 低消耗

    • 如果x比o小,返回0
    • 如果x比1大,返回1
    • 如果x处于范围 [0,1] 中间,返回x
    float smoothstep(min,max,x)
    {
    float t=saturate(x-min)/(max-min);
    return t*t*(3-2*t);
    }
    
  • 溶解原理:
    在这里插入图片描述

Shader "taecg/Character Unlit"
{
    properties
    {
    [ Header (Base) ]
    [NoScaleOffset] _MainTex ( "MainTex" , 2D ) = "White" { }
    _Color ( "Color",color ) = (0,0,0,0)
    
    [ Space (10) ]
    [ Header (Dissolve) ]
    _DissovlveTex(DissolveTex(R)", 2D ) = "White" { }
    [ NoScaleOffset ]_RampTex ( " RampTex( RGB ) " ,2D ) = "White" { }
    _Clip ( "Clip",Range(0,1)) = 0

    }
    SubShader
    {
        pass
        {
            CGPROGRAM
            #pragma vertex vert
             #pragma fragment frag
             #include "UnityCG/cginc"
             
             spmpler 2D _MainTex;
             fixed4 _color ;
             sampler2D _DissolveTex;float4_DissolveTex_ST ;
             sampler _RampTex ;
             fixed _Clip;
             
             struct appdata
             {
                 float4 vertex : POSITION ;
                 float4 uv       : TEXCOORD1;
             } ;
             
             struct v2f
             {
                 float4 pos : SV_POSITION ;
                 float4 uv    : TEXCOORD;
             } ;
             
             v2f vert (appdata v)
             {
                 v2f o ;
                 o.pos = UnityObjectToClipPos ( v.vertex ) ;
                 o.uv.xy = v.uv.xy ;
                 // o.uv.zw = v.uv * DissolveTex_ST.xy+_DissolveTex_ST.zw ; 
                 o.uv.zw = TRANSFORM_TEX( v.uv , _DissolveTex );
                 return 0 ;
             }
             
             fixed4 frag (v2f i) : sv_TARGET
             {                 
                 fixed4 c;
                 fixed4 tex = tex2D( _MainTex, i.uv.xy);
                 c = tex ;
                 c + = _Color;
                 
                 fixed4 dissolveTex = tex2D( _DissolveTex,i.uv.zw);
                 Clip( dissolveTex .r - _Clip );
                 fixed dissolveValue = saturate (( dissolveTex.r - _Clip ) / ( _Clip + 0.1 - _Clip ))  ;
                 fixed4 rampTex = tex1D(_RampTex , dissolveValue ) ; 
                 c+ = rampTex ; 
                 return c ;
             }
             
             ENGCG

        }
    
    }

}

学习产出:

  • 4.3
  • 4.4
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值