Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

[Closed] CustomStencil usage in PP material?

Hi there. I'm trying to create a post process material that creates an outline around certain objects. What i need is to have different colors depending on what a mesh is. I've read this in the forums:

There is a new feature in 4.9 that allows Custom Depth with Custom Stencil. It allows another buffer to be accessed called Custom Stencil that allows each static mesh to have a single Byte from 0-255 to be sent to that buffer. This can then be used in the shader to mask props as different colours when being highlighted for example.

Original post can be found here

I wold like to know how this masking is done in the material editor, as i've not been able to find documentation about this. Thanks!

Product Version: UE 4.9
more ▼

asked Sep 06 '15 at 04:53 PM in Rendering

avatar image

1.2k 24 13 29

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

The question has been closed Jun 26 '19 at 03:51 PM by Bariudol for the following reason:

The question is answered, right answer was accepted

3 answers: sort voted first

On a static mesh, you can set "Render Custom Depth" as well as a byte value for the "Custom Depth Stencil Value".

In the post process material, drop a scene texture sample and select "CustomStencil".

You can get a mask for each desired value using the material function "BitMask" by plugging the SceneTexture:CustomStencil to the BitMask input and a constant for each bit you wish you mask for.

You could perform a sobel type post process for each main color. The easiest example to copy is from the "Stylized rendering" example project.

You also need to go into the editor project settings under rendering ->post processing and set the "custom depth stencil pass" setting to Enabled with Stencil. You probably have to restart the editor for it to take effect.

more ▼

answered Sep 06 '15 at 07:24 PM

avatar image

2.1k 56 24 118

avatar image Bariudol Sep 07 '15 at 01:57 AM

Awesome! Thanks a lot!

avatar image Celito Sep 15 '15 at 12:57 AM

Can you show a screenshot of the connections in the material using that BitMask to select different colors? I can't seem to figure it out how to use the SceneTexture: CustomStencil to select them.

avatar image Bariudol Sep 24 '15 at 09:51 PM

Hi Celito this is how you use the bitmask. Sorry for the delayed response, I wasn't able to test this until today. Hope it helps:

alt text

Replace the 255 constant with the number of stencil you want to mask. Cheers!

customstencil.jpg (245.2 kB)
avatar image Celito Sep 28 '15 at 07:57 PM

Thank you very much Bariudol. That helped me a lot.

avatar image Kakushi_52 Oct 17 '15 at 04:02 AM

I couldn't find any result image using Custom Stencil on internet, so I tried it. And I don't think you have to use BitMask node!

alt text alt text alt text alt text

avatar image Stéphane Bourez Jun 30 '16 at 09:20 AM

Brilliant, thanks for that, I was struggling to find out how to do exactly this!

avatar image NraButtons Oct 03 '15 at 01:09 PM

RyanB, is there a way to allow the custom stenciled element to be occluded normally, in the case that we want post processing for a given mesh yet don't want it to render on top of everything else?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

You can use an if node to check if custom depth is greater or less than scene depth. If it is greater, plug a 0, if it is less than or equal plug in a 1 and then use that as your mask.

more ▼

answered Oct 03 '15 at 03:55 PM

avatar image

2.1k 56 24 118

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

I found Its doesnt work in UE4.2,doesnet it?

more ▼

answered Dec 15 '18 at 05:25 AM

avatar image

Gardon Guo

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question