Best method of supplying the shaders with data

a couple questions about ‘the best way’

at the moment for supplying (*)data to the shaders with uniforms but with a lot of it eg lightposition, material shininess etc there

already exists stuff that mirrors this in opengl eg gl_LightSource[…], now im tempted to use these cause they feel like a ‘cleaner’

solution BUT will i get bitten by doing this. eg say i add to my fragment shader

vec3 lightpos = gl_LightSource[0].position.xyz;

then on my gffx the fasm cg printout ballons from 3kb upto 18kb due to the addition of



#var float gl_LightSource[7].spotCosCutoff : : (<null atom>.x, <null atom>.y, <null atom>.z, <null atom>.w) : -1 : 0
#var float gl_LightSource[7].constantAttenuation : : (<null atom>.x, <null atom>.y, <null atom>.z, <null atom>.w) : -1 : 0
#var float gl_LightSource[7].linearAttenuation : : (<null atom>.x, <null atom>.y, <null atom>.z, <null atom>.w) : -1 : 0
#var float gl_LightSource[7].quadraticAttenuation : : (<null atom>.x, <null atom>.y, <null atom>.z, <null atom>.w) : -1 : 0
DECLARE gl_ModelViewMatrixInverse$0;
DECLARE gl_ModelViewMatrixInverse$1;
DECLARE gl_ModelViewMatrixInverse$2;
DECLARE gl_ModelViewMatrixInverse$3;
DECLARE gl_LightSource$0$ambient;
DECLARE gl_LightSource$0$diffuse;
DECLARE gl_LightSource$0$specular;
DECLARE gl_LightSource$0$position;

though the instruction count is the same in both.

(*)not per vertex data of course


also a related question about optimal camera position

is there anything wrong in getting the viewers position from doing

vec3 camera_pos = vec3( gl_ModelViewMatrixInverse[3].xyz );

ie. is this the quickest way of using the camera position in my calculation shaders, or am i better off passing the camera’s position

as a uniform to the shader?

though the instruction count is the same in both.
Only that and the number of actually used program parameters is interesting.
Compare the referenced program parameters in the assembly with the comments section (lines starting with “#”).
Using the in-built gl_ state is preferrable over doing it yourself with uniforms, which needs more code in the applicaiton to manage states and will not run faster.

Just use what makes sense in your situation. If it makes sense, use built-in variables. But I wouldn’t recommend ruining readability by abusing GL states for unrelated shader constants. Personally I almost always use uniforms, except for some stuff like the gl_ModelViewProjectionMatrix, simply because it looks better IMHO.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.