Legacy GM Adding a shader to a single object

V

VicoZann

Guest
Hello all,
I'm trying to add a shader to my player character, but I have never used shaders before and pretty much every tutorial I find is about adding shaders to the whole screen.

How does one goes about adding the shader to a single object? Do I still need to disable the auto shader in a create event? Any help I can get with this is really appreciated, the more noob friendly the better.
 
V

VicoZann

Guest
Hey, you should be able to have something like this in the draw event for the object:

Code:
shader_set(myShader);
draw_self();
shader_reset();
At first I tought it worked, but as soon as my character started facing to the other side, a copy of his appeared. there are 2 of him being drawn. One normal and one with the shader that can only look left. I think it has something to do with the other stuff on my draw event


///Draw Player

draw_sprite_ext(sprite_index, image_index, round(x), round(y), facing, image_yscale, image_angle, c_white, 1);

//shader
shader_set(shader0);
draw_self();
shader_reset();​

Any idea of what's going on?
 

Electros

Member
Ah ok, could be the other draw code you already had - have you tried:

Code:
//shader
shader_set(shader0);
draw_sprite_ext(sprite_index, image_index, round(x), round(y), facing, image_yscale, image_angle, c_white, 1);
shader_reset();
Draw self is just for a default draw "This function draws the sprite assigned to the instance exactly as it would be drawn if the draw event held no code or actions, and will reflect and changes that have been made to the sprite variables in other events."
 
V

VicoZann

Guest
Ah ok, could be the other draw code you already had - have you tried:

Code:
//shader
shader_set(shader0);
draw_sprite_ext(sprite_index, image_index, round(x), round(y), facing, image_yscale, image_angle, c_white, 1);
shader_reset();
Draw self is just for a default draw "This function draws the sprite assigned to the instance exactly as it would be drawn if the draw event held no code or actions, and will reflect and changes that have been made to the sprite variables in other events."
Once again it worked. It seens it was quite simple to do it, but this shader stuff was pretty scary not knowing anything. Thanks for the help, I'll go into learning how to modify the shaders to what I need. Any sugestion of good tutorials for that?
 

Electros

Member
I'm no expert - I have learnt how to turn things red, and how to turn things greyscale. :) Best advice I have is;

-read whatever you can on it, a couple of links I found useful:
http://www.yoyogames.com/blog/14
https://forum.yoyogames.com/index.php?threads/grayscale-shader.1657
http://xorshaders.weebly.com/tutorials
https://www.opengl.org/sdk/docs/tutorials/TyphoonLabs/ (not used too much of this, looks good though!)

-setup a very simple project with a couple of objects and shaders, and play around with the values, variables etc and see what happens!
 
Top