浏览 : 2844

[教程资源] Multi-color Outline Post Process in Unreal Engine 4

Jeffrey2016-12-12 16:25

Multi-colorOutline Post Process in Unreal Engine 4
本文翻译自Tomlooman的文章,全系共有三篇,此为第一篇,没有逐字逐句翻译,只翻译核心方法。有出错的地方请留言指出,有其他英文教程需要翻译的,也可以贴出地址,如果具备普遍性,我会尽快找时间翻译

With some of the recent changes to Unreal Engine 4,rendering multi-color outlines is now possible! This is done through the use ofCustom Stencil, a new buffer similar to Custom Depth – but allowing meshes torender as integer values. This provides us with a 1-255 range of indices thatcan be used to apply different outline colors to meshes and even combinemultiple features such as the decal x-ray shown below by using a differentstencil index.

新版本的ue引擎,已经可以实现渲染多色外轮廓。实现方式是通过建立一个自定义的模板,一个新的缓冲区,类似于自定义深度。通过一个整型变量来控制,取值范围1到255,,对应模型外轮廓的不同颜色。还可以通过不同的模板,组合多种特征达到更多的效果,如下图最后的x光效果。

1.jpg

The OriginalCustom Depth
Theoriginal outline material I made last year was based on Custom Depth, beforeCustom Stencil was available. This meant there was no way to determine the meshtype after it was drawn into the buffer as single channel depthvalue. More info on the effect and other uses for Custom Depth areavailable in my of my earlier posts. The original effect uses fewerinstructions (97 vs. 144 of the new material) so if you don’t require multiplecolors in your game you can consider sticking to the old effect.
The neweffect is still using Custom Depth to determine the (optional) occlusion whichadds the faint overlayed color adjusted by tweaking the FillAlpha parameter in the post process. Thisocclusion can be turned off in the material by unchecking FillOcclusion in the material instance.

原始的自定义深度
我去年做的原始版本外轮廓材质,是基于自定义深度实现的。当时的引擎版本还不支持自定义模板。这意味着,一旦一个mesh作为单通道的深度值写到缓存里,我们就不可能在获取他到底是什么类型的模型。原始的方式,支持的效果是97,新的支持144,所以如果你不需要那么那么多变化的话,你用老的也可以。
新的效果用自定义深度值来判断的叠加颜色的遮罩,通过在postprocess里调fillalpha这个数值,获得不同的叠加颜色。打开和关闭材质里的occlusion,可以控制是不是应用这个遮罩。

2.jpg
Above:the Custom Depth visualizer.
Enabling CustomStencil
CustomStencil is disabled by default, to enable go to Window > Project Settings > Rendering > Post Process >Custom Depth-stencil Pass and set it to Enabled with Stencil.
Some ofthe meshes are not visible in the Custom Stencil visualizer in thisexample, their Stencil value is set to 0 (default), excluding them from thisbuffer.

启用自定义深度模板
默认情况下自定义模板是禁用的,打开的地方是edit >Project Settings > Rendering > Post Process > Custom Depth-stencilPass。找到设置成Enabledwith Stencil.
在这个示例中,某些模型在自定义模板里是不可见的。它们模板值设置为0,被排除在缓冲区之外。

3.jpg
To enablethis visualizer go to your viewport, look for Lit > Buffer Visualizer >Custom Stencil.
You canenable Custom Depth and change the Stencil index through the editormenu of a mesh under the Rendering category.

在窗口中启用这个可视化工具,查找 Lit >Buffer Visualization > Custom Stencil.(新版部分英文名字有改动。以我翻译为准)
激活和改变输入值,在模型的编辑器下面,renderingcategory中,如下图
4.jpg

If you’reusing C++ you can define the stencil indices in your game header (ex.SurvivalGame.h) for your convenience and bookkeeping.
/* Stencil index mapping toPP_OutlineColored */
#define STENCIL_FRIENDLY_OUTLINE 252;
#define STENCIL_NEUTRAL_OUTLINE 253;
#define STENCIL_ENEMY_OUTLINE 254;
#define STENCIL_ITEMHIGHLIGHT 255;

Enablingcustom depth and setting the index in C++ is pretty straightforward.
GetMesh()->SetRenderCustomDepth(true);
GetMesh()->CustomDepthStencilValue =STENCIL_ENEMY_OUTLINE; // or simply assign an int32 within 1-255 range.

Setting up thePost Process
To enablethe outline you need to place a Post Process Volume.Make sure you set it to Unbound so it’savailable regardless whether camera is inside the volume or not. With the postprocess volume selected, go to Settings > Blendables andadd the PPI_OutlineColored as the first entry.

设置后处理体积
要启用外轮廓,你必须放一个后处理体积,一定要确保他被设置为解除绑定,这样才能奏效,不管你的摄像机在不在这个处理体积里。第二,当你选中post processvolume ,然后在他的编辑器下面settings中找到blendables,在第一个array后面新建一个值,然后为期选择PPI_OutlineColored。这样在整个体积中,激活的物体,就都可以看到外边缘的效果了。
PPI文件的下载在本文附件中。

检举 回应