Vertex Shader help

Okay, so currently i have 3 attributes being used by the vertex shader. Position, Normal and texture cords. Recently i’ve added a Rig object to each rawmodel object. If i have these attributes,

List<Matrix4f> boneMatrixs;
ArrayList<ArrayList<Integer>> boneChains;
private float vertexWeights[];
private int vertexBoneCount[];
private float BoneVertexAttatch[][][];

How would i go about adding these attributes to effect each vertex? Thanks in advance!

Vertex Shader:

in vec3 position;
in vec2 textureCoords;
in vec3 normal;

out vec2 pass_textureCoords;
out vec3 surfaceNormal;
out vec3 toLightVector;
out vec3 toCameraVector;

uniform mat4 transformationMatrix;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform vec3 lightPosition;

void main(void){

vec4 worldPosition = (transformationMatrix * vec4(position,1.0));
gl_Position = projectionMatrix * viewMatrix * worldPosition; 
pass_textureCoords = textureCoords;
surfaceNormal = (transformationMatrix * vec4(normal,0.0)).xyz;
toLightVector = lightPosition - worldPosition.xyz;
toCameraVector = (inverse(viewMatrix) * vec4(0.0,0.0,0.0,1.0)).xyz - worldPosition.xyz;

}

Loader:

in vec3 position;
in vec2 textureCoords;
in vec3 normal;

out vec2 pass_textureCoords;
out vec3 surfaceNormal;
out vec3 toLightVector;
out vec3 toCameraVector;

uniform mat4 transformationMatrix;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform vec3 lightPosition;

void main(void){

vec4 worldPosition = (transformationMatrix * vec4(position,1.0));
gl_Position = projectionMatrix * viewMatrix * worldPosition; 
pass_textureCoords = textureCoords;
surfaceNormal = (transformationMatrix * vec4(normal,0.0)).xyz;
toLightVector = lightPosition - worldPosition.xyz;
toCameraVector = (inverse(viewMatrix) * vec4(0.0,0.0,0.0,1.0)).xyz - worldPosition.xyz;

}

Please ask if more information is needed.

[QUOTE=noahn567;1262454]Okay, so currently i have 3 attributes being used by the vertex shader. Position, Normal and texture cords. Recently i’ve added a Rig object to each rawmodel object. If i have these attributes,


	List<Matrix4f> boneMatrixs;
	ArrayList<ArrayList<Integer>> boneChains;
	private float vertexWeights[];
	private int vertexBoneCount[];
	private float BoneVertexAttatch[][][];

How would i go about adding these attributes to effect each vertex?[/QUOTE]
You don’t state how those values are supposed to be interpreted.

But as a rough guide, what you need to pass to the vertex shader is:
[ol]
[li] A 1D array of matrices representing absolute bone transformations.
[/li][li] A 2D array of vertex-bone attachments, i.e. each attachment[v][i] is the index of one of the bones attached to vertex v.
[/li][li] A 2D array of weights, , i.e. each weight[v][i] is the weight corresponding to attachment[v][i].
[/li][/ol]
Note that GLSL doesn’t directly support 2D arrays; you can either
[list=1]
[li] pass a flattened array of length num_vertices * num_attachments and translate attachments[v][i] to attachments[v*num_attachments+i], or
[/li][li] use an array of vectors; this limits the maximum number of bones attached to a sinlge vertex to 4.
[/li][list]

Example:


#define NUM_BONES 50
uniform mat4 bones[NUM_BONES];
uniform vec4 weights[NUM_BONES];
uniform ivec4 attachments[NUM_BONES];

in vec4 position;

void main() {
    vec4 position4 = vec4(position, 1.0);
    vec4 worldPosition = vec4(0.0);
    for (int i = 0; i < 4; i++)
        worldPosition += weights[attachments[gl_VertexID][i]] * (bones[attachments[gl_VertexID][i]] * position);
    gl_Position = gl_ModelViewProjectionMatrix * worldPosition;
}

Hey, first off, thank you for the very helpful information :D. This will really get me on my way. You can completely shut down this idea if you’d like, but could we exchange emails? I just think that you are very Intelligent in this field and would love to learn what you know :D. My email: noahn567@gmail.com. I dont really have time to work with the info you’ve given me right now (Its 2 am here). But i plan on working on this tommorow! I’ll update this thread with questions later :D. Thanks again!

1- bondeindex and bonweight are attributes in other world max bone each vertex will be 4
each vertex most has 0-4 bone effect on it

2- to do it in vertex shader

in vec3 position;
in vec2 textureCoords;
in vec3 normal;
in vec4 BoneIndex;
in vec4 Weights;
uniform mat4 bones[10];

void main()
{
vec4 newvertex;
vev3 newNormal;
new newvertex += bones[int(BoneIndex.x)]gl_VertexWeights.x;
new newNormal+= mat3(bones[int(BoneIndex.x)])gl_NormalWeights.x;

new newvertex += bones[int(BoneIndex.y)]gl_VertexWeights.y;
new newNormal+= mat3(bones[int(BoneIndex.y)])gl_NormalWeights.y;

new newvertex += bones[int(BoneIndex.z)]gl_VertexWeights.z;
new newNormal+= mat3(bones[int(BoneIndex.z)])gl_NormalWeights.z;

new newvertex += bones[int(BoneIndex.w)]gl_VertexWeights.w;
new newNormal+= mat3(bones[int(BoneIndex.w)])gl_NormalWeights.w;

gl_Position = ProjectionViewTransform*newvertex ;
newNormal = mat4(Transform)*newNormal ;
}