从b站上看见了一个卷轴效果,作者使用forge进行制作的,然后想着复刻下来,就尝试了一下。刚好当了学习记录。
B站视频地址:
效果:
卷轴shader
代码附上:
Properties
{
_Transform("Transform", Range( 0 , 1)) = 0.35
[Space(10)]
_MainTex("MainTex", 2D) = "white" {}
_BackTex("BackTex", 2D) = "white" {}
[Space(10)]
[Header(Common)]
[Space(10)]
_BackSpecular("BackSpecular", Color) = (0,0,0,1)
_ShadowColor("ShadowColor", Color) = (0,0,0,1)
_Shadow("Shadow", Range( 0 , 1)) = 0.75
_Range("Range", Range( 0 , 1)) = 0.2
_Rotator("Rotator", Float) = 0
[Toggle(_USEBACKTEX_ON)] _UseBackTex("UseBackTex", Float) = 0
}
SubShader
{
Tags { "Queue"="Transparent" "RenderType"="Transparent" }
LOD 100
Pass
{
Blend SrcAlpha OneMinusSrcAlpha, One OneMinusSrcAlpha
ZWrite Off
ZTest LEqual
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma shader_feature_local _USEBACKTEX_ON
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
float2 uv0 : TEXCOORD0;
float4 pos : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _BackTex;
float4 _BackTex_ST;
float4 _ShadowColor;
float4 _BackSpecular;
float _Rotator;
float _Transform;
float _Range;
float _Shadow;
v2f vert (appdata v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv0 = v.uv;
o.uv0 = TRANSFORM_TEX(v.uv, _MainTex);
o.uv0 = TRANSFORM_TEX(v.uv, _BackTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float2 texCoord_var = i.uv0.xy * float2( 1,1 ) + float2( 0,0 );
float cos_var = cos( radians( _Rotator ) );
float sin_var = sin( radians( _Rotator ) );
float2 rotator_var = mul( texCoord_var - float2( 0,0 ) , float2x2( cos_var , -sin_var , sin_var , cos_var )) + float2( 0,0 );
float U_var = (rotator_var).x;
float V_var = (rotator_var).y;
float Transform_var = _Transform;
float Range_var = _Range;
float CommonRange_var = ( Transform_var * ( Range_var + 1.0 ) );
float Texmask = step( V_var , CommonRange_var );
float lerp_v = lerp( V_var , ( (Transform_var + (V_var - 0.0) * (( Transform_var - 1.0 ) - Transform_var) / (1.0 - 0.0)) + Transform_var ) , Texmask);
float2 append_uv = (float2(U_var , lerp_v));
float4 textureUV_var = tex2D( _MainTex, append_uv );
float4 Shadow_var = saturate( ( (0.0 + (V_var - CommonRange_var) * (1.0 - 0.0) / (( ( Transform_var * _Shadow ) + CommonRange_var ) - CommonRange_var)) * _ShadowColor ) );
float clamp_var = clamp( abs( (-1.0 + (( distance( V_var , ( ( Range_var * 0.5 ) + Transform_var ) ) / Range_var ) - 0.0) * (1.0 - -1.0) / (1.0 - 0.0)) ) , 0.0 , 1.0 );
float4 blackColor = ( clamp_var * _BackSpecular );
#ifdef _USEBACKTEX_ON
float4 use_back = ( blackColor + tex2D( _BackTex, append_uv ) );
#else
float4 use_back = ( blackColor + textureUV_var );
#endif
float4 Color_var = lerp( ( textureUV_var * Shadow_var ) , use_back , Texmask);
float Clip_var = ( 1.0 - step( V_var , Transform_var ) );
float3 finalColor = Color_var.rgb;
float finalAlpha = ( textureUV_var.a * Clip_var );
return half4( finalColor, finalAlpha );
}
ENDCG
}
}
垃圾小特效的代码,有问题部分还望大佬们指正。