diff --git a/com.unity.toonshader/Editor/UTS3GUI.cs b/com.unity.toonshader/Editor/UTS3GUI.cs index 8f234b277..45b5cff2c 100644 --- a/com.unity.toonshader/Editor/UTS3GUI.cs +++ b/com.unity.toonshader/Editor/UTS3GUI.cs @@ -995,7 +995,7 @@ void OnOpenGUI(Material material, MaterialEditor materialEditor, MaterialPropert m_MaterialScopeList.RegisterHeaderScope(Styles.emissionFoldout, Expandable.Emission, GUI_Emissive, (uint)UTS_Mode.ThreeColorToon, (uint)UTS_TransparentMode.Off, isTessellation: 0); m_MaterialScopeList.RegisterHeaderScope(Styles.outlineFoldout, Expandable.Outline, GUI_Outline, (uint)UTS_Mode.ThreeColorToon, - (uint)UTS_TransparentMode.On, isTessellation: 0); + (uint)UTS_TransparentMode.Off, isTessellation: 0); m_MaterialScopeList.RegisterHeaderScope(Styles.tessellationFoldout, Expandable.TessellationLegacy, GUI_Tessellation, (uint)UTS_Mode.ThreeColorToon, (uint)UTS_TransparentMode.Off, isTessellation: 1); diff --git a/com.unity.toonshader/Runtime/Shaders/URP/UniversalToonOutline.hlsl b/com.unity.toonshader/Runtime/Shaders/URP/UniversalToonOutline.hlsl index fbad86367..39afa1032 100644 --- a/com.unity.toonshader/Runtime/Shaders/URP/UniversalToonOutline.hlsl +++ b/com.unity.toonshader/Runtime/Shaders/URP/UniversalToonOutline.hlsl @@ -42,7 +42,9 @@ VertexOutput vert(VertexInput v) { //end float Set_Outline_Width = (_Outline_Width * 0.001 * smoothstep(_Farthest_Distance, _Nearest_Distance, distance(objPos.rgb, _WorldSpaceCameraPos)) * _Outline_Sampler_var.rgb).r; +#ifndef _UTS_OUTLINE_FORCE_VISIBLE Set_Outline_Width *= (1.0f - _ZOverDrawMode); +#endif //v.2.0.7.5 float4 _ClipCameraPos = mul(UNITY_MATRIX_VP, float4(_WorldSpaceCameraPos.xyz, 1)); //v.2.0.7 @@ -70,10 +72,12 @@ VertexOutput vert(VertexInput v) { float4 frag(VertexOutput i) : SV_Target { //v.2.0.5 +#ifndef _UTS_OUTLINE_FORCE_VISIBLE if (_ZOverDrawMode > 0.99f) { return float4(1.0f, 1.0f, 1.0f, 1.0f); // but nothing should be drawn except Z value as colormask is set to 0 } +#endif _Color = _BaseColor; float4 objPos = mul(GetObjectToWorldMatrix(), float4(0, 0, 0, 1)); //v.2.0.9 diff --git a/com.unity.toonshader/Runtime/Shaders/UnityToon.shader b/com.unity.toonshader/Runtime/Shaders/UnityToon.shader index f24d03dcb..ff62f3a9b 100644 --- a/com.unity.toonshader/Runtime/Shaders/UnityToon.shader +++ b/com.unity.toonshader/Runtime/Shaders/UnityToon.shader @@ -1210,6 +1210,60 @@ Shader "Toon/Toon" { ENDHLSL } + // EXPERIMENT: visible outline for transparent materials. Drawn via the + // UniversalForwardOnly tag (URP transparent tag index 2) so it renders AFTER the + // body (UniversalForward, index 1), while the SRPDefaultUnlit "Outline" pass above + // stays as the transparency depth pre-pass (index 0). Uses hardcoded render state + // and _UTS_OUTLINE_FORCE_VISIBLE so it ignores the _ZOverDrawMode width collapse. + Pass { + Name "OutlineTransparent" + Tags { + "LightMode" = "UniversalForwardOnly" + } + Cull Front + ColorMask 15 + ZWrite Off + Blend SrcAlpha OneMinusSrcAlpha + Stencil + { + Ref[_StencilNo] + Comp[_StencilComp] + Pass[_StencilOpPass] + Fail[_StencilOpFail] + + } + + HLSLPROGRAM + #pragma target 2.0 + #pragma vertex vert + #pragma fragment frag + + #define _UTS_OUTLINE_FORCE_VISIBLE + + //V.2.0.4 + #pragma multi_compile _IS_OUTLINE_CLIPPING_NO _IS_OUTLINE_CLIPPING_YES + #pragma multi_compile _OUTLINE_NML _OUTLINE_POS + // Outline is implemented in UniversalToonOutline.hlsl. + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + + //-------------------------------------- + // GPU Instancing + #pragma multi_compile_instancing + #if UNITY_VERSION >= 202230 // Requires Universal RP 14.0.7 + #include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl" + #else + #pragma multi_compile _ DOTS_INSTANCING_ON + #endif + +#ifdef UNIVERSAL_PIPELINE_CORE_INCLUDED + #include "URP/UniversalToonInput.hlsl" + #include "URP/UniversalToonHead.hlsl" + #include "URP/UniversalToonOutline.hlsl" +#endif + ENDHLSL + } + Pass { Name "Universal2D"