• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

Apply Shader to everything within a sprite_width && sprite_height area

JeanSwamp

Member
Hello,

I am trying to make some underwater effect in a sidescrolling game. Applying a fullscreen shader to create an underwater effect is pretty easy, but when you have in the same screen both water and terrain, this might get tricky.

Basically I need to apply the shader to everything that the water collision sprite (I use object collision and not tile collisions) covers within the room, so it does apply the distorsion shader to all the backgrounds and objects that are within the water.

Anyone experienced with this kind of stuff could throw in some light?

Thanks
 

obscene

Member
Since you know how to apply it full-screen, you probably know how to draw a surface and apply a shader to it.

shader_set(shader);
draw_surface(surface,...);
shader_reset();

You can use the exact same setup using with() and draw_surface_part() to just draw parts of the surface using the bbox of certain objects.

shader_set(shader);
with (obj_water) { draw_surface_part(surface,...); }
shader_reset();

Hopefully that will work for your application.
 

JeanSwamp

Member
Yeah that's more or less what I had in mind. My problem was I wasn't able to get anything done to work correctly with draw_surface_part();.

If I recall correctly I was trying draw_surface_part(obj_water, bbox_left,bbox_top,sprite_width,sprite_height,x,y) but I wasn't getting anything being drawn, not even the water sprite itself.
 

sp202

Member
Because you're using room coordinates rather than coordinates relative to the view/surface origin.
 

JeanSwamp

Member
Because you're using room coordinates rather than coordinates relative to the view/surface origin.
And how can I use coordinates related to the view, to only apply it to the sprite_width and height of the water sprite?

Thanks for your time
 
Top