Unity URP shader之镭射效果实现

发布时间 2023-03-27 19:42:45作者: 孤独の巡礼

可参考:万物皆可镭射,个性吸睛的材质渲染技术

镭射公式分享如下:

 1 // 此公式来源于:https://zhuanlan.zhihu.com/p/487204843
 2 // HSV -> RGB
 3 half3 HUEToRGB(half h)
 4 {
 5     half3 color;
 6     color.r = abs(h*6-3) - 1;
 7     color.g = 2 - abs(h*6-2);
 8     color.b = 2 - abs(h*6-4);
 9     color = saturate(color);
10     return color;
11 }
12 
13 // HSV -> RGB
14 half3 HSVToRGB(half3 hsv)
15 {
16     half3 rgb = HUEToRGB(hsv.x);
17     half3 color = ((rgb-1)*hsv.y + 1) * hsv.z;
18     return color;
19 }
20 
21 // 计算镭射颜色
22 half3 CalcLaserColor(half fresnel, half4 param)
23 {
24     half hueValue = fresnel * param.x + param.y;
25     half3 hsvValue = half3(hueValue, param.z, param.w);
26     half3 color = HSVToRGB(hsvValue);
27     color = Pow2(color);
28     return color;
29 }

此公式生成的颜色如上:

 

 

如何在衣服上增加镭射效果?

调用代码参考如下:

1 // 镭射
2 half2 uv_laserNoise = input.uv * _LaserNoiseMap_ST;
3 uv_laserNoise += V.xy * _LaserNoiseSpeed;
4 half4 laserNoiseMap = SAMPLE_TEXTURE2D(_LaserNoiseMap, sampler_LaserNoiseMap, uv_laserNoise);
5 half fresnel = 1 - NoV + laserNoiseMap.r * _LaserNoiseScale;
6 half3 laserColor = CalcLaserColor(fresnel, _LaserParam);

shader面板如下:

 这里使用了一张noise图做扰动。

效果如下:

 转载请注明出处:https://www.cnblogs.com/jietian331/p/17262618.html