好玩的可交互护盾效果——UnityShader学习笔记


自言自语

嗯今天又来一个效果。比较绕哦 有好几个小知识点。为了怕自己忘记了就放上来源码吧。 其中几个方法都是之前小知识点的集合。

一、效果就不贴了 演示起来肯定超出GIF上限了 懒得弄了

二、代码部分

1.C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RayHitPosition : MonoBehaviour
{
    public ParticleSystem particleController;
    [Range (0,100)]
    public int Particle=100;
    public float timeInvertal = 0.1f;
    private float timeClock = 0.0f;
    //声明粒子数组 存储设定好的粒子 注意粒子个数后边为.Particle
    private ParticleSystem.Particle [] particleArray;
    //声明粒子位置的数组 存储每个粒子位置
    private Vector4[] particlePosition;
    //声明所有粒子的大小存储的数组
    private float[] size;

    // Start is called before the first frame update
    void Start()
    {

    }
    void RayCast()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(ray, out RaycastHit rayCastinfo, Camera.main.farClipPlane,LayerMask.GetMask("EffectLayer")))
        {
            Debug.DrawRay(rayCastinfo.point, Camera.main.transform.TransformDirection(Vector3.forward), Color.green);           
            particleController.transform.position = rayCastinfo.point;
            particleController.Emit(1);
            //transform.position = rayCastinfo.point;
        }
        else
        {
            Debug.DrawRay(rayCastinfo.point, Camera.main.transform.TransformDirection(Vector3.forward), Color.yellow);
        }
    }
    // Update is called once per frame
    void Update()
    {
        //声明一个计时器。
        timeClock += Time.deltaTime;
        if (Input.GetMouseButton(0))
        {
            if(timeClock > timeInvertal)
            {
                RayCast();
                timeClock = 0.0f;
            }
        }
        //声明粒子系统的最大粒子数 用于控制和统一粒子数量
        var particleMain = particleController.main;
        particleMain.maxParticles = Particle;

        //将各个声明好的数组进行初始化 数组使用前要进行初始化操作
        particleArray = new ParticleSystem.Particle[Particle];
        particlePosition = new Vector4[Particle];
        size = new float[Particle];

        //然后给每个数组进行赋值 首先把从particleController得到的所有粒子存出在particleArray粒子数组中
        particleController.GetParticles(particleArray);

        //再利用For循环,将每个粒子的position和size赋值给相应的数组元素,即可遍历得到第i个粒子的中的坐标和大小
        for (int i = 0;i< Particle;i++)
        {
            particlePosition[i] = particleArray[i].position;
            //注意GetCurrentSize()是个方法 所以用括号进行 一开始也惯性思维的或者完全没用脑子的以为是数组 给中括号会报错。
            size[i] = particleArray[i].GetCurrentSize(particleController);
        }
        Shader.SetGlobalFloat("MaxParticle", Particle);
        Shader.SetGlobalVectorArray("circleCenter", particlePosition);
        Shader.SetGlobalFloatArray("waveSize", size);
    }
}

2.Shader

Shader "TNEffectShaders/ShaderPractise_WaveClic"
{
    Properties
    {
		[Header(Wave)]
		[HDR]_WaveColor("WaveColor",Color) = (1,1,1,1)
		_RampMap ("Ramp",2D) ="white"{}
		_circleSpread("_circleSpread",Float) = 0
		_FadeSize ("FadeSize",Float) =1
		_FadeSmooth("FadeSmooth",Float) =1
	    _NoiseTex ("WaveNoise", 2D) = "white" {}
		_NoiseIntensity("WaveNoiseIntensity",Float) = 1

		[Space(10)][Header(Distortion)]	
		[HDR]_DistortionColor("DistortionColor",Color) =(1,1,1,1)
		[HDR]_MainColor ("FresnelColor",Color)=(1,1,1,1)
		_DistortionFactor("Distortion",Float) = 1
		_DistortionSmooth("DistortionSmooth",Float)=1
		_NoiseTexDistor("DistorNoise",2D)="white"{}
		_NoiseIntensityDistor("DistorNoiseIntensity",Float) =1
		_PositionOffset("Position",Vector) = (0,0,0,0)

		[Space(10)][Header(Sheild)]
		_FresnelIntensity("FresnelIntensity",Float) =1
		_FresnelSmooth("FresnelSmooth",Float) = 1
		_FlowSpeed("FlowSpeed",Float) =0.25
		_EdgeValue("SheildEdge",Float) = 0
		_EdgePow("Edgesmooth",Range(0,1)) =1
		//_NoiseSpeed("NoiseSpeed",Float) =0.25
		_FlowLightmap("FlowLightMap",2D) ="white"{}
		_FlowMap("FlowMap",2D) = "white"{}
		_FlowIntensity("FlowIntensity",Vector) =(1,1,0,0)
		_Alpha("TotalAlpha",Float) = 1


		//_MaxParticle("MaxParticle",Int) = 20
		//_waveSize("_waveSize",Float) = 0
		//_circleCenter("circleCenter",Vector4)=(0,0,0,0)
    }
    SubShader
    {
        Tags { "RenderType"="Transparent" "Queue" ="Transparent"  }

        Pass
        {
			Blend SrcAlpha OneMinusSrcAlpha
			Cull Front
            CGPROGRAM
			#ifndef UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX
			//only defining to not throw compilation error over Unity 5.5
			#define UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input)
			#endif
	        #pragma vertex vert
            #pragma fragment frag
			#pragma target 4.0
            #include "UnityCG.cginc"

            struct a2v
            {
                float4 vertex : POSITION;
                float2 texcoord : TEXCOORD0;
				float3 normal : NORMAL;
				UNITY_VERTEX_INPUT_INSTANCE_ID
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 pos : SV_POSITION;
				float4 posWS : TEXCOORD1;
				float4 scrpos :    TEXCOORD5;
				float3 normalWS : TEXCOORD2;
				float2 uv2 : TEXCOORD3;
				float2 uv3 : TEXCOORD4;
				UNITY_VERTEX_INPUT_INSTANCE_ID
				UNITY_VERTEX_OUTPUT_STEREO
            };

            sampler2D _NoiseTex;
			float _NoiseIntensity;
            float4 _NoiseTex_ST;
			sampler2D _RampMap;

			//这3个参数时要传进来的
			uniform float MaxParticle;
			uniform float waveSize[100];
			uniform float4 circleCenter[100];
			//这3个参数时要传进来的


			float _circleSpread;
			float _FadeSize;
			float _FadeSmooth;
			float4 _PositionOffset;
			float _DistortionFactor;
			float _DistortionSmooth;
			float _FresnelIntensity;
			float _FresnelSmooth;
			float4 _MainColor;
			float4 _DistortionColor;
			sampler2D _FlowMap;
			sampler2D _FlowLightmap;
			float4 _FlowMap_ST;
			float4 _FlowLightmap_ST;
			float2 _FlowIntensity;
			float _FlowSpeed;
			float _NoiseSpeed;
			float4 _WaveColor;
			sampler2D _NoiseTexDistor;
			float _NoiseIntensityDistor;
			float _EdgeValue;
			float _EdgePow;
			float _Alpha;
			
			//声明深度图,拿到深度图算边界
			UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
			float4 _CameraDepthTexture_TexelSize;

            v2f vert (a2v v)
            {
                v2f o;
				UNITY_SETUP_INSTANCE_ID(v);
				UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
				UNITY_TRANSFER_INSTANCE_ID(v, o);

                o.pos = UnityObjectToClipPos(v.vertex);
				o.scrpos = ComputeScreenPos(o.pos);
                o.uv = TRANSFORM_TEX(v.texcoord, _NoiseTex);
                o.uv3 = TRANSFORM_TEX(v.texcoord, _FlowLightmap);
				o.uv2 = TRANSFORM_TEX(v.texcoord,_FlowMap);
				o.posWS = mul(unity_ObjectToWorld,v.vertex);
				o.normalWS = UnityObjectToWorldNormal(v.normal);
                 return o;
            }

			//Triplanar——Time
			half4 TriPlanar (float3 posWS,half3 normal,float smooth,sampler2D textures)
			{
				half3 normalWS = normalize(normal);
				half3 weight = pow(abs(normalWS),smooth);
				half3 uvWeight = weight /(weight.x+weight.y+weight.z);

				half4 col0 = tex2D(textures,posWS.xy+_Time.y*_NoiseSpeed)*uvWeight.z;
                half4 col1 = tex2D(textures,posWS.xz+_Time.y*_NoiseSpeed)*uvWeight.y;
                half4 col2 = tex2D(textures,posWS.zy+_Time.y*_NoiseSpeed)*uvWeight.x;

                return col0+col1+col2;
			} 		
			//Triplanar----notime
			half4 TriPlanarnotime (float3 posWS,half3 normal,float smooth,sampler2D textures,float2 flow,float2 uv3)
			{
				half3 normalWS = normalize(normal);
				half3 weight = pow(abs(normalWS),smooth);
				half3 uvWeight = weight /(weight.x+weight.y+weight.z);

				half4 col0 = tex2D(textures,posWS.xy*uv3+flow)*uvWeight.z;
                half4 col1 = tex2D(textures,posWS.xz*uv3+flow)*uvWeight.y;
                half4 col2 = tex2D(textures,posWS.zy*uv3+flow)*uvWeight.x;

                return col0+col1+col2;
			}

			//waveClick
			half FinalWave (float3 worldPos,sampler2D noise,float2 uv,float noiseIntensity,float smooth,sampler2D rampmap,float fadeScale,float fadeIntensity,half3 normal)
			{
				half ramp;
				for (int j = 0;  j<MaxParticle; j++)
				{
			
					//求距离  函数作用是求空间中任意一点到物体表面的最小距离。此间我们假设坐标原点为000中心点
					//中心点到任意一点像素的最小距离可有如下两个函数求出. 任意一点越接近000点则返回值越小越黑.减去半径后则可以求画出相应的圆形.
					//float dis = length(circleCenter - i.posWS.xyz);
					float dis = distance(circleCenter[j],worldPos);
					float circleSize = dis - waveSize[j];
					//float noisemap = tex2D(noise, uv).r;
					float noisemap = TriPlanarnotime(worldPos,normal,0.5,noise,0,uv).r;

					//淡出范围和淡出平滑																				 
					float fadesize =1- dis /fadeScale;
					float fadeSmooth =saturate( fadesize * fadeIntensity);

					float circleCol = saturate((circleSize + noisemap*noiseIntensity)/smooth);
				    float wave = tex2D (rampmap,float2(circleCol,0.5)).r;
					float wavefade = wave *fadeSmooth;
					ramp += wavefade;
				}
				return saturate(ramp);
			}

			half Luminance (float4 col)
			{
				half  lum = col.r*0.2125+col.g*0.7154+col.b*0.0721;
				return lum;
			}

			//FlowMap
			half4 FlowMapFunction (float flowspeed,float2 flowIntensity,sampler2D maintex,float2 maintexUV,float4 posws,half3 normal,float smooth,float2 uv3,float2 uv2,half wave,float2 uv,half Distortionnal)
            {
                //先算个时间
                float2 timeDelta = frac(_Time.y*flowspeed)*flowIntensity;
                //再算个间隔帧时间
                float2 timeNext =frac(_Time.y*flowspeed+0.5)*flowIntensity;
                //再算个两个时间插值的插值因子
                float timeLerp = abs(frac(_Time.y*flowspeed)*2-1);
                //采样flowmap 当做干扰方向	融入三平面映射
				//half2 flowDirection = TriPlanarnotime(posws,normal,smooth,_FlowMap,0,uv2).rg;
                half2 flowDirection = 0.5-tex2D(_FlowMap,uv2).rg+wave+0.02+Distortionnal;
				//half2 flowDirection = -tex2D(_FlowMap,flowuv).rg;

                //前一状态的流动效果
                half2 FlowMap = flowDirection*timeDelta;
                //half4 mainTexpre = tex2D(maintex,maintexUV+FlowMap);
				half4 mainTexpre = TriPlanarnotime(posws,normal,smooth,maintex,FlowMap,uv3);
                //后一状态的流动效果
                half2 flowMapNext = flowDirection*timeNext; 
                //half4 mainTex = tex2D(maintex,maintexUV+flowMapNext);
				half4 mainTex = TriPlanarnotime(posws,normal,smooth,maintex,flowMapNext,uv3);
                //插值两个流动效果 减少顿挫感
                half4 col =  lerp(mainTexpre,mainTex,timeLerp);
				float mask  = 1-saturate(pow(1-smoothstep(uv.y,1,0.65),100));
				col *= 	mask;
                //输出最终效果
                return col;            
            }


            half4 frag (v2f i) : SV_Target
            {
				//前置准备
				float3 worldPos = i.posWS.xyz;
				half3 viewDir = normalize(UnityWorldSpaceViewDir(worldPos));
				half3 normalDir = normalize(i.normalWS);
				//求交叉边缘
				float4 screenPos  = i.scrpos/i.scrpos.w;
				screenPos.z = UNITY_NEAR_CLIP_VALUE>=0 ? screenPos.z : screenPos.z*0.5+0.5;
				float depth = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,screenPos.xy));
				float distanceDepth =saturate(abs ((depth - LinearEyeDepth(screenPos.z))/_EdgeValue)*100);
				float EdgeSmooth =1-saturate(smoothstep(0,_EdgePow,distanceDepth));

				//溶解
				float3 centerpos = worldPos.xyz - mul(unity_ObjectToWorld,float4(0,0,0,1)).xyz;
				float3 localPos = _PositionOffset;
				half distortionNoise = tex2D(_NoiseTexDistor,i.uv+_Time.y*0.05).r*_NoiseIntensityDistor;
				half dispos = distance(localPos,centerpos);
				half distortion = saturate((dispos - _DistortionFactor+distortionNoise)/_DistortionSmooth);

				//边缘光
				half NdotV = abs(dot(normalDir,viewDir));
				half fresnel = saturate(1 - NdotV);
				fresnel =saturate( (fresnel+_FresnelIntensity )/_FresnelSmooth);
				fresnel += EdgeSmooth;
				half4 fresnelColor = _MainColor * saturate(fresnel);

				//点击扩散
				half Wave = saturate(FinalWave(i.posWS.xyz,_NoiseTex,i.uv,_NoiseIntensity,_circleSpread,_RampMap,_FadeSize,_FadeSmooth,normalDir));

 				//加FlowMap扰动
				half4 FlowMap =FlowMapFunction(_FlowSpeed,_FlowIntensity,_FlowLightmap,i.uv3,i.posWS,normalDir,5,i.uv3,i.uv2,Wave+Wave,i.uv,distortion);
				half4 mainColor = fresnelColor * FlowMap;
				mainColor.a = saturate((Luminance(FlowMap*fresnel+EdgeSmooth)+Wave)*_Alpha);
		    
				//溶解边缘光插值合并
				mainColor = lerp(mainColor,distortion*_DistortionColor,saturate(1-distortion));

				//再把点击扩散与溶解合并后乘上颜色加进去
				half4 WaveColor = Wave*_WaveColor;
				mainColor += WaveColor;

				return float4(mainColor.rgb,mainColor.a);
				
            }
            ENDCG		
        }
		    Pass
        {
			Blend SrcAlpha OneMinusSrcAlpha
			Cull Back
            CGPROGRAM
			#ifndef UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX
			//only defining to not throw compilation error over Unity 5.5
			#define UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input)
			#endif
	        #pragma vertex vert
            #pragma fragment frag
			#pragma target 4.0
            #include "UnityCG.cginc"

            struct a2v
            {
                float4 vertex : POSITION;
                float2 texcoord : TEXCOORD0;
				float3 normal : NORMAL;
				UNITY_VERTEX_INPUT_INSTANCE_ID
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 pos : SV_POSITION;
				float4 posWS : TEXCOORD1;
				float4 scrpos :    TEXCOORD5;
				float3 normalWS : TEXCOORD2;
				float2 uv2 : TEXCOORD3;
				float2 uv3 : TEXCOORD4;
				UNITY_VERTEX_INPUT_INSTANCE_ID
				UNITY_VERTEX_OUTPUT_STEREO
            };

            sampler2D _NoiseTex;
			float _NoiseIntensity;
            float4 _NoiseTex_ST;
			sampler2D _RampMap;

			//这3个参数时要传进来的
			uniform float MaxParticle;
			uniform float waveSize[100];
			uniform float4 circleCenter[100];
			//这3个参数时要传进来的


			float _circleSpread;
			float _FadeSize;
			float _FadeSmooth;
			float4 _PositionOffset;
			float _DistortionFactor;
			float _DistortionSmooth;
			float _FresnelIntensity;
			float _FresnelSmooth;
			float4 _MainColor;
			float4 _DistortionColor;
			sampler2D _FlowMap;
			sampler2D _FlowLightmap;
			float4 _FlowMap_ST;
			float4 _FlowLightmap_ST;
			float2 _FlowIntensity;
			float _FlowSpeed;
			float _NoiseSpeed;
			float4 _WaveColor;
			sampler2D _NoiseTexDistor;
			float _NoiseIntensityDistor;
			float _EdgeValue;
			float _EdgePow;
			float _Alpha;
			
			//声明深度图,拿到深度图算边界
			UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
			float4 _CameraDepthTexture_TexelSize;

            v2f vert (a2v v)
            {
                v2f o;
				UNITY_SETUP_INSTANCE_ID(v);
				UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
				UNITY_TRANSFER_INSTANCE_ID(v, o);

                o.pos = UnityObjectToClipPos(v.vertex);
				o.scrpos = ComputeScreenPos(o.pos);
                o.uv = TRANSFORM_TEX(v.texcoord, _NoiseTex);
                o.uv3 = TRANSFORM_TEX(v.texcoord, _FlowLightmap);
				o.uv2 = TRANSFORM_TEX(v.texcoord,_FlowMap);
				o.posWS = mul(unity_ObjectToWorld,v.vertex);
				o.normalWS = UnityObjectToWorldNormal(v.normal);
                 return o;
            }

			//Triplanar——Time
			half4 TriPlanar (float3 posWS,half3 normal,float smooth,sampler2D textures)
			{
				half3 normalWS = normalize(normal);
				half3 weight = pow(abs(normalWS),smooth);
				half3 uvWeight = weight /(weight.x+weight.y+weight.z);

				half4 col0 = tex2D(textures,posWS.xy+_Time.y*_NoiseSpeed)*uvWeight.z;
                half4 col1 = tex2D(textures,posWS.xz+_Time.y*_NoiseSpeed)*uvWeight.y;
                half4 col2 = tex2D(textures,posWS.zy+_Time.y*_NoiseSpeed)*uvWeight.x;

                return col0+col1+col2;
			} 		
			//Triplanar----notime
			half4 TriPlanarnotime (float3 posWS,half3 normal,float smooth,sampler2D textures,float2 flow,float2 uv3)
			{
				half3 normalWS = normalize(normal);
				half3 weight = pow(abs(normalWS),smooth);
				half3 uvWeight = weight /(weight.x+weight.y+weight.z);

				half4 col0 = tex2D(textures,posWS.xy*uv3+flow)*uvWeight.z;
                half4 col1 = tex2D(textures,posWS.xz*uv3+flow)*uvWeight.y;
                half4 col2 = tex2D(textures,posWS.zy*uv3+flow)*uvWeight.x;

                return col0+col1+col2;
			}

			//waveClick
			half FinalWave (float3 worldPos,sampler2D noise,float2 uv,float noiseIntensity,float smooth,sampler2D rampmap,float fadeScale,float fadeIntensity,half3 normal)
			{
				half ramp;
				for (int j = 0;  j<MaxParticle; j++)
				{
			
					//求距离  函数作用是求空间中任意一点到物体表面的最小距离。此间我们假设坐标原点为000中心点
					//中心点到任意一点像素的最小距离可有如下两个函数求出. 任意一点越接近000点则返回值越小越黑.减去半径后则可以求画出相应的圆形.
					//float dis = length(circleCenter - i.posWS.xyz);
					float dis = distance(circleCenter[j],worldPos);
					float circleSize = dis - waveSize[j];
					//float noisemap = tex2D(noise, uv).r;
					float noisemap = TriPlanarnotime(worldPos,normal,0.5,noise,0,uv).r;

					//淡出范围和淡出平滑																				 
					float fadesize =1- dis /fadeScale;
					float fadeSmooth =saturate( fadesize * fadeIntensity);

					float circleCol = saturate((circleSize + noisemap*noiseIntensity)/smooth);
				    float wave = tex2D (rampmap,float2(circleCol,0.5)).r;
					float wavefade = wave *fadeSmooth;
					ramp += wavefade;
				}
				return saturate(ramp);
			}

			half Luminance (float4 col)
			{
				half  lum = col.r*0.2125+col.g*0.7154+col.b*0.0721;
				return lum;
			}

			//FlowMap
			half4 FlowMapFunction (float flowspeed,float2 flowIntensity,sampler2D maintex,float2 maintexUV,float4 posws,half3 normal,float smooth,float2 uv3,float2 uv2,half wave,float2 uv,half Distortionnal)
            {
                //先算个时间
                float2 timeDelta = frac(_Time.y*flowspeed)*flowIntensity;
                //再算个间隔帧时间
                float2 timeNext =frac(_Time.y*flowspeed+0.5)*flowIntensity;
                //再算个两个时间插值的插值因子
                float timeLerp = abs(frac(_Time.y*flowspeed)*2-1);
                //采样flowmap 当做干扰方向	融入三平面映射
				//half2 flowDirection = TriPlanarnotime(posws,normal,smooth,_FlowMap,0,uv2).rg;
                half2 flowDirection = 0.5-tex2D(_FlowMap,uv2).rg+wave+0.02+Distortionnal;
				//half2 flowDirection = -tex2D(_FlowMap,flowuv).rg;

                //前一状态的流动效果
                half2 FlowMap = flowDirection*timeDelta;
                //half4 mainTexpre = tex2D(maintex,maintexUV+FlowMap);
				half4 mainTexpre = TriPlanarnotime(posws,normal,smooth,maintex,FlowMap,uv3);
                //后一状态的流动效果
                half2 flowMapNext = flowDirection*timeNext; 
                //half4 mainTex = tex2D(maintex,maintexUV+flowMapNext);
				half4 mainTex = TriPlanarnotime(posws,normal,smooth,maintex,flowMapNext,uv3);
                //插值两个流动效果 减少顿挫感
                half4 col =  lerp(mainTexpre,mainTex,timeLerp);
				float mask  = 1-saturate(pow(1-smoothstep(uv.y,1,0.65),100));
				col *= 	mask;
                //输出最终效果
                return col;            
            }


            half4 frag (v2f i) : SV_Target
            {
				//前置准备
				float3 worldPos = i.posWS.xyz;
				half3 viewDir = normalize(UnityWorldSpaceViewDir(worldPos));
				half3 normalDir = normalize(i.normalWS);
				//求交叉边缘
				float4 screenPos  = i.scrpos/i.scrpos.w;
				screenPos.z = UNITY_NEAR_CLIP_VALUE>=0 ? screenPos.z : screenPos.z*0.5+0.5;
				float depth = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture,screenPos.xy));
				float distanceDepth =saturate(abs ((depth - LinearEyeDepth(screenPos.z))/_EdgeValue)*100);
				float EdgeSmooth =1-saturate(smoothstep(0,_EdgePow,distanceDepth));

				//溶解
				float3 centerpos = worldPos.xyz - mul(unity_ObjectToWorld,float4(0,0,0,1)).xyz;
				float3 localPos = _PositionOffset;
				half distortionNoise = tex2D(_NoiseTexDistor,i.uv+_Time.y*0.05).r*_NoiseIntensityDistor;
				half dispos = distance(localPos,centerpos);
				half distortion = saturate((dispos - _DistortionFactor+distortionNoise)/_DistortionSmooth);

				//边缘光
				half NdotV = abs(dot(normalDir,viewDir));
				half fresnel = saturate(1 - NdotV);
				fresnel =saturate( (fresnel+_FresnelIntensity )/_FresnelSmooth);
				fresnel += EdgeSmooth;
				half4 fresnelColor = _MainColor * saturate(fresnel);

				//点击扩散
				half Wave = saturate(FinalWave(i.posWS.xyz,_NoiseTex,i.uv,_NoiseIntensity,_circleSpread,_RampMap,_FadeSize,_FadeSmooth,normalDir));

 				//加FlowMap扰动
				half4 FlowMap =FlowMapFunction(_FlowSpeed,_FlowIntensity,_FlowLightmap,i.uv3,i.posWS,normalDir,5,i.uv3,i.uv2,Wave+Wave,i.uv,distortion);
				half4 mainColor = fresnelColor * FlowMap;
				mainColor.a = saturate((Luminance(FlowMap*fresnel+EdgeSmooth)+Wave)*_Alpha);
		    
				//溶解边缘光插值合并
				mainColor = lerp(mainColor,distortion*_DistortionColor,saturate(1-distortion));

				//再把点击扩散与溶解合并后乘上颜色加进去
				half4 WaveColor = Wave*_WaveColor;
				mainColor += WaveColor;

				return float4(mainColor.rgb,mainColor.a);
				
            }
            ENDCG		
        }
    }
}



总结

这个小效果啃了一个礼拜多。。。哎 超级打击自信心 好在现在弄出来了 扛过来就好了 继续啃新东西

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值