Enhanced Outline Material

Step 0.

You can see how to make a outline material and an unsolved problem on the previous post(Can't see outline behind a outlined object).

More detail : Draw outline

Step 1.

 - Find file from Unreal Engine 4 source code(UE4 version 4.14) : Engine\Source\Runtime\Renderer\Private\CustomDepthRendering.cpp

 - Remark SetDepthStencilState Operation and add new stencil buffer operation code. This code is a little bad to avoid 'expression must have a constant value' error. But you can make it better...
/// Original.
//RHICmdList.SetDepthStencilState(TStaticDepthStencilState<true, CF_DepthNearOrEqual, true, CF_Always, SO_Keep, SO_Keep, SO_Replace>::GetRHI(), CustomDepthStencilValue);

/// GameEngineBread : Outline
switch( CustomDepthStencilValue )
{
 case 1:
  RHICmdList.SetDepthStencilState( TStaticDepthStencilState<true, CF_Always, true, CF_Always, SO_Keep, SO_Replace, SO_Replace,
             false, CF_Always, SO_Keep, SO_Keep, SO_Keep, 0x01, 0x01 >::GetRHI(), 0xFF );
  break;

 case 2:
  RHICmdList.SetDepthStencilState( TStaticDepthStencilState<true, CF_Always, true, CF_Always, SO_Keep, SO_Replace, SO_Replace,
             false, CF_Always, SO_Keep, SO_Keep, SO_Keep, 0x02, 0x02 >::GetRHI(), 0xFF );
  break;

  // ...
}

 - Build and restart editor.

Step 2.

Now, new stencil buffer is working like below.








Step 3.

In this time, Bit Operation is not allowed in material blueprint. You have to find a way to do it instead.




Comments

Popular posts from this blog

Liquid material in a bottle

How to Make Circular Progress Bar(or Rounded Rectangle)

MatCap material