microsoft / microsoft/MixedReality-GraphicsTools-Unity

Solve 'self overlap' with transparent 3D objects

Open
#48 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
C#
Stars
209
Forks
49
PR merge metrics
No merged PRs in 30d

Description

Describe the problem

Usually semitransparent shaders do not write into the depth buffer. However, this can create draw order problems, especially with complex non-convex meshes. If you want to fade in & out meshes like that, then using a shader that fills in the depth buffer before rendering transparency might be useful.

image

Semitransparent object; left: standard Transparent/Diffuse shader; right: shader that writes to depth buffer.

Describe the solution you'd like

Unity recomends a solution like below: https://docs.unity3d.com/2017.2/Documentation/Manual/SL-CullAndDepth.html

Shader "Transparent/Diffuse ZWrite" {
Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}
SubShader {
    Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
    LOD 200

    // extra pass that renders to depth buffer only
    Pass {
        ZWrite On
        ColorMask 0
    }

    // paste in forward rendering passes from Transparent/Diffuse
    UsePass "Transparent/Diffuse/FORWARD"
}
Fallback "Transparent/VertexLit"
}

But! Multi-pass shaders are not supported by URP. There are some alternatives like using the draw objects render pass with light tags. But we'll need to find a solution that works for both URP and built-in pipelines.

Describe alternatives you've considered

n/a

Additional context

Original issue: https://github.com/microsoft/MixedRealityToolkit-Unity/issues/6285

If adding an extra depth pass we need to ensure it's not enabled by default. This API might be able to do that? But it is still unclear.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the linked Unity depth, transparent shader, and SetShaderPassEnabled documentation, then compare the URP and built-in pipeline constraints described in the issue. Done means a transparent non-convex mesh avoids self-overlap in both pipelines, while any extra depth pass remains disabled by default.

Written by the indexing model from the issue text.

Assessment

Tech stack
unity
Domain
computer-graphics
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.