I would like to hear peoples experience with optimizing for GLSL, particularly when it comes to particles/sprites.
Can any performance be gained by saving OpenGL some vertex-processing (using 3 less vertices per sprite).
Are point-sprites considerably faster than quads?
BACKGROUND:
I need to make a lot of sprites of small size (64 pixels) and I can choose between making them as QUADS or POINTS (i.e. point sprites). Only bad part is that I need to interpolate some data over the sprites (not texture-coordinates - a variable I use for an effect. The value-range is derived from a 32-bit texture which designates “range-categories”, E.g. 0==> 0…1, 1==>2…3).
Now, I can:
- Use point-sprites which makes the texture-coordinates the only varying entity over the fragment, but hardwired to have the range 0…1. I must do something like:
// VERTEX SHADER
uniform baseX, stepX;
uniform baseY, stepY;
baseX = ...
baseY = ...
stepX = ...
stepY = ...
// FRAGMENT SHADER:
uniform baseX, stepX;
uniform baseY, stepY;
...
i = baseX + gl_TexCoord0.s * stepX;
j = baseY + multiTexCoord0.t * stepY;
...
This approach saves me three texture-lookups (and some data-movement with my vertex-buffers) in the vertex shader but has the penalty of 128 extra multiplications in the fragment shader (per sprite that is).
- Use quads and have GL automatically interpolate:
// VERTEX SHADER:
// figure out which corner we're in: 0,1,2,3
// Use gl_TexCoord for interpolation
if (corner == 0) {
gl_TexCoord[0].s = ...
gl_TexCoord[0].t = ...
}
else if (corner == 1) {
...
// FRAGMENT SHADER:
...
i = gl_TexCoord0.s;
j = multiTexCoord0.t;
...
This approach makes the fragment shader minimal but adds extra texture-lookups in the vertex shader (even worse, the texture-lookups will yield the same value for each lookup)
What is your experience when it comes to texture-lookups versus multiplications?
Any thoughts appreciated.
-Rene Jensen