Best way to pass parameters to a glsl shader with very low overhead?

Started by
2 comments, last by V-man 15 years, 3 months ago
Hello, I have to draw high-quality antialiased 2D trapezoids. There are very strict quality regulations, so I can't use multisampling of fsaa. The problem I am faicng is that I don't know a good way to transport the trapezoid geometry down to the shader? I experimented using textures accessed by the shader, but to make this route efficiently I would have to render many trapezoids in one go, which makes the loopup-routines (to decide which pixel-value in the command-texture is which trapezoid and so on) very complex and slow. Ideally I would like to draw a single trapezoid per quad I render, with a very low overhead method of telling the shader the properties of the next trapezoid. Whats the preferred way to do so? Something like repeated: 1. Set properties of next trapezoid 2. Render one single trapezoid (shader on quad) I have heard the shader is re-compiled as when uniforms are changed, so that would have way too much overhead. Or is this information outdated? Can the problem above solved efficiently at all? Thank you in advance, Clemens
Advertisement
Quote:Original post by TheLinuxhippy
I have heard the shader is re-compiled as when uniforms are changed, so that would have way too much overhead. Or is this information outdated?
Can the problem above solved efficiently at all?


It was said that on nvidia, when you set certain values for uniforms like 0.0, 0.5, 1.0, 2.0, it would recompile your shader in order to optimize it.
For other values, it does not recompile.
This is a problem for games and application where there is a lot of animation and uniforms are changing all the time.
I don't want my shader to recompile if I suddenly set something to 0.0 because I have hundreds of shaders.
I haven't retested this to see if nvidia changed things.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
And do you know how slow setting uniforms is, if the driver doesn't do crazy things?
Is it the preferred way to transport small amounts of data into the shader frequently?
That's what I use and it is fine for my case.

In other cases where you needs to render lots of time the same object, there is a method called pseudo instancing.
Then came along http://www.opengl.org/registry/specs/ARB/draw_instanced.txt

and then there is BUO for certain GPUs like Gf 8
http://www.opengl.org/registry/specs/EXT/bindable_uniform.txt
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement