UniVRM icon indicating copy to clipboard operation
UniVRM copied to clipboard

[URP] MToon10 Outline

Open HongDeveloper opened this issue 1 year ago • 1 comments

image Screenshot 2024-03-18 at 18 46 03 image

  • UniVRM version: v.0.12.0
  • Unity version: Unity-2021.3
  • OS: Mac, Window

Describe the bug

Hi. I have a issue Adjusting the outline value doesn't change. It's not even visible Package is recent release.

HongDeveloper avatar Mar 18 '24 09:03 HongDeveloper

Maybe adding "MToonOutlineRenderFeature" Render Feature will help! image

sack-kazu avatar Jun 11 '24 02:06 sack-kazu

Adding the outline render feature doesn't make a difference to me 🤷🏻

kaioduarte avatar Jul 17 '24 08:07 kaioduarte

I managed to get the outline working on URP by adding this pass to the shader (Assets/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_urp.shader) -- I'm not a shader expert, so it may be inefficient or too hacky :)

EDIT 2: I found a workaround for my case and the glitches went away.

EDIT: there's an issue with this code, there are glitches on the mouth, depending on your use case it may be unnoticeable. image image

// MToon Outline Pass
...

Pass
{
  Name "Outline"
  Cull Front
  Tags { "LightMode" = "SRPDefaultUnlit" }

  HLSLPROGRAM
  #pragma vertex vert
  #pragma fragment frag
  #pragma multi_compile_fog

  #define MTOON_URP

  #include "./vrmc_materials_mtoon_render_pipeline.hlsl"
  #include "./vrmc_materials_mtoon_input.hlsl"

  struct appdata
  {
    float4 vertex  : POSITION;
    float3 normal  : NORMAL;
    float2 uv      : TEXCOORD0;
  };

  struct v2f
  {
    float4 pos      : SV_POSITION;
    half2 uv        : TEXCOORD1;
  };

  v2f vert(appdata v)
  {
    v2f output;

    float _Offset_Z = 0.04;
    float4 _ClipCameraPos = mul(UNITY_MATRIX_VP, float4(_WorldSpaceCameraPos.xyz, 1));

    #if defined(UNITY_REVERSED_Z)
      _Offset_Z *= -1;
    #endif

    output.pos = MToon_TransformObjectToHClip(float4(v.vertex.xyz + v.normal * _OutlineWidth * 0.1, 1));
    output.pos.z += _Offset_Z * _ClipCameraPos.z;
    output.uv = v.uv;

    return output;
  }

  float4 frag(v2f i) : SV_Target
  {
    half4 texColor = MTOON_SAMPLE_TEXTURE2D(_MainTex, i.uv);

    if (texColor.a <= _Cutoff) {
      discard;
    }

    return _OutlineColor;
  }

  ENDHLSL
}

kaioduarte avatar Jul 17 '24 14:07 kaioduarte

Turn off 'Depth Priming Mode' in your renderer, Unity's toon shader has a similar issue with their outlines: https://docs.unity3d.com/Packages/[email protected]/manual/Known-issue.html#when-using-universal-render-pipeline

WilsonCWong avatar Aug 07 '24 08:08 WilsonCWong

That option was already disabled for me and it didn't help.

kaioduarte avatar Aug 07 '24 09:08 kaioduarte

Thx 👍

NewMassMedia avatar Aug 26 '24 02:08 NewMassMedia