Rendering models that contain transparent and non transparent parts

Lets say I have a car model with both solid and transparent parts (car body and a windshield you can see-through). And lets make it even trickier - I also want to render a driver inside the car (a different, changable model). Now multiply it by 100 cars.

What’s the best approach to render this type of scene?

I know that all the transparent parts should be drawn last, ordered by distance from camera (in case you can see-through multiple windshields) and without writing to depth buffer (so they won’t block solid stuff). But how can I make it somewhat generic and not very specific hard-coded stuff for this scenario?

Lets say I added metadata to all models and their parts, and I somehow magically know which parts are transparent.

This means that I still need to

  1. Do at least 2 rendering phases, one for solids and one for transparent.
  2. Sort the transparent stuff by distance from camera and disable depth writing.

Is this really the right way to do it? I feel like MonoGame design doesn’t really encourage it, as it treat model and meshes as a whole. Is there maybe a more simple way to do it which I’m missing?

PS. please don’t try to give solutions for my specific car-driver example, it was just to explain the problem. Assume my scene have hundreds of different models with complete transparent / non-transparent insanity. Assume the worse possible case.

Thanks!

you can create your own class or slit into two models(opaque and transparent)

What I do is this:
A custommodelprocessor, which marks/tags meshparts as “transparent” or “alpha-test” or etc.
When I ask to my scene manager what to draw, it gives me 2 lists (Fitting your example, but I have more types): solid and transparants objects, which are then passed to the renderer into their own effect handler.
But if I have no or a very few transparent objects, I loose some speed, so I added a “simple” method in the scene manager which gives me only a list objects, ignoring tags, and I switch effects when looping on meshparts and looking for the mesh’s tag. For 20 or less transparents against 200 objects it is faster than looking each tags of each mesh.

1 Like

In my deferred engine I sort all the meshes by material type and just store their transformations additionally.

It’s honestly a bit messy, but there is no good way “built-in”, it’s a pain you have to resolve manually as monogame/xna has no design philosophy for this

1 Like

Since I have my own mesh loader that don’t rely on content pipeline, I can easily change texture, effects and renderstate at any given time. Sorting only happened whenever there is a TRANSPARENT_ALPHA_BLEND on current frame drawable mesh list.

       // Ship main body
        m_Ship.MeshGroups( 0 ).Materials(0).renderState     = RenderState.SOLID_CCW;
        m_Ship.MeshGroups( 0 ).Materials(0).textureContent0 = m_ShipBodyText;            
        // Ship window
        m_Ship.MeshGroups( 1 ).Materials(0).renderState     = RenderState.TRANSPARENT_ADDITIVE;
        m_Ship.MeshGroups( 1 ).Materials(0).textureContent0 = m_ShipWindowText;
        // Ship hud
        m_Ship.MeshGroups( 2 ).Materials(0).renderState     = RenderState.TRANSPARENT_ALPHA_BLEND;
        m_Ship.MeshGroups( 2 ).Materials(0).textureContent0 = m_ShipHudTexture;
1 Like

Thanks for all the replies, this question is super old I already implemented sorting queues a long time ago :slight_smile: but I guess its good to have this thread going for future seekers that might wonder the same thing.

Cheers!