vrm-c / UniVRM

UniVRM is a gltf-based VRM format implementation for Unity. English is here https://vrm.dev/en/ . 日本語 はこちら https://vrm.dev/
https://vrm.dev/en
MIT License
2.66k stars 427 forks source link

[URP] MToon10 Outline #2265

Closed HongDeveloper closed 3 months ago

HongDeveloper commented 8 months ago
image Screenshot 2024-03-18 at 18 46 03 image

Describe the bug

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

sack-kazu commented 5 months ago

Maybe adding "MToonOutlineRenderFeature" Render Feature will help! image

kaioduarte commented 4 months ago

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

kaioduarte commented 4 months ago

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
}
WilsonCWong commented 3 months ago

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

kaioduarte commented 3 months ago

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

Kwajik commented 3 months ago

Thx 👍