Hey! I had some miscellaneous questions about optimising a project I’m working on and I was wondering if you guys (and girls!) could point me in the right direction on a few things.
First: with a vec2, which is quicker? a*a or pow(a,2)? In an ideal world they’d optimise to the same thing but I don’t have a whole lot of modern hardware to try it out on what’s relevant today.
Second: we need a quick way to discard the current fragment based on a threshold. Is it quicker to use alpha_test or an if statement and discard? This would also skip some other calculations early.
Third: it’s part of the project that the scene is entirely paletted flat colours (with lighting of course). We also intend to use a LOT of lights so have opted for the deferred approach. The intention is to use a 1d palette texture and only write a U into a single float buffer. Is there a format that’d be optimal for this given we’re using at max 30-40 colours? It’d be nice to be able to upload an unsigned char with the particle data and have it rendered out to an unsigned char buffer but it’s a bit unclear as to whether there might be a performance hit because the pipeline seems well optimised for floats.
Fourth: Is there a best format for storing normals in a buffer?
Fifth (and finally): For the lighting stage, it’s necessary to have the current pixel’s position. Would it be best to have a superexpensive RGBAF32 buffer to store the position (expensive in both memory and bandwidth) or is it cheap enough to determine the pixel position using the depth buffer and screen position that it just doesn’t matter?
Thanks for your time!