Unity屏幕灰化效果
发表于2020-04-30
1. 屏幕灰化效果简述
一般由于政策特殊日期等因素,或者游戏内角色死亡效果要求等等,我们会想看到一个整体灰色的效果。具体表现测试效果:
![hgathQXX0BmIq3wLy794.png](https://tigimg-1252093452.image.myqcloud.com/2020/04/30/hgathQXX0BmIq3wLy794.png)
2. 需要了解
Unity后处理OnRenderImage
https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnRenderImage.html
Graphics.Blit
https://docs.unity3d.com/ScriptReference/Graphics.Blit.html
Copies source texture into destination render texture with a shader.
在后处理中调Graphics.Blit传入一个改变颜色饱和度的shader,即可实现想要的灰色效果。
3. 具体shader
![DpfyARrIvum60jtr2HcM.png](https://tigimg-1252093452.image.myqcloud.com/2020/04/30/DpfyARrIvum60jtr2HcM.png)
4. C#脚本
变量
![8PlFjfw7lShKS1sB95Bm.png](https://tigimg-1252093452.image.myqcloud.com/2020/04/30/8PlFjfw7lShKS1sB95Bm.png)
兼容判断(不支持的话会造成卡帧等等)
![SHOhTnW3TwBfdcDc85Kp.png](https://tigimg-1252093452.image.myqcloud.com/2020/04/30/SHOhTnW3TwBfdcDc85Kp.png)
可动态调整灰度值,看后处理渲染出的灰色效果
![ioEdaj1Lc1ZIEwHly41Z.png](https://tigimg-1252093452.image.myqcloud.com/2020/04/30/ioEdaj1Lc1ZIEwHly41Z.png)
脚本挂在相机上即可。
![W90Yj5zdqsPVxQKARwgG.png](https://tigimg-1252093452.image.myqcloud.com/2020/04/30/W90Yj5zdqsPVxQKARwgG.png)