2
\$\begingroup\$

The picture shows an object made out of one model. The object works as intended when rendering with opaque rendering mode, but I want the object to fade in/out during animation. The glitch seems to have something to do with queue of rendering, but since it's only one model, and since there's only one material on the model (tried fresh materials, same problem), it seems to be weird glitch. Any help is appreciated, and if possible, I need to find a solution without using a 3d modelling software.

building with incorrect rendering

Forward rendering is used on the camera.

\$\endgroup\$
1
  • 3
    \$\begingroup\$ Welcome to rendering transparent stuff. It's a b-tch. There is no quick-fix to this, you're either going to have to render it opaque by itself and then render the result transparently, write a custom shader, or find some other method. Because correctly depth-sorting transparent objects is one of the Holy Grails of computing. \$\endgroup\$ Oct 18, 2017 at 18:14

2 Answers 2

3
\$\begingroup\$

Here's a simple fix you can use when rendering a solid object like a building.

We'll copy the building and render it twice in the same location:

  1. Drawing only to the depth buffer, without writing any colour over the background
  2. Drawing translucently, only where our polygons pass the depth test (ie. only the frontmost faces)

You can use a shader like this to "reserve" this object's surface position in the depth buffer after the other opaque geometry has rendered, while leaving the background as-is:

Shader "Unlit/DepthReserve"
{
    Properties
    {
    }
    SubShader
    {
        Tags { "RenderType" = "Opaque" "Queue"="AlphaTest+1" }
        LOD 100

        Blend Zero One

        Pass
        {

        }
    }
}

(Here I'm abusing the blending to just ignore our material and output the background colour. There may be a more efficient way to skip computing a colour to blend at all.)

When we render without this depth-reserving pass, the translucent triangles can get drawn in any random order, so stuff that's behind can render in addition to / on top of stuff that's in front - see the internal structure of the windowsills & wells visible on the left below. When we write the depth buffer first, we block all but the frontmost face at a given pixel from rendering, so we get a result like the one on the right, with a more expected translucent layering effect:

Undesired depth layeringCorrected depth layering

\$\endgroup\$
0
\$\begingroup\$

You can't do much against this. There's a reason you don't see many transparent objects in games.

The triangles get rendered in a basically random order, so this results in basically random colors.

You can kind of fake it by disabling depth write before rendering the object, but it won't be perfect. If you can get a usable result, then consider youself lucky.

If you need perfect results, then the best thing you can do is disassamble the model into triangles, sort them from back to front based on the camera's position and upload it to the GPU

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .