Material optimization questions

  • Do pixels shaded with a translucent material cost as much as opaque pixels when they are fully opaque, or do they all cost as much as translucent pixels?

  • Is Masked shading affecting overdraw and if so, is it actually cheaper than Translucent shading and why?

  • Is the option “Dither Opacity Mask” making things more expensive or cheaper?

  • Is the “Dither Opacity Mask” option supposed to be used with certain material functions? Is it supposed to be used with the DitherTemporalAA function? Is it supposed to replace the DitherTemporalAA function?

How does VR with instanced stereo rendering and with or without Forward Rendering affect the answers to these questions?

I don’t know how easy it would be to compare opaque and translucent materials because they are using different rendering paths (differed vs forward) and they support different features.
If we are talking strictly about performance then I would say the main thing you need to look out is the instruction count and sample count of the material more than anything else.

I’m not that familiar with masked materials but as far as I know they are not any cheaper… if the opacity is at 100% then it should be almost the same as opaque material (probably with a small extra overhead) if the opacity is less than 100% however then you could run into overdraw.

Dither Opacity is probably a bit more expensive since it’s masking + fading calculations and whatnot.

But as always… this all completely depends on your game (and your hardware) so there is no crystal clear answer here… you should profile your scene and use the shader complexity view to find potential expensive shaders.

I have a question regarding instruction count: Is it possible to see the instruction count of a node/function before plugging it into your material and seeing how much it increases for the entire material? Is there a list of nodes with their instruction counts somewhere?

If material blend mode is set to translucent, cost will be the same for all opacity values.

In masked blend mode, you are receiving a hit from overdraw only for pixels, that are actually transparent. Opaque pixels will cost you slightly more than ordinary surface. This is achieved by early Z rejection.

Wilkes: Nope. Instruction count need to be measured within context. Actual cost depends of other instructions, possible code sharing, instruction latency, register pressure. Actual preformance depends if shader is texture or ALU bound.

Masked material is same cost than opaque + overhead for alpha calculation/texture. Masked material use alpha testing which is dynamic branch. Alpha testing may lower depth testing effiency by eliminating early depth testing or hierarchical depth testing but this vary between GPU’s.

Translucent materials are completely different. Exact cost depends shading mode, shading quality and overdraw. Translucent materials are always forward shaded so they support less features. This is also opens lot of possibilities for optimizations. You can disable everything that is not needed. If pixel opacity is zero it will still cost as much as other pixels. This can be optimized with early out test for these pixels. I have to checkout does UE4 already do this.

How can that early out test be done for those pixels?

You will need to edit BasePassPixelshader.usf. You can insert dynamic branch with return 0; to very early on shader. There is similar branch for alpha testing.

Actually, is there any particular reason why translucent pixels with opacity of 0 are not being discarded?

I know this is a very old post. But, I need help with optimizing my game.
I am getting high Translucency numbers in the GPU visualizer. Can you give examples on the possibilities you meant here “This is also opens lot of possibilities for optimizations.”??