Is there any advantage in using float2 for POSITION in shaders?

Started by
3 comments, last by DividedByZero 5 years, 11 months ago

For a 2D game, does using a float2 for position increases performance in any way?

I know that in the end the vertex shader will have to return a float4 anyway, but does using a float2 decreases the amount of data that will have to be sent from the CPU to the GPU?

 

Advertisement

Seems like you already answered your question. "Increase performance" is a very vague term, in order to quantify performance you need metrics. In either case since you mentioned a 2D use case, if all your objects are in the same place ( ie no parallax ), the using just 2 floats to represent position makes sense. There are certain inherent behavior of the GPU that you cannot control and which may have no bearing on what you put in, with the vertex shader position output size being one of those. The general guidance is to use the smallest type( size and count ) possible while maintaining enough precision in order to reduce the amount of data transferred from CPU to GPU ( bandwidth ).

Yes, but this only becomes an issue if you have a truly massive amount of vertices.

Note that the worst case vertex size is that which is just over multiples of 32 bytes, since the vertex cache is usually partitioned at that size. If you're under that anyway, don't worry.

Niko Suni

1 - Smaller graphical assets, smaller installer package / download.

2 - Faster loading to the GPU.

3 - Faster rendering, less verts to process.

 

Seems like a win-win situation to me.

This topic is closed to new replies.

Advertisement