• 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!

Shaders [SOLVED] How to apply two shaders to application surface?

I

izark

Guest
I have tried to apply two different shaders to the application surface without success:
If I apply these shaders separately on the draw_gui event, they work fine.
But I don´t know how to apply both.

I have tried to draw the application surface with the first shader applied to it, copy it to a new surface and draw this new surface with the second shader applied, but I get a black screen.

I have tried also to draw the application surface two times, with 0.5 alpha each one, and apply those two shaders separately, but only the last shader is drawn.

I have also tried to draw the first shader on the draw_end event and the second shader on the draw_gui event, but then a texture page is drawn on the screen lol.

I have also thought of combining those two shaders in one shader in the shader editor, but that would be a pain.

How can I solve this? I appreciate any help.
 
Last edited by a moderator:

Perseus

Not Medusa
Forum Staff
Moderator
I have tried to draw the application surface with the first shader applied to it, copy it to a new surface and draw this new surface with the second shader applied, but I get a black screen.
In theory, that should work fine. What is the exact code that you used? Did you try drawing the (new) surface without applying the second shader? It is possible that something screwed up when you tried to draw the application surface with the first shader onto it.
 
I

izark

Guest
In theory, that should work fine. What is the exact code that you used? Did you try drawing the (new) surface without applying the second shader? It is possible that something screwed up when you tried to draw the application surface with the first shader onto it.
Ok, I rearranged the code and it is misteriously working now what I did:
Instead of applying the first shader to the application surface, copy that surface to a new one and apply the second shader to this new surface:

Code:
application_surface_draw_enable(false);

display_set_gui_size(room_width, room_height);

if !surface_exists(surfa)
   surfa = surface_create(display_get_gui_width(),display_get_gui_height())

//FIRST SHADER

   surface_set_target(surfa)
   shader_set(shader_to_use);
     draw_surface(application_surface,0,0)
   shader_reset();
   surface_reset_target()
 
//SECOND SHADER

 shader_set(s_grain);
  draw_surface(surfa,0,0)
  shader_reset();
 

Dupletor

Member
Something feels odd about this code. Why can he leave without resetting the target to the application surface after the second shader?
Is it reset automatically, or did he just leak a surface and replaced the application surface with surfa?
 
Something feels odd about this code. Why can he leave without resetting the target to the application surface after the second shader?
Because he reset the target after the first shader and didn't set a new target for the second shader. So if that code would be in a normal draw event, GMS would draw the surface "surfa" back to the application surface.
But since he's most likely in the post draw or even a draw gui event, GMS will draw to the back buffer - which is kinda like drawing to the screen.
 
Top