Author Topic: Help with Highest Quality + Depth Clip  (Read 86 times)

robatato

  • Newbie
  • *
  • Posts: 5
    • View Profile
Help with Highest Quality + Depth Clip
« on: April 04, 2021, 01:08:34 AM »
Hi there! First off, wonderful asset. Thank you for developing it!

So the issue I am having is that I want to use the built-in render pipeline along with the highest quality outline (am only using outline, no other effects applied). But since I am also using MSAA, the outline is being forced to Always On Top. The message says to enable Depth Clip to fix it, which then allows me to set the Visibility to Normal, which I have done. However, this does not seem to stop the outline from being "Always On Top" and it is still showing through. I looked at the documentation but after reading through the part about Depth Clip, I am still lost and have even more questions like what is the special__CameraDepthTexture buffer? I don't think I need to worry about transparent objects in my scene so I'm not too concerned with that aspect (yet). I am just struggling to figure out how to make the highest quality outline work on Normal visibility (if possible!).

Thanks!  ;D

robatato

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Help with Highest Quality + Depth Clip
« Reply #1 on: April 04, 2021, 02:28:31 AM »
Hey so I actually figured out how to get it to work! Turns out I did need to worry about transparent shaders because my character uses a fading system I built when the camera gets too close.

That said, onto the next issue! I am seeing that my outer glow (not outline, I had it mixed up previously) is now aligning to the contour of my character rather than being simply occluded. Is there some way for me to disable the contouring in favor of basic occlusion?

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 6851
    • View Profile
Re: Help with Highest Quality + Depth Clip
« Reply #2 on: April 04, 2021, 08:24:25 AM »
Hello!

When MSAA is enabled, the Depth Clip option needs to be used in order to occlude the outline and outer glow effects. This occlusion can only work with other opaque objects.
Note that in SceneView, MSAA is always enabled - in this case, just pay attention to the GameView.

I've just tested using latest Unity version just in case and it still works as expected:
- When MSAA is off on the Camera or Quality Settings, the occlusion works naturally, no need to use Depth Clip option. In SceneView, the effects show through other objects because in this window the internal SceneCam uses MSAA.
- When MSAA is on, the Depth Clip must be enabled so both outline and outer glow in Highest Quality mode get occluded by other objects (ie. walls). Doing so makes the effect occluded fine both in SceneView and GameView.

Regards



robatato

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Help with Highest Quality + Depth Clip
« Reply #3 on: April 05, 2021, 04:38:56 PM »
Thanks for the help! So I've actually run into a different issue that has to do with the "Make Transparent Object Compatible With Depth Clipping" functionality.

This appears to work for GameObjects with a Skinned Mesh Renderer that have only 1 Material (so long as I re-assign the material to overwrite the "(instance)" version via script after hitting play).

However this does not work for GameObjects with a Skinned Mesh Renderer that have more than 1 Material. In my case I have 4 (see attached).

Do you have any possible solutions for how to achieve the expected functionality?

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 6851
    • View Profile
Re: Help with Highest Quality + Depth Clip
« Reply #4 on: April 05, 2021, 06:34:13 PM »
Could you please send the character with the Highlight Effect and your settings attached?

robatato

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Help with Highest Quality + Depth Clip
« Reply #5 on: April 06, 2021, 09:43:07 AM »
Hey so I was finally able to sort this out by adding some new shader code to my character. Please see below:

Code
	SubShader
{
Tags {"Queue" = "AlphaTest" "IgnoreProjector" = "True" "RenderType" = "Transparent"}

Pass
{
Name "ShadowCaster"
Tags { "LightMode" = "ShadowCaster" }

CGPROGRAM
#pragma exclude_renderers gles
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#pragma multi_compile_shadowcaster
#include "ShadowCastCG.cginc"


v2f vert(appdata_full v)
{
v2f o;
TRANSFER_SHADOW_CASTER(o)

return o;
}

float4 frag(v2f i) : COLOR
{
fixed4 texcol = tex2D(_MainTex, i.uv);
clip(texcol.a - _Cutoff);
SHADOW_CASTER_FRAGMENT(i)
}
ENDCG
}
}

Also this uses another file ShadowCastCG.cginc, code below:
Code
#include "UnityCG.cginc"
 
float4 _Color;
sampler2D _MainTex;
fixed _Cutoff;
 
 
struct v2f {
V2F_SHADOW_CASTER;
float2 uv : TEXCOORD1;
};

I placed this subshader above the existing subshader in my character's shader and now everything works as expected. I believe the issue was that on objects with multiple materials, the order of those materials cannot be changed so when the "HighlightPlusDepthClipComp" material gets Inserted at index 0 and moves the other materials down, the renderer gets all messed up and the textures are assigned to the wrong parts of the mesh. There was seemingly no way around this other than directly editing the shader on my character to do what I needed it to do with regard to the ShadowCaster that was being implemented by "HighlightPlusDepthClipComp" so the above subshader handles that while also accounting for the model's existing transparency requirement.

This was slightly adapted from this shader I found here.

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 6851
    • View Profile
Re: Help with Highest Quality + Depth Clip
« Reply #6 on: April 06, 2021, 10:59:06 AM »
Nice. Glad to see you sorted it.

robatato

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Help with Highest Quality + Depth Clip
« Reply #7 on: April 08, 2021, 06:58:32 AM »
Ok, last question!

Code
Tiled GPU perf. warning: RenderTexture color surface (682x512) was not cleared/discarded. See TiledGPUPerformanceWarning.ColorSurface label in Profiler for info
UnityEngine.Graphics:ExecuteCommandBuffer(CommandBuffer)
HighlightPlus.HighlightEffect:ComposeSmoothBlend(Visibility, Visibility) (at Assets/HighlightPlus/Scripts/HighlightEffect.cs:1420)
HighlightPlus.HighlightEffect:DoOnRenderObject(Camera) (at Assets/HighlightPlus/Scripts/HighlightEffect.cs:1190)
HighlightPlus.HighlightEffect:OnRenderObject() (at Assets/HighlightPlus/Scripts/HighlightEffect.cs:553)

I am getting this warning in play mode. Any ideas?