• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Legacy GM How to use multiple shaders with passthrough?

D

DeDelner

Guest
Hello again,

new problem ^^"

Since my godrays shader is working, I want to use multiple shaders. The first shader will render the godrays and the second shader will do some processing stuff like vignette. Now my question is, how do I use multiple shaders at once? Like how do I render my godrays first, so that my post process shader can manipulate the rendered image of the godrays with a sampler2D texture and apply it to the application surface?

Maybe I do have to work with custom surfaces? But I honestly didn't get how to work with them (yet).
 
D

DeDelner

Guest
Yeah but then how do I set them up? Especially in which order and which event. And what about the application surface?

aaaaaaaaaaaa *cries*
 

Simon Gust

Member
Calm!
Grab a piece of paper and do some brain-storming.

draw-event:
Code:
shader_set(shader);

var tex = surface_get_texture(surface); // whatever surface it is. Unless it’s the application surface
shader_set_stage(tex);
shader_set_uniform_f(uni_whatever, whatever);

//draw some stuff;

shader_reset();
shader:
Code:
varying vec2 v_vTexcoord;
varying vec4 v_vColour;

uniform sampler2D texture;
unifrom float stuff;

void main()
{
// god rays

// vignette
}
you order it in the shader.
 
D

DeDelner

Guest
"surface_get_texture" actually helped me a little further! But I need to separate my shaders, because I need this in future. However, I think did something wrong with the surfaces, but what? ;~;
Btw I am using the PostDraw event, because it looks like the normal draw event doesn't seem to work at all for me.

 

Simon Gust

Member
post-draw event is a good start but I'm taking a closer look and test it in my own project.
Have you disabled automatic application surface drawing?
Code:
application_surface_draw_enable(false);
 
D

DeDelner

Guest
Basically what I need is a shader been drawn on a surface.
 

Simon Gust

Member
I read the manual and it says that the application render target is reset in this event. So your surface might be drawn too late on it, though the manual drawing of the application surface must be here.
 
D

DeDelner

Guest
Nevermind, I managed to get it to work by my own c:

So basically what I do is I draw the first shader on my surface using "draw_surface(application_surface, 0, 0)". But it is still not visible for the player yet, because it has been drawn on my surface only!
After I reset the surface target, I set the final shader and put the texture of my surface into a sampler2D. And in the final shader I use my surface texture instead of "gm_BaseTexture"! After that I finally use "draw_surface(application_surface, 0, 0)"

Here an example how my PostDraw-Event looks like:
 
Top