• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

SOLVED Surface with shaders displaying blank window

Greetings developers!

Recently I was playing with surfaces and shaders and I've managed to create (by following some tutorials) a simple lighting system with some shaders. It worked perfectly on my demo project but when I tried to apply it to my main project it didnt work at all... I don't usually ask for help but this is something I really wan't to get a hold of since surfaces are going to be big all future projects.

Drawing application_surface draws blank window with my HUD on top.
If I draw the lighting surface it draws on top of the application_surface and it displays black background with bright lights in the right spots where they're suppose to be.

I'm clearly missing some basic understanding of surfaces... Any hints on what could be wrong?
Thanks a bunch!

o_light_controller
Create:

GML:
lighting = surface_create(view_wview,view_hview);
Draw GUI:
GML:
surface_set_target(lighting);
draw_set_color(c_black);
draw_rectangle(0,0,room_width,room_height,false);

draw_set_blend_mode(bm_add);
// Lights
with(o_light) {
    draw_circle_colour((x - view_xview)*(display_get_gui_width()/view_wview),(y - view_yview)*(display_get_gui_height()/view_hview),radius,col,c_black,false);
}
draw_set_blend_mode(bm_normal);
surface_reset_target();

//Drawing the Shader on the Application surface
shader_set(sh_lighting);

var tex = surface_get_texture(lighting);
var handle = shader_get_sampler_index(sh_lighting,"lighting");
texture_set_stage(handle,tex);

draw_surface(application_surface,0,0);
//draw_surface(lighting,-500,0); // Drawing the surface on top of application_surface with 500px offset

shader_reset();
Shader
Fragment:

GML:
varying vec2 v_vTexcoord;
varying vec4 v_vColour;

uniform sampler2D lighting;
void main()
{
    vec4 mult = texture2D(lighting, v_vTexcoord);
    vec4 main = texture2D(gm_BaseTexture, v_vTexcoord);
    vec4 finalcol;
vec4 lightcol;


lightcol.r = mult.r * 2.5;
lightcol.b = mult.b * 2.5;
lightcol.g = mult.g * 2.5;


finalcol.r = mix(main.r,main.r*lightcol.r,mult.r);
finalcol.g = mix(main.g,main.g*lightcol.g,mult.g);
finalcol.b = mix(main.b,main.b*lightcol.b,mult.b);
finalcol.a = 1.;

//You can set the overall darkness of the shader here. 0 = transparent, 1 = black.
float darkness = .7;

finalcol.r = mix(finalcol.r,finalcol.r*darkness,1.-mult.r);
finalcol.g = mix(finalcol.g,finalcol.g*darkness,1.-mult.g);
finalcol.b = mix(finalcol.b,finalcol.b*darkness,1.-mult.b);
           
    gl_FragColor = finalcol;
}
 

sp202

Member
Can't see an issue with that code, must be an issue elsewhere if the application_surface is showing up blank.
 
Can't see an issue with that code, must be an issue elsewhere if the application_surface is showing up blank.
Thank you for the reply. It's working now, the problem was some other surface I use to blur the background when in main menu... It's using and drawing it's own surface (not the application) with blur shader and I'm guessing that means the application_surface is no longer used or something like that?
 
Top