Sign in to follow this  

How to transform vertices by GLSL..

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

typedef struct _vertex
{
float x,y,z;
}vertex;

typedef struct _matrix
{
float value[16];
}
vertex vArray[1000];
vertex mArray[32];

the matrixes will transform the vertices..
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
OK..We send the datas in vArray to a VBO...And we really know witch matrix in mArray will transform a vertex in vArray as a index..
and may be we can send the matrix datas to GPU as a texture or as a buffer object..

we can code GLSL like :
void main ()
{
gl_Position = M1 * M2 * Vertex;//Vertex is an enement in VBO source from vArray;
}
but I don't know the true index of the vertex in vbo.... any way ?

And I've think about to send all the datas - the matrixes and the vertices - as texture to GPU but maybe it'll be foolish..


I'm just finding the right way to act the Skeletal animation with GPU..But not with CPU...

Thanks for any help..

Share this post


Link to post
Share on other sites
you can pass an attribute(or in) vertex as vertex data. you don't only have to pass x/y/z, lookup information about attributes with shaders.

for skinning, you can do it as a series of uniform matrix's, but your limited by the number of uniform names the gpu can have. personally, i use a texture buffer sampler, which is essentially a large unformatted array, to hold my skeleton matrix's, and the vertex's have both an ivec4 and vec4 for index/weight information passed.

still, i'd recommend first learning about attributes, then move onto texture buffers/uniform buffers.

also, off topic, but i somehow activated firefox's 3D view when i was responding, it's pretty sick.

Share this post


Link to post
Share on other sites
[quote name='slicer4ever' timestamp='1343029011' post='4962167']
you can pass an attribute(or in) vertex as vertex data. you don't only have to pass x/y/z, lookup information about attributes with shaders.
[/quote]

I notice that you've said :the vertex's have both an ivec4 and vec4 for index/weight information passed.
Yes it's really the right way .. But I don't know how to get the value for the index and weight in GLSL..
All of glVertexPointer and glBufferData can submit data to GPU include the X Y Z , index and weight and other value we want to submit..
Then we call the Scence render funcs of OpenGL but I want to know how should the GLSL separate them as X Y Z and index and weight or other data..?

Share this post


Link to post
Share on other sites
If the data in vertex buffer is like this:
x y z index weight
x y z index weight
x y z index weight
x y z index weight
x y z index weight
x y z index weight
x y z index weight

then how the OpenGL pass the data to our shader process ?
here's the vertex shader: Edited by FireInDark

Share this post


Link to post
Share on other sites
glVertexAttribPointer is what you need, to be fair, i'd recommend forgetting glVertexPointer, or it's affiliates exist. using glVertexAttribPointer you can pass any data you need to the shader, you just have to bind the attribute's name to a bind index, and pass the proper offset's.

Share this post


Link to post
Share on other sites
[quote name='slicer4ever' timestamp='1343034966' post='4962186']
glVertexAttribPointer is what you need, to be fair, i'd recommend forgetting glVertexPointer, or it's affiliates exist. using glVertexAttribPointer you can pass any data you need to the shader, you just have to bind the attribute's name to a bind index, and pass the proper offset's.
[/quote]

Thank you ..I'll try it latter..[img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]

But still I can't understand your last words "the vertex's have both an ivec4 and vec4 for index/weight information passed"
How will you get vertex part ,the index part and the weight part frome a "vertex data buffer" .

I've google glVertexAttribPointer and I noticed that there's a parameter "stride " for it ,just as the glVertexPointer.
It's means that we can pass extra datas like:

"attribute in use" "extra data"
"attribute in use" "extra data"
"attribute in use" "extra data"
"attribute in use" "extra data"
"attribute in use" "extra data"
I got it's useful by your words "bind the attribute's name to a bind index, and pass the proper offset's."

But just like what I express as you pass the data to GPU :
x y z index weight
x y z index weight
x y z index weight
x y z index weight
x y z index weight
x y z index weight
x y z index weight

how will you use the index and the weight part ...
Any way to bind index part and the weight part as we bind the attribute datas ? Edited by FireInDark

Share this post


Link to post
Share on other sites
you really should be looking up some tutorials, i've given you quite a few keywords to be searching though.

this is a rather old, but goodie for introduction to shaders: [url="http://www.lighthouse3d.com/tutorials/glsl-tutorial/"]http://www.lighthous.../glsl-tutorial/[/url]

but let's look at your problem, you want to pass just a single index/weight.

so, in c++/openGL:
[code]
struct Vertex{
float x, y, z;
int index;
float weight;
};


void DrawObject(Vertex *Verts, int Count){
glUseProgram(ShaderID); //ShaderID is defined elsewhere
//Also bind buffer here if using vbo
//Upload uniform's here as well for bone matrix's/view/proj matrix's.
int i_VetexLoc=glGetAttribLocation(ShaderID, "i_Vertex"); //get attib locations
int i_IndexLoc=glGetAttribLocation(ShaderID, "i_Index");
int i_WeightLoc=glGetAttribLocation(ShaderID, "i_Weight");

glEnableVertexAttribArray(i_VertexLoc); //Enable them so the appropiate pointer is also called.
glEnableVertexAttribArray(i_IndexLoc);
glEnableVertexAttribArray(i_WeightLoc); //remember to disable later!

glVertexAttribPointer(i_VertexLoc, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), &Verts[0].x); //use offset's if using vbo.
glVertexAttribPointer(i_IndexLoc, 1, GL_INT, GL_FALSE, sizeof(Vertex), &Verts[0].index);
glVertexAttribPointer(i_WeightLoc, 1, GL_FLOAT, GL_FALSE, sizeof(Vertex), &Vertes[0].weight);
glDrawArrays(GL_TRIANGLES, 0, Count);
return;
}
[/code]

note: my engine abstracts this away, so if i got something wrong, someone please correct me.

vertex shader:
[code]
#version 150 //i like to use 1.50, but you can use whatever you want.

uniform mat4 ViewMatrix; //My view matrix, and/or viewmodel
uniform mat4 ProjMatirx; //My projection matrix.
uniform mat4 BoneMatrix[30]; //My array of bone matrix's.

in vec3 i_Vertex; //In vertex.
in int i_Index; //Index to BoneMatrix;
in float i_Weight; //Weight of influence.

void main(){
gl_Position = ProjMatrix*ViewMatrix*BoneMatrix[i_Index]*vec4(i_Vertex, 0.0)*i_Weight; //over-simplified, but get's the point across...
return;
}
[/code]

edit: also:
[quote name='FireInDark' timestamp='1343035556' post='4962189']
I've google glVertexAttribPointer and I noticed that there's a parameter "stride " for it ,just as the glVertexPointer.
It's means that we can pass extra datas like:
[/quote]

[quote="docs"]
Stride:
Specifies the byte offset between consecutive generic vertex attributes. If stride is 0, the generic vertex attributes are understood to be tightly packed in the array. The initial value is 0.
[/quote]
it has nothing to do with "extra data", you could encode all the data in diffrent arrays for all gl cares, all stride does it tell each attribute how far to move before reading the next element. Edited by slicer4ever

Share this post


Link to post
Share on other sites
[quote name='slicer4ever' timestamp='1343046686' post='4962217']
you really should be looking up some tutorials, i've given you quite a few keywords to be searching though.
[/quote]

Yes,that's true ....I just have read the "red book " about OpenGL and I know little about shader language ...
Thus I've got http://www.lighthouse3d.com many days ago ,but still I learned little about GLSL..cause I know little about english too..

But I know how should I code my shader now by reading your codes above..So thank you very much..

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this