# OpenGL (GLSL) Limitations on passing values to shader?

This topic is 2689 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Although I suspect this will vary between graphics cards, in general, what is the limitation (both sane and possible) GLSL places on the number of values passed as uniforms and attributes?

For instance, I was looking at vertex shader skinning, but came to the conclusion that even if interpolation of rotation matrices is performed outside of the GPU, a considerable number of values must still be passed, and many of those are per vertex.

Here is something I threw together to demonstrate the size of just 15 bones (though, I may have made several blunders so please forgive me if I have):
 uniform mat4 matModel,matView,matProj; uniform mat3 bone[15];//bone orientation in world space uniform vec3 boneOffset[15];//bone location in world space attribute vec3 offset[15];//relative position of vertex to bone location in world space attribute float weight[15];//influence bone has on vertex. Usually 0, sum = 1.0 void main(){ vec3 pos = vec3(0.0f,0.0f,0.0f);//position dependent only on bone weights mat4 matFinal = matProj*matView*matModel;//ftransform() depricated for(int i=0;i<15;i++){ //orient vertex offset by bone angle //translate by bone world position to establish target position //add weight*target position to pos pos+= (bone*offset+boneOffset)*weight; } gl_Postion = matFinal*vec4(pos,1.0f);//submit final vertex position } 
My question is two fold: 1) what are the sane limits and limits imposed by openGL itself, on passing values (uniforms, varying or attribute) to a shader program? I do understand that practically, it will vary between systems, but surely there is some sort of heuristic I can judge by? and 2) is this typically how vertex skinning is performed (I omitted normal calculations and texturing for simplicity)?

Thank you for any help in this regard. I hope the code above was clear enough, I have a tendency to lack clarity.

##### Share on other sites
For opengl 4

const int gl_MaxTextureUnits = 2;
const int gl_MaxTextureCoords = 8;
const int gl_MaxClipPlanes = 8;
const int gl_MaxVaryingFloats = 60;
const int gl_MaxVertexAttribs = 16;
const int gl_MaxVertexUniformComponents = 1024;
const int gl_MaxVertexOutputComponents = 64;
const int gl_MaxGeometryInputComponents = 64;
const int gl_MaxGeometryOutputComponents = 128;
const int gl_MaxFragmentInputComponents = 128;
const int gl_MaxVertexTextureImageUnits = 16;
const int gl_MaxCombinedTextureImageUnits = 80;
const int gl_MaxTextureImageUnits = 16;
const int gl_MaxImageUnits = 8;

From page 8: http://www.khronos.org/files/opengl42-quick-reference-card.pdf

##### Share on other sites
As for your question, no you are doing it wrong in a lot of different ways. To start, you don't need to transform a vertex by 15 bones and 15 weights. Obviously most of those weights are 0 anyway as a finger only has to do with its bone, the wrist bone, and the two arm bones. So most people put a limit of 4 or 5 bones (could be more) that a vertex is actually influenced by. so you have:

for(int i = 0; i < bones_per_vertex;i++)
{
pos += weight*(bone[curr_vertex_attribute]*vertex);
}

and you could do yourself a favor and take "[color="#1C2837"][font="CourierNew, monospace"][color="#000000"]uniform mat4 matModel[color="#666600"],[color="#000000"]matView[color="#666600"],[color="#000000"]matProj[color="#666600"];" and just multiply those on cpu and send 1 matrix.[/font]

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 11
• 9
• 9
• 42
• ### Forum Statistics

• Total Topics
634131
• Total Posts
3015716
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!