Shaders Help: Converting the shader objects draw GUI event to normal draw event

trentallain

Member
Hi, I need help converting the shader object's draw GUI event into a normal draw event, due to depth issues and the fact that it would take too long to re-code all the HUD to enable the mouse clicking on it.
Here is the code for the object:
Code:
//Create Event:
//execute code:

draw_set_color(c_white);
display_set_gui_maximise(window_get_width()/340,window_get_width()/340)

uni_resolution_hoz = shader_get_uniform(shd_gaussian_horizontal,"resolution");
uni_resolution_vert = shader_get_uniform(shd_gaussian_vertical,"resolution");
var_resolution_x = view_wview;
var_resolution_y = view_hview;

uni_blur_amount_hoz = shader_get_uniform(shd_gaussian_vertical,"blur_amount");
uni_blur_amount_vert = shader_get_uniform(shd_gaussian_horizontal,"blur_amount");
var_blur_amount = 1.0;

shader_enabled = false;
final_surface = surface_create(view_wview,view_hview);

surf = surface_create(view_wview, view_hview);
view_surface_id[0] = surf;

//Draw GUI Event:
//execute code:

if (shader_is_compiled(shd_gaussian_horizontal))
if (shader_is_compiled(shd_gaussian_vertical))
   {
        var_mouse_pos_x = mouse_x - view_xview;
        var_mouse_pos_y = mouse_y - view_yview;
       
        //Do horizontal blur first
        surface_set_target(final_surface);
        if shader_enabled shader_set(shd_gaussian_horizontal);
            shader_set_uniform_f(uni_resolution_hoz, var_resolution_x, var_resolution_y);
            shader_set_uniform_f(uni_blur_amount_hoz, var_blur_amount);
            draw_surface(surf,0,0);
        shader_reset();
        surface_reset_target();
       
        //Do vertical blur last
        if shader_enabled shader_set(shd_gaussian_vertical);
            shader_set_uniform_f(uni_resolution_vert, var_resolution_x, var_resolution_y);
            shader_set_uniform_f(uni_blur_amount_vert, var_blur_amount);
            draw_surface(final_surface,0,0);
        shader_reset();
   }
else show_debug_message("Shader failed");
//Nothing below here ~~~
scr_gamepad_hotbar() //Needs to be drawn above all
if (global.controller_hotbar == true)
{
    shader_enabled = true
}
else shader_enabled = false
PS: The script is fairly irrelevant in what I need help with and the shader code isn't mine.
 

Jaqueta

Member
What is the problem exactly (Screenshots would be nice)?
If you use Post Draw, the problem persist?
 

trentallain

Member
What is the problem exactly (Screenshots would be nice)?
If you use Post Draw, the problem persist?
Here are some screenshots (sorry I use the fullscreen so I had to take a photo)
When I used Post Draw, im pretty sure that would fix the issue, the only problem is that the screen goes 1:1 with the pixels on the computer (at least it looks like it does) and it only display the top half of the view. (The issue is that the GUI layer is above all.)
Draw GUI:
https://goo.gl/photos/yz7Jff47Yunt5iRv7
Post Draw:
https://goo.gl/photos/dGoQ8xP59hzud8du8
 

Jaqueta

Member
Ok, try this these options I'm not sure which will work, so I recommend test them all :v

When creating the surface use the VIEW PORT size,
If it doesn't work, use the application_surface size, you can use surface_get_width and height

I'm pretty sure one of these above will work, but if it doesn't, try this: When drawing the surface, use draw_surface_stretched, using one of the sizes above.
 

trentallain

Member
Ok, try this these options I'm not sure which will work, so I recommend test them all :v

When creating the surface use the VIEW PORT size,
If it doesn't work, use the application_surface size, you can use surface_get_width and height

I'm pretty sure one of these above will work, but if it doesn't, try this: When drawing the surface, use draw_surface_stretched, using one of the sizes above.
Ok, thank you so much!
 

trentallain

Member
Ok, try this these options I'm not sure which will work, so I recommend test them all :v

When creating the surface use the VIEW PORT size,
If it doesn't work, use the application_surface size, you can use surface_get_width and height

I'm pretty sure one of these above will work, but if it doesn't, try this: When drawing the surface, use draw_surface_stretched, using one of the sizes above.
Sorry, I am trying your ideas but I think i'm entering it in wrong :/ (Probably just my interpretation, but its still really small and split in half)
Code:
Create Event:

execute code:

draw_set_color(c_white);
//display_set_gui_maximise(window_get_width()/340,window_get_width()/340)

uni_resolution_hoz = shader_get_uniform(shd_gaussian_horizontal,"resolution");
uni_resolution_vert = shader_get_uniform(shd_gaussian_vertical,"resolution");
var_resolution_x = view_wview; //view_wview,view_hview
var_resolution_y = view_hview;

uni_blur_amount_hoz = shader_get_uniform(shd_gaussian_vertical,"blur_amount");
uni_blur_amount_vert = shader_get_uniform(shd_gaussian_horizontal,"blur_amount");
var_blur_amount = 1.0;

shader_enabled = false;
final_surface = surface_create(view_wport,view_hport); //view_wview,view_hview

surf = surface_create(view_wport, view_hport); //view_wview, view_hview
view_surface_id[0] = surf;
//draw_surface_stretched(surf,0,0,window_get_width()/340,window_get_width()/340)

Post Draw Event:

execute code:

if (shader_is_compiled(shd_gaussian_horizontal))
if (shader_is_compiled(shd_gaussian_vertical))
if (surface_exists(surf))
   {
        //display_set_gui_maximise(window_get_width()/340,window_get_width()/340)
        var_mouse_pos_x = mouse_x - view_xview; //view_xview,view_yview
        var_mouse_pos_y = mouse_y - view_yview;
       
        //Do horizontal blur first
        surface_set_target(final_surface);
        if shader_enabled shader_set(shd_gaussian_horizontal);
            shader_set_uniform_f(uni_resolution_hoz, var_resolution_x, var_resolution_y);
            shader_set_uniform_f(uni_blur_amount_hoz, var_blur_amount);
            draw_surface_stretched(surf,0,0,surface_get_width(surf),surface_get_height(surf));
        shader_reset();
        surface_reset_target();
       
        //Do vertical blur last
        if shader_enabled shader_set(shd_gaussian_vertical);
            shader_set_uniform_f(uni_resolution_vert, var_resolution_x, var_resolution_y);
            shader_set_uniform_f(uni_blur_amount_vert, var_blur_amount);
            draw_surface_stretched(final_surface,0,0,surface_get_width(surf),surface_get_height(surf));
        shader_reset();
   }
else show_debug_message("Shader failed");
//Nothing below here ~~~
scr_gamepad_hotbar() //Needs to be drawn above all
if (global.controller_hotbar == true)
{
    shader_enabled = true
}
else shader_enabled = false;
 

Jaqueta

Member
This is so weird. I'm running out of ideas tbh. :v
When this object is created, the view size is already defined? Things can get messed up if you changed the view_size/app_surface_size during runtime... MAYBE.

Try do some debugging, Draw on the screen, the size of the surface, the size of the view_port...view_size...gui... Everything, maybe with that you'll have an idea of what's going on.
Also, try cleaning the asset cache (Green Broom Icon).
 
Top