一、最终效果
二、制作步骤
溶解效果的核心思想为 clip 函数的使用
2.1 使用 noise 贴图,来模拟不规则边缘
2.2 通过使用 smoothstep 方法,并添加内焰和外焰颜色,实现火焰效果
_EdgeWidth = Remap(_EdgeWidth, half2(0, 1), half2(_ClipValue, 1));
half edgeMask = 1 - smoothstep(_ClipValue, _EdgeWidth, dissolveMask);
half4 edgeColor = lerp(_EdgeColor1 * _EdgeColor1Intensity, _EdgeColor2 * _EdgeColor2Intensity, edgeMask);
edgeColor = edgeColor * edgeMask;
2.3 通过设置一个中心点,计算 UV 到该中心点的距离,与 mask 值相加,可实现定向(圆形)溶解
half dissolveDis = distance(IN.texcoord.xy, half2(_DissolveCenterX, _DissolveCenterY));
2.4 通过 _Time 偏移 noise 贴图的 offset 便可实现火焰流动的动态效果
2.5 通过添加一个缩放值,计算在距离结果上,可以改变它的扩散
代码如下:
half4 finalColor = (tex2D(_MainTex, IN.texcoord.xy) + _TextureSampleAdd) * IN.color;
half dissolveDis = distance(IN.texcoord.xy, half2(_DissolveCenterX, _DissolveCenterY));
half dissolveMask = maskRaw + dissolveDis * _DissolveScale;
最终效果:
参考:
https://zhuanlan.zhihu.com/p/138942181
https://github.com/zd304/Dissolve/tree/master/Assets/Shaders