M
moogthedog
Guest
I have no idea if this is the right place for this, so if not, I apologise and I'll remove.
I have created a couple of projects in Gamemaker 1.4, and have enjoyed using the system. Now I'm looking to investigate shaders, as I want to apply some more complex effects to some sprites. I'm a long-time programmer, but fairly new to Gamemaker.
As a first stab, I am looking to create a shader that will only render the even numbered lines of a sprite or surface, based on its X,Y value on the screen. (So a sprite at position Y=3 will not have a top line and alternating between on and off down from there, but a sprite at Y=4 would have its second and fourth lines 'missing' and so on down...)
I figured I could do this by setting the odd numbered lines to be completely transparent. The idea is to then have a second shader that does this to the even numbered lines (presumably that'll be a very similar script ) and have the two items 'pass through' each other like a comb effect.
I figured this should be fairly easy, and wrote the code below into the vertex portion of a new shader:
The idea being that I create a 'forced even' version of the Y co-ordinate of the vertex (halfline), and if that *doesn't* match the 'real' Y co-ordinate (meaning it's an odd line number), then the alpha is set to zero.
I applied this to a simple sprite of a white circle ...
...that I stuck fairly randomly in a blank room, and it had the rather odd effect applying a gradient fade to the circle, so the lowest line was completely shown, and reducing the alpha until the top was completely see-through.
When I wrote some more code to move the circle down the screen a pixel at a time, it flickered between that, and fading other way up - top to bottom. An interesting effect, but not what I'm after. I'm particularly intrigued where the fade came from, as in my code the alpha is either untouched or 0.
Can anyone explain what's happening? (And if anyone's got tips as to how to do what I want, that would be lovely too )
I have created a couple of projects in Gamemaker 1.4, and have enjoyed using the system. Now I'm looking to investigate shaders, as I want to apply some more complex effects to some sprites. I'm a long-time programmer, but fairly new to Gamemaker.
As a first stab, I am looking to create a shader that will only render the even numbered lines of a sprite or surface, based on its X,Y value on the screen. (So a sprite at position Y=3 will not have a top line and alternating between on and off down from there, but a sprite at Y=4 would have its second and fourth lines 'missing' and so on down...)
I figured I could do this by setting the odd numbered lines to be completely transparent. The idea is to then have a second shader that does this to the even numbered lines (presumably that'll be a very similar script ) and have the two items 'pass through' each other like a comb effect.
I figured this should be fairly easy, and wrote the code below into the vertex portion of a new shader:
Code:
void main()
{
vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
/* MY BIT HERE */
int halfline=int(in_Position.y/2.0);
halfline=halfline*2;
v_vColour = in_Colour;
/* AND HERE*/
if (halfline!=int(in_Position.y))
{
v_vColour.a=0.0;
}
v_vTexcoord = in_TextureCoord;
}
I applied this to a simple sprite of a white circle ...
Code:
object draw event {
shader_set(shader0);
draw_self();
shader_reset();
}
When I wrote some more code to move the circle down the screen a pixel at a time, it flickered between that, and fading other way up - top to bottom. An interesting effect, but not what I'm after. I'm particularly intrigued where the fade came from, as in my code the alpha is either untouched or 0.
Can anyone explain what's happening? (And if anyone's got tips as to how to do what I want, that would be lovely too )