Adding Occlusion to Multicolor Soft Outline - Part II



This is second of two part tutorial. You can find first part here.

In first part of the tutorial we showed how to edit Custom Stencil buffer and send it forward to be processed via alpha channel. Today we will be adjusting Multicolor Soft Outline from here to make use of this information.

Idea

All we need to do is change the instances of SceneTexture using Stencil buffer to using alpha channel of PostProcessInput0. At the same time we need to adjust blur Custom node to blur the edited stencil data, instead of the Custom Depth.

Setup 

We will  be using material PP_OutlineColored from previous tutorial. First change the setting of the material, as follows:


This will set the priority of the material to be smaller than that of the PP_OcclusionCheck from the first material, meaning it will be executed after PP_OcclusionsCheck.

Edits

We pretty much only need to change some of the occurrences of the Stencil buffer, specifically those in the highlighted parts.


In 1) don't forget to also change Component Mask to A channel instead of R. We also need to edit input of the blurring function that we created.


Instead of using Custom Depth in SceneTexture change it to PostProcessInput0 and use following code:

 float2 nUV = UV;
 int i=0;
 float StepSize = Detail / (int) DetailIterations;
 float CurDetail=0;
 float2 CurOffset=0;
 float3 CurColor=0;
 float SubOffset = 0;
 float TwoPi = 6.283185;
 float accumdist=0;
 int TexIndex = 14;

 if (DetailIterations < 1)
 {
   return SceneTextureLookup(nUV, TexIndex, false).w;
 }
 else
 {
   while (i < (int) DetailIterations)
   {
     CurDetail += StepSize;
     for (int j = 0; j < (int) RadialSteps; j++)
     {
       SubOffset +=1;
       CurOffset.x = cos(TwoPi*(SubOffset / RadialSteps));
       CurOffset.y = sin(TwoPi*(SubOffset / RadialSteps));
       nUV.x = UV.x + CurOffset.x * CurDetail;
       nUV.y = UV.y + CurOffset.y * CurDetail;
       float distpow = pow(CurDetail, KernelPower);
       float txt = SceneTextureLookup(nUV, TexIndex, false).w;
       CurColor += ceil(txt)*distpow; 
       accumdist += distpow;
     }
     SubOffset +=RadialOffset;
     i++;
   }
   CurColor = CurColor;
   CurColor /=accumdist;
   return CurColor.x;
 }

Part highlighted in red are those that changed when comparing to previous version of the Blurring node.

And that's all, everything should be working now!

Results

The results you may get should look something like this.


Issue

- Due to blurring used the effect can become performance heavy if number of iteration is chosen to be too high, plus side, it doesn't depend on number of outlines present in the scene
- Blurring can be adjusted to not compute blur where unnecessary, this will improve performance immensely
- All the previous issues from the original tutorial (some of them being relatively easy to fix :) )

Comments

Popular Posts