Order Independent Transparency technique

is there any ORDER INDEPENDENT TRANSPARENCY sample demo implementation I can refer with?

1 Like

You can use AlphaTest as a quick solution. Up close it’s not visually incredible, but it takes care of the bare minimum of ordering with transparency. I actually posted about this several years ago: Png transparent pixels in trianglestrip not rendering see-through

Alpha testing is nothing to do with OIT

Order independent transparency uses buffers to log transparent pixels written into the framebuffer so that they can be added together in the correct order in the final render

Look at https://kosmonautblog.wordpress.com/2017/03/17/motion-blur-order-independent-transparency/

Okay so that reply was a little short.

For those that don’t know, OIT is a neat trick that allows you to render transparency without sorting transparent pixels.

It handles the problem when you have multiple transparent surfaces overlapping.

If you just alpha blend everything it looks awful and just plain wrong

It works by using a weighting function based on scene depth, so the pixels closer to the camera are given priority over the pixels further away.

You need two extra render passes

In the first pass you render transparent pixels into two render targets.
The first captures the colour after being multiplied by the weighting fucntion
The second contains the weight

You do need to setup a special blend equation for this pass.

The second pass combines these render targets with the opaque scene using a full screen quad

So why do we need this?

Sorting is evil. Anytime you have to sort triangles you are burning t states and eating memory. There are no simple ways of doing this on a GPU, so it is the CPU that has to take the hit. Sorting should be avoided if at all possible

Do you always need it?

No.
If you don’t have a lot of transparency in your 3D scene you can get away with a simple alpha blending system

Is it worth the effort?

Well it depends on your game. If you are doing something like a final fantasy clone with lot’s of effects going off every frame , lot’s of layers of transparent polys, hell yes. The bang you get for your buck is well worth it

How hard is it?

The ONLY difficult thing is the weighting equation. Get it wrong and the results are wrong. You will notice it, swear a lot, throw the teddy bear out of the pram and sink into a corner singing the programmers song

So do the research, do some reading, and you will be fine.

I don’t know of a Monogame demo of OIT, maybe I should write one.

1 Like

I had an hour to spare so I threw a demo together

By the way we can’t set a different blend equation per render target.

We should be able to

Isn’t TargetBlendState an array?

3 Likes

Thanks alot, u save my day. i ned some time to digest it.

Note I had to add an extra render pass because you need different blending equations for the weight and colour parts

These are normally done in one pass, but we need a change to MonoGame to support that

1 Like

I probably shouldn’t ask this, but what IS the programmer song?

I would hazard at one of these two:

Bonus track:

Hehe

An old version I wrote

https://gamedev.net/forums/topic/654080-my-own-game-feels-worse-than-it-is/5136322/