Posted on September 14, 2014 by Tom

Unreal Engine 4 introduced a new depth buffer along with their PBR rendering system. It’s called “Custom Depth” and can be used for effects like the selection outline that is built-in the Editor, rendering of occluded meshes or custom culling of transparency. I will discuss some of the basics of using this buffer in the material editor and explain some of the features I used it for in my own projects.

Contents [hide]

  • 1 Custom Depth 101
  • 2 Rendering Object Outlines
  • 3 Culling Inner Triangles
  • 4 Other Uses
  • 5 Multi-Color Outline Effect
  • 6 Issues & Limitations
  • 7 References

When using the techniques described for your own effect that utilize Custom Depth it’s important to read through the Issues & Limitations at the bottom of the page to prevent you hours of headache and unnecessary debugging.

Custom Depth 101

For those who have never used this feature before, you can enable it for both Static and Skeletal meshes under the Rendering category named “Render Custom Depth”.

To view this particular buffer go to Buffer Visualization in the viewport-options.

Note that objects close to the camera are near-black and may be difficult to see!

Rendering Object Outlines

To render outlines around specific meshes (like a fallen ally, usable loot container etc.) we need a buffer to get their silhouettes. Custom Depth is perfect for this.

With the buffer filled with our object depth info we can perform a simple depth comparison by sampling the neighboring pixels in our post process. If a neighbor has depth info but the pixel itself does not – we color it to our outline color.

We can use another technique for drawing a translucent overlay for all occluded geometry by comparing custom depth against SceneDepth. If CustomDepth is larger than SceneDepth we blend in a white tint with SceneColor.

Combining both techniques results in the post effect below:

I skipped most of the implementation details – if you have any questions feel free to ask them in the comment section below! I’ve made this effect available for download, feel free to modify and use this in your game.

Outline Post Process [Download]

Post Process material for outlines with translucent veil on occluded pixels.

After copying the .uasset files into the Content folder of your project you must add a Post Process Volume into your scene and enable the Unbound property, also don’t forget to add the post effect material under Blendables.

Download Now!10581 Downloads

Culling Inner Triangles

When using transparency on models like character that have inner triangles (eyes, mouth, arm or bit of armor sticking through) you will see a noticable highlight in your material that attracts attention and simply doesnt look right. We can solve this issue using Custom Depth.

By rendering our character into the Custom Depth buffer we can cull any pixels that are behind the outter shell of the mesh. A slight depth offset should be added when comparing depth of Scene and Custom to prevent too many pixels to be culled including the outer shell. The material setup for this is quite simple:

Material Nodes – Copy this url’s content and you can directly paste the above nodes into your own material. (Project Source is available on GitHub)

I made a comparison of depth culling enabled and disabled in the setup below. The character on the right displays all occluded pixels in red. I rendered each character TWICE to work around a limitation where transparent materials do not render into custom depth at all (this is normal behavior for SceneDepth, but undesirable when explicitly enabling Custom Depth on a mesh with transparency applied) You can download the project source to see exactly how this was done.

For Switch we use this culling technique on a stealth effect giving it a more consistent ‘shell’ and highlight on a mesh that has a lot of overlapping pixels.

It’s important to know that if multiple materials use this technique that only the object closest to camera is culled correctly. In this image you can see the errors can would occur if you have multiple meshes overlapping. This should be taken into consideration when considering this technique – it may never be an issue if you use this effect sparingly or consistent isolated scenarios.

This issue can possibly be solved by adding a max depth delta when culling. I have had no need to dive into this further, but may come back to this in the future when it starts to cause practical issues.

Other Uses

For our game Switch we are using Custom Depth for a number of features, one of them includes an x-ray material that exposes players behind a wall – I added a short video of an early proof of concept below.

Multi-Color Outline Effect

A few engine versions ago Stencil Index buffer was added alongside Custom Depth. This enables us to create multi-colored outline effects among many other cool effects! Click here to read about this new effect, included with a download link for the material.

Issues & Limitations

  • Custom Depth does not work on translucent materials. In that case you need a second copy of the mesh using a simple opaque material with Custom Depth enabled and Render Main pass disabled. View on AnswerHub
  • Because the buffer is filled with all objects using Custom Depth it will not work when having multiple overlapped meshes (one behind the other) depending on how you’re using the depth value – a transparent mesh might be entirely culled if you use custom depth to cull inner triangles. A possible workaround is to add a maximum depth difference when looking for inner triangles to reduce the errors.

References

  • Source files on GitHub
  • Multi-color Outline Effect
Posted on September 14, 2014 by Tom

Unreal Engine 4 introduced a new depth buffer along with their PBR rendering system. It’s called “Custom Depth” and can be used for effects like the selection outline that is built-in the Editor, rendering of occluded meshes or custom culling of transparency. I will discuss some of the basics of using this buffer in the material editor and explain some of the features I used it for in my own projects.

Contents [hide]

  • 1 Custom Depth 101
  • 2 Rendering Object Outlines
  • 3 Culling Inner Triangles
  • 4 Other Uses
  • 5 Multi-Color Outline Effect
  • 6 Issues & Limitations
  • 7 References

When using the techniques described for your own effect that utilize Custom Depth it’s important to read through the Issues & Limitations at the bottom of the page to prevent you hours of headache and unnecessary debugging.

Custom Depth 101

For those who have never used this feature before, you can enable it for both Static and Skeletal meshes under the Rendering category named “Render Custom Depth”.

To view this particular buffer go to Buffer Visualization in the viewport-options.

Note that objects close to the camera are near-black and may be difficult to see!

Rendering Object Outlines

To render outlines around specific meshes (like a fallen ally, usable loot container etc.) we need a buffer to get their silhouettes. Custom Depth is perfect for this.

With the buffer filled with our object depth info we can perform a simple depth comparison by sampling the neighboring pixels in our post process. If a neighbor has depth info but the pixel itself does not – we color it to our outline color.

We can use another technique for drawing a translucent overlay for all occluded geometry by comparing custom depth against SceneDepth. If CustomDepth is larger than SceneDepth we blend in a white tint with SceneColor.

Combining both techniques results in the post effect below:

I skipped most of the implementation details – if you have any questions feel free to ask them in the comment section below! I’ve made this effect available for download, feel free to modify and use this in your game.

Outline Post Process [Download]

Post Process material for outlines with translucent veil on occluded pixels.

After copying the .uasset files into the Content folder of your project you must add a Post Process Volume into your scene and enable the Unbound property, also don’t forget to add the post effect material under Blendables.

Download Now!10581 Downloads

Culling Inner Triangles

When using transparency on models like character that have inner triangles (eyes, mouth, arm or bit of armor sticking through) you will see a noticable highlight in your material that attracts attention and simply doesnt look right. We can solve this issue using Custom Depth.

By rendering our character into the Custom Depth buffer we can cull any pixels that are behind the outter shell of the mesh. A slight depth offset should be added when comparing depth of Scene and Custom to prevent too many pixels to be culled including the outer shell. The material setup for this is quite simple:

Material Nodes – Copy this url’s content and you can directly paste the above nodes into your own material. (Project Source is available on GitHub)

I made a comparison of depth culling enabled and disabled in the setup below. The character on the right displays all occluded pixels in red. I rendered each character TWICE to work around a limitation where transparent materials do not render into custom depth at all (this is normal behavior for SceneDepth, but undesirable when explicitly enabling Custom Depth on a mesh with transparency applied) You can download the project source to see exactly how this was done.

For Switch we use this culling technique on a stealth effect giving it a more consistent ‘shell’ and highlight on a mesh that has a lot of overlapping pixels.

It’s important to know that if multiple materials use this technique that only the object closest to camera is culled correctly. In this image you can see the errors can would occur if you have multiple meshes overlapping. This should be taken into consideration when considering this technique – it may never be an issue if you use this effect sparingly or consistent isolated scenarios.

This issue can possibly be solved by adding a max depth delta when culling. I have had no need to dive into this further, but may come back to this in the future when it starts to cause practical issues.

Other Uses

For our game Switch we are using Custom Depth for a number of features, one of them includes an x-ray material that exposes players behind a wall – I added a short video of an early proof of concept below.

Multi-Color Outline Effect

A few engine versions ago Stencil Index buffer was added alongside Custom Depth. This enables us to create multi-colored outline effects among many other cool effects! Click here to read about this new effect, included with a download link for the material.

Issues & Limitations

  • Custom Depth does not work on translucent materials. In that case you need a second copy of the mesh using a simple opaque material with Custom Depth enabled and Render Main pass disabled. View on AnswerHub
  • Because the buffer is filled with all objects using Custom Depth it will not work when having multiple overlapped meshes (one behind the other) depending on how you’re using the depth value – a transparent mesh might be entirely culled if you use custom depth to cull inner triangles. A possible workaround is to add a maximum depth difference when looking for inner triangles to reduce the errors.

References

  • Source files on GitHub
  • Multi-color Outline Effect

Custom Depth in Unreal Engine 4相关推荐

  1. Unreal Engine 4 —— Pixel Depth Offset的使用心得

    http://blog.csdn.net/noahzuo/article/details/51361789 这篇博客解释了Unreal Engine 4中的Pixel Depth Offset通道的使 ...

  2. Unreal Engine 4 使用HLSL自定义着色器(Custom Shaders)教程(下)

    本文是<Unreal Engine 4 自定义着色器(Custom Shaders)教程>的下半部分,上半部分请见<Unreal Engine 4 自定义着色器(Custom Sha ...

  3. UNREAL ENGINE 4.13 正式发布!

    这次的版本带来了数百个虚幻引擎 4 的更新,包括来自 GitHub 的社区成员们提交的 145 个改进!感谢所有为虚幻引擎 4 添砖加瓦贡献的人们: alk3ovation, Allegorithmi ...

  4. Unreal Engine 4 渲染目标(Render Target)教程 之 实现雪地足迹(上)

    原文|<Unreal Engine 4 Tutorial: Creating Snow Trails in Unreal Engine 4> 作者|Tommy Tran Jun 3 201 ...

  5. UNREAL ENGINE 4.12 正式发布!下载地址

    UNREAL ENGINE 4.12 正式发布! 下载地址:https://www.unrealengine.com/ Alexander Paschall 在 June 1, 2016 |功能新闻社 ...

  6. matlab如何打开dcm_MATLAB结合Unreal Engine构建用以自动驾驶仿真测试的逼真驾驶场景...

    之前的文章<MATLAB/Simulink自动驾驶工具箱之Driving Scenario Designer>提到了MathWorks自己开发的场景构建工具Driving Scenario ...

  7. Unreal Engine 4 卡通着色(Cel Shading)教程

    原文|<Unreal Engine 4 Cel Shading Tutorial> 作者|Tommy Tran Feb 27 2018 阅读时长|20分钟 内容难度|中等 文章目录 开始吧 ...

  8. matlab您的安装可能需要执行其他配置步骤_手把手超详细介绍MATLAB+RoadRunner+Unreal Engine自动驾驶联合仿真...

    RoadRuner是MathWorks新收购的自动驾驶场景构建工具,Unreal Engine是商业游戏引擎.RoadRunner创建驾驶场景,导入到Unreal Engine,与Simulink联合 ...

  9. How Unreal Engine 4 Will Change The Next Games You Play

    How Unreal Engine 4 Will Change The Next Games You Play[纯搬运] How Unreal Engine 4 Will Change The Nex ...

最新文章

  1. Ubuntu 18.04 Authentication Error
  2. vue + element ui 的后台管理系统框架_从零开始搭建 VUE + Element UI后台管理系统框架...
  3. windows的键盘输入重定向
  4. Linux之解析鼠标input事件数据
  5. dojo.publish 和 dojo.subscribe
  6. matlab实现图像放大两倍,matlab图像处理基础知识0(双线性插值matlab实现--调整水平和垂直放大倍数)...
  7. Lync Server 2010标准版系列PART3:证书准备
  8. 利用for循环打印出不同的三角形
  9. HTML 5 画布
  10. LINQ系列:Linq to Object集合操作符
  11. android studio mac svn插件,Mac下Android Studio升级SVN1.8(使用1.8format来checkout项目)
  12. Allegro给一个网络赋默认值,取消默认值
  13. RS485通讯接口定义图详解
  14. CAN报错BUSLIGHT,BUSHEVAY,BUSOFF什么意思
  15. 河南初中计算机考试2028,沾沾喜气!河南28名考生被清北提前录取,竟有27人来自一所中学...
  16. 初识instantRun
  17. 21天学习挑战赛之Java网络编程(二)
  18. three.js中坐标系转换以及camera的position、lookAt与up属性理解
  19. ComicEnhancerPro 系列教程十八:JPG文件长度与质量
  20. GitHub下载加速网站

热门文章

  1. python3.7.3配置环境变量_配置环境变量切换到python3.7
  2. 匿名内部类 可以访问外部类_Java——内部类详解
  3. antlr 可以用java写吗_java – 我们可以用ANTLR定义一个非上下文语法吗?
  4. iar环境下c语言编程,c语言_源代码-iar环境配置.pdf
  5. 微信小程序下拉框插件_微信小程序自定义select下拉选项框组件的实现代码_清玖_前端开发者...
  6. aspose条件格式无法读取_分析 Pandas 源码,解决读取 Excel 报错问题
  7. 前端学java还是python_零基础应该选择学习 java、php、前端 还是 python?
  8. linux so获取自己路径,linux下so获得自己文件位置的路径
  9. ssm实现管理员和用户_基于SSM的网上水果生鲜超市商城管理系统
  10. python自动调整格式_pycharm使用技巧之自动调整代码格式总结