Unity3D URP 仿蜘蛛侠风格化BloomAO

URP 仿蜘蛛侠风格化Bloom&AO完善 风格化AO 总结
本篇文章介绍在URP中如何进行风格化后处理,使用和自定义Pass 实现 。这种做法比起使用具有很大的自由度,能够自由控制渲染时机,减少束缚 。
本教程使用.3.5f1 版本 。较低版本 Graph 没有Full。
以下两张图是蜘蛛侠动画剧照,高光Bloom部分很多是点阵的方式表现,一些AO使用混合平行斜线来表现 。
类似的卡通渲染方案也被游戏 HiFi Rush 所使用 。
Bloom Bloom效果流程:
先制作Bloom效果,将Bloom渲染到一张上,再将这个通过我们的风格化最后渲染到屏幕上
原始Bloom基本参照Unity的做法,在/com.unity.-.core/ 文件夹中可找到相关代码
制作控制面板.CS 直接复制Unity Bloom需要的控制参数 。添加我们风格化点阵需要的控制参数 。
[VolumeComponentMenuForRenderPipeline("CustomBloomEffect", typeof(UniversalRenderPipeline))]public class CustomBloomEffectComponent : VolumeComponent, IPostProcessComponent{//bloom settings copy from Unity default Bloom[Header("Bloom Settings")]public FloatParameter threshold = new FloatParameter(0.9f,true);public FloatParameter intensity = new FloatParameter(1,true);public ClampedFloatParameter scatter = new ClampedFloatParameter(0.7f,0,1,true);public IntParameter clamp = new IntParameter(65472,true);public ClampedIntParameter maxIterations = new ClampedIntParameter(6,0,10);public NoInterpColorParameter tint = new NoInterpColorParameter(Color.white);//Custom Bloom Dots[Header("Dots")] public IntParameter dotsDensity = new IntParameter(10,true);public ClampedFloatParameter dotsCutoff = new ClampedFloatParameter(0.4f,0,1, true);public Vector2Parameter scrollDirection = new Vector2Parameter(new Vector2());[Header("AOLines")]public ClampedFloatParameter linesWidth = new ClampedFloatParameter(0.001f,0.001f,0.01f, true);public ClampedFloatParameter linesIntensity = new ClampedFloatParameter(0.05f,0,0.05f, true);public ColorParameter linesColor = new ColorParameter(Color.black, true, true, true);public FloatParameter linesAngle = new FloatParameter(30f, true);public bool IsActive(){return true;}public bool IsTileCompatible(){return false;}}
将这个脚本挂载到场景中,我们就得到了一个和Unity原生很相识的一个控制面板,并且有新增的Dots控制功能:
参照Unity自带的我们可仿写一个我们自己的
Unity自带目录:
Pass
先创建一个简单的自定义Pass,这是渲染Pass,在中这些根节点都是一个Pass,如图:
最简代码如下:
[System.Serializable]public class CustomPostProcessPass : ScriptableRenderPass{public override void Execute(ScriptableRenderContext context,ref RenderingData renderingData)}}}
然后我们再创建一个
代码:
[System.Serializable]public class CustomPostProcessRendererFeature : ScriptableRendererFeature{private CustomPostProcessPass m_customPass;public override void AddRenderPasses(ScriptableRenderer renderer,ref RenderingData renderingData){renderer.EnqueuePass(m_customPass);}public override void Create(m_customPass = new CustomPostProcessPass()}}
有了这两个后,我们就能在 Data 面板中添加这个新了
Bloom
这个为了方便直接复制Unity自带的Bloom 。地址:/com.unity.-.///Bloom.
使用 Graph 制作用于风格化Bloom后的 。创建一个h(Unity 2022以上)
创建 节点,并且修改名称,注意名称,我们需要通过这个名称向传入bloom
使用 Node输 设置为0, 使用作为UV 得到一组排列整齐的圆点格子,创建属性,用于控制格子密度(大小)
再通过一个 Node 这样得到1,0分明的圆点,并创建属性进行圆点占据格子比例大小控制