使用UnityShader实现模型的边缘流光效果

使用UnityShader实现模型的边缘流光效果


实现原理------------------------------------------------------------------------------------

  1. 边缘发光+流光效果
fixed4 frag (v2f i) : SV_Target
            {
               
                fixed4 col = tex2D(_MainTex, i.uv);
				
				//边缘外发光
				float rim = pow(saturate((1 - dot(normalize(i.normal), normalize(i.objViewDir)))),_RimPower)*_RimIntensity;
				fixed4 rimColor = rim * _RimColor;
			

				//流光效果		
				float2 flowUV = float2(i.uv.x, i.uv.y+_Time.y*_Speed);
				fixed4 maskColor = tex2D(_MaskTex, flowUV);

				fixed4 finalColor = col + rimColor* maskColor.r;
				return finalColor;
				//return maskColor;
            }
  1. 流光效果:UV流光和世界空间或模型空间流光
fixed4 frag (v2f i) : SV_Target
            {
               
                fixed4 col = tex2D(_MainTex, i.uv);						
				//流光效果	
			    //使用纹理坐标,流光可能不是严格的从上到下或从下到上
				//float2 flowUV = float2(i.uv.x, i.uv.y+_Time.y*_Speed);   


			    //使用世界坐标偏移
				float2 flowUV = float2(i.worldPos.x, i.worldPos.y*_Scale + _Time.y*_Speed);

				fixed4 maskColor = tex2D(_MaskTex, flowUV);

				fixed4 finalColor = col + _RimColor * maskColor.r;
				return finalColor;
				//return maskColor;
            }
  1. 不使用贴图的方式
v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);   

				if (v.vertex.x<_Top && v.vertex.x>_Top - _Range){
					o.litColor = float4(0, 1, 1, 1);
				}
				else {
					o.litColor = float4(0, 0, 0, 0);
				}

                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {             
                fixed4 col = tex2D(_MainTex, i.uv)+i.litColor;               
                return col;
            }

4.溶解消失

  v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);   
				o.DisVector = fixed2(0, 0);
				if (v.vertex.x<_Top && v.vertex.x>_Top - _Range){
					o.litColor = float4(0, 1, 1, 1);
				}
				else if (v.vertex.x >= _Top) {
					//o.litColor = float4(1, 0, 0, 1);
					o.DisVector = fixed2(1, v.vertex.x - _Top);
				}
				else {
					o.litColor = float4(0, 0, 0, 0);
				}

                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {             
                fixed4 col = tex2D(_MainTex, i.uv)+i.litColor;   

				
				if (i.DisVector.x > 0.8) {			
					clip(_ClipValue - i.DisVector.x * maskCol.a - i.DisVector.y);
					}
                return col;
            }
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值