//Circle Precision
draw_set_circle_precision(128);
//Surface
surf_final_light = -1;
surf_particles = -1;
final_light_alpha = 0.95;
//Shader Light
uni_sh_color = shader_get_uniform( sh_lighten, "shadow_color");
array_shadow_color = array_create(4, 0);
array_shadow_color[3] = image_alpha; //Alpha
array_shadow_color[0] = color_get_red(image_blend) *0.003921568; //Red
array_shadow_color[1] = color_get_green(image_blend) *0.003921568; //Green
array_shadow_color[2] = color_get_blue(image_blend) *0.003921568; //Blue
//Set alpha again
image_alpha = 1;
//Particles
part_sys = part_system_create();
part_system_automatic_draw(part_sys, false);
scr_initialize_particle_system();
array_particle_mask = array_create(4, 0);
array_particle_mask[3] = 1;
//Shader Gaussian Blur
uni_v_resolution_h = shader_get_uniform(sh_gaussian_blur_h,"v_resolution");
uni_v_resolution_v = shader_get_uniform(sh_gaussian_blur_v,"v_resolution");
uni_v_blur_intensity_h = shader_get_uniform(sh_gaussian_blur_h,"v_blur_intensity");
uni_v_blur_intensity_v = shader_get_uniform(sh_gaussian_blur_v,"v_blur_intensity");
surf_aux_blur = -1;
//Creating Instances
instance_create_depth( x, y, light_depth, obj_uls_light_renderer);
instance_create_depth( x, y, shadow_depth, obj_uls_shadow_renderer);
//Particles
if (surf_particles)
{
var cam_id = view_get_camera(view_current);
var cam_x = camera_get_view_x(cam_id);
var cam_y = camera_get_view_y(cam_id);
var cam_w = camera_get_view_width(cam_id);
var cam_h = camera_get_view_height(cam_id);
part_particles_create(part_sys, cam_x + random(cam_w), cam_y + random(cam_h*0.75), part_dust_light, choose(0.5,0.75,1));
//part_particles_create(part_sys, 15 , 15, part_dust_light, choose(2,3));
}
//Applying into the final surface
var cam_id = view_get_camera(view_current);
if( !surface_exists(surf_final_light) )
{
surf_final_light = surface_create( camera_get_view_width(cam_id), camera_get_view_height(cam_id));
}
//Draw
surface_set_target(surf_final_light);
draw_clear_alpha(0,1);
gpu_set_blendmode(bm_add);
with(obj_uls_light)
{
//Check
if (Visible and visible)
{
//Get cam
var cam_id = view_get_camera(view_current);
//Draw
if (surface_exists(light_surf))
{
draw_surface_ext( light_surf, x - (surface_get_width(light_surf)*0.5) - camera_get_view_x(cam_id), y - (surface_get_height(light_surf)*0.5) - camera_get_view_y(cam_id), 1, 1, 0, image_blend, image_alpha);
}
}
}
gpu_set_blendmode(bm_normal);
surface_reset_target();
//Check blur effect
if (blur_effect_intensity > 0)
{
//Aux surface
if( !surface_exists(surf_aux_blur) )
{
surf_aux_blur = surface_create( camera_get_view_width(cam_id), camera_get_view_height(cam_id));
}
//Resolution gather
var v_res_w = surface_get_width(surf_final_light);
var v_res_h = surface_get_height(surf_final_light);
//Horizontal
surface_set_target(surf_aux_blur);
shader_set(sh_gaussian_blur_h);
shader_set_uniform_f(uni_v_resolution_h, v_res_w, v_res_h);
shader_set_uniform_f(uni_v_blur_intensity_h, blur_effect_intensity);
draw_surface(surf_final_light, 0, 0);
shader_reset();
surface_reset_target();
//Vertical
surface_set_target(surf_final_light);
shader_set(sh_gaussian_blur_v);
shader_set_uniform_f(uni_v_resolution_v, v_res_w, v_res_h);
shader_set_uniform_f(uni_v_blur_intensity_v, blur_effect_intensity);
draw_surface(surf_aux_blur, 0, 0);
shader_reset();
surface_reset_target();
}
//Draw particles
if (particle_layer)
{
//Check
if( !surface_exists(surf_particles) )
{
surf_particles = surface_create( camera_get_view_width(cam_id), camera_get_view_height(cam_id));
}
//Start
surface_set_target(surf_particles);
draw_clear_alpha(0,0);
//Draw
part_system_position(part_sys, - camera_get_view_x(cam_id), - camera_get_view_y(cam_id));
part_system_drawit(part_sys);
//Mask
gpu_set_blendmode(bm_subtract);
shader_set(sh_lighten)
shader_set_uniform_f_array(uni_sh_color, array_particle_mask);
draw_surface_ext( surf_final_light, 0, 0, 1, 1, 0, -1, 1);
shader_reset();
gpu_set_blendmode(bm_normal);
//End
surface_reset_target();
}
//Clean Surface
if (surface_exists(surf_final_light))
{
surface_free(surf_final_light);
}
if (surface_exists(surf_particles))
{
surface_free(surf_particles);
}
if (surface_exists(surf_aux_blur))
{
surface_free(surf_aux_blur);
}
//Clean particle system
part_system_destroy(part_sys);
//Destroy Each Light
with(obj_uls_light)
{
instance_destroy();
}
//Destroy aux
with(obj_uls_light_renderer)
{
instance_destroy();
}
with(obj_uls_shadow_renderer)
{
instance_destroy();
}
//
// Simple passthrough vertex shader
//
attribute vec3 in_Position; // (x,y,z)
//attribute vec3 in_Normal; // (x,y,z) unused in this shader.
attribute vec4 in_Colour; // (r,g,b,a)
attribute vec2 in_TextureCoord; // (u,v)
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
void main()
{
vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
v_vColour = in_Colour;
v_vTexcoord = in_TextureCoord;
}
//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec4 shadow_color;
void main()
{
//Get Color
vec4 col = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord );
//Discoverying how lighten the color is
float cMin = min( col.r, min( col.g, col.b ) );
float cMax = max( col.r, max( col.g, col.b ) );
float l = ( cMax + cMin ) / 2.0;
//Return
gl_FragColor = vec4( shadow_color.r, shadow_color.g, shadow_color.b, pow( 1.0 - l, 3.0) * shadow_color.a);
}
Couldn't you just draw them in the Draw GUI Event? If the shader is being applied in the Draw Event then the Draw GUI Event won't be affected by the shaders dark magic.
display_get_gui_width()
, display_get_gui_height()
instead of using room coordinates (to convert from room to GUI coordinates, the calculation is simply x-camera_x
and y-camera_y
with camera_x and y being the x and y coordinates of your camera, obviously), so you might have to do some calculations to position stuff properly (also, to get the mouse position in the GUI layer, it's device_mouse_x_to_gui(0)
and device_mouse_y_to_gui(0)
rather than mouse_x
and mouse_y
).