Cost of shaders

Are “Flat” frag shaders MUCH cheaper than “Phong”?
Are “Untextured” materials much faster than “Textured”?
Is “Write depth (zbuffer)” much costlier than “Only read depth” and “ignore depth”?
Would ignore depth shader be processed to be drawn first?

Would a Flat shader skybox cause performance issues since the WHOLE screen would have to be filled at least once?

Hey @yin-chien_Yeap !

  • Flat is significantly cheaper than Phong, it doesn’t do any light computations at all.
  • Reading texture memory is one of the slowest operations in shaders, hence, yes, untextured should be significantly faster.
  • Not writing depth is likely slower, since it would not prevent shading of the same pixel with a larger depth value (i.e. from a triangle behind the one that is not writing depth). If you know that there are no objects drawn after this object, it may be (probably insignificantly) faster to not write it, but there’s a possibility that it saves nothing, but switching the WebGL state there incurs a tiny insignficant additional cost instead.
  • Blending, although you didn’t mention it, is expensive, since it needs to read from the framebuffer, make sure to disable it where not needed.
  • For the skybox: Make sure to draw it last (drag & drop the pipeline to the end), since this will avoid shading pixels that would be overdrawn by other objects later otherwise, you can therefore get the minimum of pixels shaded with a cheap Flat Textured pipeline there.

In any case, it’s best practice to measure. Enabled the “WebGL Developer Extensions” in “chrome://flags” for higher resolution GPU profiling in the Profile View (works for Oculus Browser, Chrome Desktop and Chrome Android, Brave and other chromium based browsers). Generally, it’s best to draw objects front to back, since the depth test can avoid overdraw that way)

Since performance will depend on which pixels are being shaded, i.e. the scene and the view transform, you can set specific view positions and rotations for the player to take that out of the equation and get results more comparable between runs.