Shaders Using Chromatic Aberration when killing an enemy.

B

BOON

Guest
Hello, I'm making something like this example

example.PNG



(I want to achieve something like this death animation (the colors specifically)

What I want to do is basically offset the color channels of a Sprite or the entire image after its been destroyed by the player

I found a shader that I can use in GameMaker that can make such an effect
https://marketplace.yoyogames.com/assets/3046/chromatic-aberration-shader


but I have little experience with shaders and now that I've imported the shader I'm unsure how I can apply it only at the instance where I want it.

_______________________________________________________________________________________


Here is the object and events and scripts that the shader came with, essentially it did exactly what is presented in its trailer

You click SPACE then it creates an image which you can then control how much of the effect you want to apply with the left and right keys.


Here is the code that came with an object that interacts with the shader.

///This is a create event
dis_u = shader_get_uniform(sh_aberration, 'u_Distance');
dis = 1;

shader = 1;
draw_set_font(f_std);
str = 'Press space to turn on/off the shader.#';
str += 'Press Left or Right to change the distance.';


///A step event
dis += (keyboard_check(vk_right)-keyboard_check(vk_left))/10;

if (keyboard_check_released(vk_space)) {
shader = !shader;
}

____________________________________________________________________________

///A normal draw event
if (shader = 1) {
shader_set(sh_aberration);
shader_set_uniform_f(dis_u, dis);
}
draw_background(b_back, x, y);
shader_reset();

draw_text(16, 16, str);


How can I control this effect so that it applies when you destroy an enemy?example.PNG
 

dphsw

Member
I haven't looked at the shader but I'm imagining how it should work. I think that when drawing your enemy, you'll just need to replace it's draw call (which might just be draw_self(); at the moment - if you haven't made a draw event, that's what it does by default) with:
Code:
shader_set(sh_aberration);
shader_set_uniform_f(dis_u, dis);
draw_self();
shader_reset();
Of course, you'll have to have got the dis_u and dis variables first in the enemy create event, the same as in the example code. And you'll only want to use this code if the enemy is dying - otherwise just use draw_self(); by itself.
 

obscene

Member
If you want to avoid shaders, you can easily do this yourself on a sprite by just drawing the sprite 3 times with offsets and different colors...

var offset=2; // Strength of effect
draw_set_blend_mode_ext(bm_one, bm_inv_src_color);
draw_sprite_ext(sprite_index,-1,x+offset,y,image_xscale,image_yscale,image_angle, c_red, 1);
draw_sprite_ext(sprite_index,-1,x,y,image_xscale,image_yscale,image_angle, c_lime, 1);
draw_sprite_ext(sprite_index,-1,x-offset,y,image_xscale,image_yscale,image_angle, c_blue, 1);
draw_set_blend_mode(bm_add);
 
Top