• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

1 vertex model, 2 triangles, vertex shader opposite directions

sorry if this is a repost not sure what im searching for :
As the title says im trying to make a vertex model of a sprite image split into two opposite directions with vertex shader sort of like in fruit ninja.

so in the draw event I send a uniform to the shader with a positive and negative value for both x and y (only x is needed);

I can then move the entire vertex image using the following code in the vertex shader :

////////////
//
// Simple passthrough vertex shader
//
attribute vec3 in_Position; // (x,y,z)
attribute vec3 in_Normal; // (x,y,z) unused in this shader.
attribute vec4 in_Colour; // (r,g,b,a)
attribute vec2 in_TextureCoord; // (u,v)

varying vec2 v_vTexcoord;
varying vec4 v_vColour;

uniform vec2 posx[2];

float testitx, testity, testitx1, testity1;

void main()
{
testitx = posx[0].x;
testity = posx[0].y;
testitx1 = posx[1].x;
testity1 = posx[1].y;


vec4 object_space_pos = vec4( in_Position.x + testitx , in_Position.y + testity , in_Position.z, 1.0);

gl_Position = (gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos);

v_vColour = in_Colour;
v_vTexcoord = in_TextureCoord;
}


///


where posx[0] is positive x and posx[1] is negative but the problem im having is i do not know how to declare each individual triangle as a component in the shader. if anyone has any keywords I can search for to close topic thank you.
 

rytan451

Member
In order to do this, I suspect you'll need to use a geometry shader, which is not supported by GMS. As an alternative, why not draw the sprite twice, in two primitives, with the UV positions modified so that it looks like it's cut?
 
So im still pretty lost about what im doing here there is almost no simplified examples for vertex shader animations....
However I was able to slip a custom vec3 float as a custom color with one triangle having -1 for x and y and the other triangle
having positive 1 for x and y like so:

vertex_float3(v_buff5,1,1,0);
vertex_float3(v_buff5,-1,-1,0);

and then I simply multiplied that by the xy position sent through uniform

it works but it isn't exactly what I wanted. I was hoping to more precisely control the triangles when they split but I dont quite get bone_weight
and bone_indices concepts. I've looked around; it is all the same technical terms repeated with little simplified examples. I guess it helps if you know what
you are searching for exactly
 
the only reason this doesn't completely work is because there are multiple sprites on a single model all the -1 and positive 1 triangles split at the same time
 
so all I had to do was write an array in the buffer and set a number for the custom color and use the custom color to pull from the array.

here is an example project:

when I run it using frame_skip and an alarm i find using shader to draw and move 1000 sprites is a lot faster.

So if I wanted to have more like 10,000-20,000 sprites I would need to use a vec4 for xy positions or the shader gets overloaded
and then access them as a vec2. Maybe I can figure it out playing with arrays but
if someone could answer how to do that would appreciate it.

Also if anyone knows using a fragment shader to achieve this same effect would be faster?
 
Top