maz*_*zin 4 blur unity-game-engine
图片来自这个网站:
https://forum.unity.com/threads/how-to-blur-specific-layers-only.555520/
我尝试了后处理配置文件并在后处理体积中使用了景深,但它模糊了所有场景。
我遇到了一个YouTube 视频,它解释了如何实现与我正在寻找的类似的结果,但设置中的情况发生了巨大变化。例如,在 1:57(分 57 秒),他点击了Add Additional Camera Data
我在最新版本的 LWRP 中很难找到的内容。
我使用的是 Unity 版本 2019.2.9f1
我怎样才能达到上图中的结果?(模糊除一个物体外的所有场景)
您的指导将不胜感激。
注意:我的项目是在 VR 中使用 SteamVR 和 VRTK
der*_*ugo 14
虽然你的问题有点宽泛,但我花了一些时间向你展示如何做到这一点。
首先,您需要Post Processing
通过PackageManager导入包
Window → PackageManager
确保在All Packages
视图中,搜索post
,找到Post Processing
包并点击Install
现在首先转到图层设置(Layers→ Edit Layers)
并添加两个额外的图层:例如PostProcessing
和Focused
现在到相机。Afaik 无论你是否在 VR 中都没有区别,通常你有一个MainCamera
与你的耳机一起移动的。如果您的项目设置中应该有两个,只需对第二个相机重复相同的步骤。
MainCamera
不会渲染两个添加的图层 → 从Culling Mask
将一个新的 CameraFocusCamera
作为子项添加到现有的MainCamera
. 这样,它会自动与主相机一起移动。
RightClick on MainCamera
&右箭头 Camera
它应该具有与MainCamera
except相同的所有设置:
Clear Flags
:Don't ClearDepth Only
聚焦对象将始终呈现在所有内容之上,即使它实际上位于 3D 空间中的其他对象之后。你决定你想要的效果在这里;)CullingMask
:只有 FocusedDepth
: 任何高于 的东西,MainCamera
所以这个相机会在它上面渲染AudioListener
组件。最后添加一个新PostProcessingVolume
的场景。我会把它作为孩子添加到FocusCamera
! 为什么?- 因为这样它会自动与FocusCamera
!
RightClick在FocusCamera
→ 3D Object→Post Processing Volume
将其设置Layer
为添加的PostProcessing
启用Is Global
以便与音量的距离无关紧要并通过点击new→ Unity→添加新的配置文件Depth of field
在您的情况下,您想覆盖Focus Distance
因此选中左侧的框并设置一个靠近相机的值,例如0.5
到目前为止,您的场景中没有任何真正改变。
现在转到MainCamera
和,一个组件PostProcessingLayer
并将其设置Layer
为我们添加的图层PostProcessing
现在场景中的一切都应该模糊了!
几乎准备好了!现在禁用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;
}
}
Run Code Online (Sandbox Code Playgroud)
这将允许您通过将某个游戏对象的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);
}
}
Run Code Online (Sandbox Code Playgroud)
这是它的样子
如前所述,我不确切知道您的 VR 设置是什么样的。如果您必须使用 MainCameras,只需向其中添加两个子摄像机即可。您仍然只需要一个 PostProcessingVolume 并且只需要一个,FocusSwitcher
因此您可能会将它们移动到另一个对象并以不同的方式处理相机禁用等,但我希望这个想法足够清晰。
归档时间: |
|
查看次数: |
6230 次 |
最近记录: |