Legacy GM How can I apply multiple shaders on the application_surface?

C

Ceymoonie

Guest
I've been trying for about a week now, but I just can't find a working solution. The easiest way seems to be surface stacking, so this:

Code:
surface_set_target(rgbSurface);
shader_set(shRGB);

    draw_set_blend_mode_ext(bm_one, bm_inv_src_color);
    draw_surface_ext(application_surface, modX + 0, modY + 0, crt_surface_scale, crt_surface_scale, 0, c_white, 1);
    draw_set_blend_mode(bm_normal);
   
shader_reset();
surface_reset_target();


surface_set_target(crtSurface);
shader_set(shCRT);

    shader_set_uniform_f(uni_crt_sizes, surface_width, surface_height,crt_surface_width, crt_surface_height);
    shader_set_uniform_f(distort, var_distort);
    shader_set_uniform_f(distortion, var_distortion_ammount);
    shader_set_uniform_f(border, var_border);
    draw_surface_ext(rgbSurface, modX + 0, modY + 0, crt_surface_scale, crt_surface_scale, 0, c_white, 1);
   
shader_reset();
surface_reset_target();

draw_surface(crtSurface, 0, 0);
But that just results in a white screen.

The next thing I did was the obvious, combining the two shaders. However, I got stuck at this part:

Code:
    gl_FragColor = vec4(mul_res, 1.0);

    gl_FragColor.r = (v_vColour * texture2D(gm_BaseTexture, vec2(newcoordx.r, newcoordy.r))).r;
    gl_FragColor.g = (v_vColour * texture2D(gm_BaseTexture, vec2(newcoordx.g, newcoordy.g + offset))).g;
    gl_FragColor.b = (v_vColour * texture2D(gm_BaseTexture, vec2(newcoordx.b, newcoordy.b))).b;
The first line comes from the CRT shader, and the column comes from the RGB-shift shader. But instead of combining them, all this does is choose the shader at the bottom.

I don't want to make this post too bulky, so I'll leave it at that. Please tell me if you have any more ideas.
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
Code:
gl_FragColor = vec4(mul_res, 1.0); gl_FragColor.r = (v_vColour * texture2D(gm_BaseTexture, vec2(newcoordx.r, newcoordy.r))).r; gl_FragColor.g = (v_vColour * texture2D(gm_BaseTexture, vec2(newcoordx.g, newcoordy.g + offset))).g; gl_FragColor.b = (v_vColour * texture2D(gm_BaseTexture, vec2(newcoordx.b, newcoordy.b))).b;
The first line comes from the CRT shader, and the column comes from the RGB-shift shader. But instead of combining them, all this does is choose the shader at the bottom.
It would likely need to be like
Code:
    gl_FragColor.r = (mul_res.r * v_vColour * texture2D(gm_BaseTexture, vec2(newcoordx.r, newcoordy.r))).r;
    gl_FragColor.g = (mul_res.g * v_vColour * texture2D(gm_BaseTexture, vec2(newcoordx.g, newcoordy.g + offset))).g;
    gl_FragColor.b = (mul_res.b * v_vColour * texture2D(gm_BaseTexture, vec2(newcoordx.b, newcoordy.b))).b;
 
C

Ceymoonie

Guest
Thanks, but without the original
Code:
gl_FragColor = vec4(mul_res, 1.0);
, it results in a black screen. And when it is added to the beginning of the code, it draws the screen twice; once with the CRT distort effect, and once with the RGB-shift effect.
 
C

Ceymoonie

Guest
I finally found a solution. I used the shader-stacking technique I mentioned above, but ended it with
Code:
surface_resize(rgbSurface, view_wport, view_hport);
, I have no idea why this works, but it works.
 
Top