我想创建类似于下图的模糊效果:
图片来自这个网站:
https://forum.unity.com/threads/how-to-blur-specific-layers-only.555520/
我尝试了后处理配置文件并在后处理体积中使用了景深,但它模糊了所有场景。
我遇到了一个 YouTube Video这解释了如何实现与我正在寻找的类似结果,但设置中的情况发生了巨大变化。例如,在 1:57(分 57 秒),他点击了 Add Additional Camera Data
我正在努力在最新版本的 LWRP 中找到它。
我使用的是 Unity 版本 2019.2.9f1
我怎样才能达到上图中的结果? (模糊除一个物体外的所有场景)
您的指导将不胜感激。
注意:我的项目是在 VR 中使用 SteamVR 和 VRTK
最佳答案
虽然你的问题有点宽泛,但我花了一些时间向你展示如何做到这一点。
首先,您需要导入 Post Processing
通过 PackageManager 打包
窗口 → 包管理器
确保在 All Packages
查看、搜索 post
,找到 Post Processing
打包并点击安装
现在首先转到图层设置(图层→编辑图层)
并添加 两个附加层:例如PostProcessing
和 Focused
现在到相机。 Afaik 无论你是否在 VR 中都没有区别,通常你有一个 MainCamera
随耳机一起移动。如果您的项目设置中应该有两个,只需对第二个相机重复相同的步骤。
MainCamera
不渲染添加的两个图层 → 从 Culling Mask
中删除它们FocusCamera
作为现有 MainCamera
的 child .这样,它会自动与主相机一起移动。右键单击
MainCamera
&rightarrow 相机它应该具有等于
MainCamera
的所有设置除了 :Clear Flags
: 不清除如果您将其设置为
Depth Only
聚焦对象将始终呈现在所有对象之上,即使它实际上位于 3D 空间中的其他对象之后。你决定你想要的效果在这里;) CullingMask
:只有专注 Depth
: 任何高于 MainCamera
所以这个相机是在它上面渲染的 AudioListener
成分。 PostProcessingVolume
到现场。我会把它作为 child 添加到 FocusCamera
!为什么? - 因为这样它会与 FocusCamera
一起自动禁用!右键单击
FocusCamera
→ 3D 对象 → 后处理体积设置其
Layer
添加到 PostProcessing
启用
Is Global
所以与体积的距离无关紧要,并通过点击 new → Unity → Depth of field 添加新的配置文件在您的情况下,您想覆盖
Focus Distance
所以选中左边的框并设置一个靠近相机的值,例如0.5
到目前为止,您的场景中没有任何真正改变。
现在转到
MainCamera
和,一个组件 PostProcessingLayer
并设置 Layer
到我们添加的层后处理现在场景中的一切都应该模糊了!
几乎准备好了!现在禁用
FocusCamera
并将此脚本添加到其中using UnityEngine;
public class FocusSwitcher : MonoBehaviour
{
public string FocusedLayer = "Focused";
private GameObject currentlyFocused;
private int previousLayer;
public void SetFocused(GameObject obj)
{
// enables this camera and the postProcessingVolume which is the child
gameObject.SetActive(true);
// if something else was focused before reset it
if (currentlyFocused) currentlyFocused.layer = previousLayer;
// store and focus the new object
currentlyFocused = obj;
if (currentlyFocused)
{
previousLayer = currentlyFocused.layer;
currentlyFocused.layer = LayerMask.NameToLayer(FocusedLayer);
}
else
{
// if no object is focused disable the FocusCamera
// and PostProcessingVolume for not wasting rendering resources
gameObject.SetActive(false);
}
}
// On disable make sure to reset the current object
private void OnDisable()
{
if (currentlyFocused) currentlyFocused.layer =previousLayer;
currentlyFocused = null;
}
}
这将允许您通过将某个游戏对象的层更改为
Focused
来将其集中在运行时。我们添加的图层,唯一由 FocusCamera
渲染的图层.所以这个对象将被渲染在图像之上,没有任何模糊效果!为了演示,我只是将这个简单的脚本添加到每个立方体对象中,以便在鼠标进入时启用焦点并在鼠标退出时禁用它:
using UnityEngine;
public class FocusMe : MonoBehaviour
{
[SerializeField] private FocusSwitcher focus;
private void OnMouseEnter()
{
focus.SetFocused(gameObject);
}
private void OnMouseExit()
{
// reset the focus
// in the future you should maybe check first
// if this object is actually the focused one currently
focus.SetFocused(null);
}
}
这是它的样子
如前所述,我不确切知道您的 VR 设置是什么样的。如果您必须使用 MainCameras,只需向其中添加两个子摄像机即可。您仍然只需要一个 PostProcessingVolume 和一个
FocusSwitcher
所以你可能会将它们移动到另一个对象并以不同的方式处理相机禁用等,但我希望这个想法足够清晰。
关于unity3d - 如何为除一个对象之外的所有场景创建模糊效果(专注于该对象)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59188747/