the_dude_abides
Member
I'm a noob, so bare that in mind
I am looking at using vertex buffers and shaders for animating objects, and was wondering whether my current approach has any benefits for this method of "drawing". I have my shape defined and can draw it, but am totally flummoxed by how you then re-position the vertexes using a shader.
Some objects are rotating around a specific point at an unchanging length. Their positions from the origin for each angle have already been calculated, and the x difference / y difference stored in an array. The maths is only done once, and hopefully accessing one array position is better than redoing multiple lengthdir_x/y calculations each time.
1) If the shader is just saying "this corner was here before, and now I want it over there", is there anything to still be gained from handing it to the GPU in a vertex buffer? This is my code in a step event, from when I was just drawing textured primitives:
Could I pass the origin point (is_x, is_y) to the shader, along with 'is_ang' and the array, and then have it perform the basic maths of:
is_x + is_array_joint[is_ang, 0];
to get the positions? Which I guess adds up to slightly less for the CPU to do?
2)If there is still some benefit to be had from using a vertex buffer and shader: how would I go about doing it?
This is trimmed down for readability. It's 2d so I am only using x and y positions, then the texture coordinates and colour.
vertex_format_add_custom etc is my guess at how I tell it to change the position, but what do I put for the x / y values when defining the buffer? Because it would seem like I don't have anything fixed to add in at this point, and it's in the shader where I'd define the value of the floats. They need to be included in the format here, but I just put a fixed value in for now and then update it in the shader?
Presumably the shader needs telling what 'is_x' / 'is_y' / 'is_ang' / 'is_array_joint' are as values, but I have no idea what changes the passthrough shader, or fragment shader, would require to alter the vertices position.
Any help with this would be appreciated
I am looking at using vertex buffers and shaders for animating objects, and was wondering whether my current approach has any benefits for this method of "drawing". I have my shape defined and can draw it, but am totally flummoxed by how you then re-position the vertexes using a shader.
Some objects are rotating around a specific point at an unchanging length. Their positions from the origin for each angle have already been calculated, and the x difference / y difference stored in an array. The maths is only done once, and hopefully accessing one array position is better than redoing multiple lengthdir_x/y calculations each time.
1) If the shader is just saying "this corner was here before, and now I want it over there", is there anything to still be gained from handing it to the GPU in a vertex buffer? This is my code in a step event, from when I was just drawing textured primitives:
Code:
var is_x = x;
var is_y = y;
var is_ang = round(point_direction(is_x, is_y, mouse_x, mouse_y));
if is_ang > is_360
{is_ang -= is_360;}
image_angle = is_ang;
first_x = is_x + is_array_joint[is_ang, 0];
first_y = is_y + is_array_joint[is_ang, 1];
is_x + is_array_joint[is_ang, 0];
to get the positions? Which I guess adds up to slightly less for the CPU to do?
2)If there is still some benefit to be had from using a vertex buffer and shader: how would I go about doing it?
GML:
vertex_format_begin();
vertex_format_add_position();
vertex_format_add_textcoord();
vertex_format_add_colour();
vertex_format_add_custom(vertex_type_float2, vertex_usage_position) <<<<<<<<< ??
format = vertex_format_end();
joint_buffer = vertex_create_buffer();
vertex_begin(joint_buffer, format);
vertex_position(joint_buffer, second_x, second_y);
vertex_texcoord(joint_buffer, tex_left, tex_bottom);
vertex_colour(joint_buffer, c_white, 1.0);
vertex_float2(joint_buffer, what goes here?, what goes here?) <<<<<<<<<<<<< ??
vertex_end(joint_buffer);
vertex_format_add_custom etc is my guess at how I tell it to change the position, but what do I put for the x / y values when defining the buffer? Because it would seem like I don't have anything fixed to add in at this point, and it's in the shader where I'd define the value of the floats. They need to be included in the format here, but I just put a fixed value in for now and then update it in the shader?
Presumably the shader needs telling what 'is_x' / 'is_y' / 'is_ang' / 'is_array_joint' are as values, but I have no idea what changes the passthrough shader, or fragment shader, would require to alter the vertices position.
Any help with this would be appreciated