So I am very new to shaders, and I am working with a free shader from the GMS2 marketplace> Anyways, I have run into an issue with this shader that I guess I am just too new at shaders to be knowledgeable about this. The code for the shader is:
shd_mosaic.vsh:
attribute vec3 in_Position;
attribute vec4 in_Colour;
attribute vec2 in_TextureCoord;
varying vec2 v_texcoord;
void main()
{
gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * vec4(in_Position, 1.0);
v_texcoord = in_TextureCoord;
}
shd_mosaic.fsh:
varying vec2 v_texcoord;
uniform float time;
uniform vec2 mouse_pos;
uniform vec2 resolution;
uniform float pixel_amount;
void main()
{
vec2 res = vec2(1.0, resolution.x/resolution.y);
vec2 size = vec2(res.x/pixel_amount, res.y/pixel_amount);
vec2 uv = v_texcoord - mod(v_texcoord,size);
gl_FragColor = texture2D( gm_BaseTexture, uv );
}
And then I also have my object that manages the shader, obj_controller_mosaic
:
create code:
draw_set_color(c_white);
uni_time = shader_get_uniform(shd_mosaic,"time");
var_time_var = 0;
uni_mouse_pos = shader_get_uniform(shd_mosaic,"mouse_pos");
var_mouse_pos_x = mouse_x - camera_get_view_x(view_get_camera(view_current));
var_mouse_pos_y = mouse_y - camera_get_view_y(view_get_camera(view_current));
uni_resolution = shader_get_uniform(shd_mosaic,"resolution");
var_resolution_x = room_width //camera_get_view_width(view_get_camera(view_current));
var_resolution_y = room_height //camera_get_view_height(view_get_camera(view_current));
uni_pixel_amount = shader_get_uniform(shd_mosaic, "pixel_amount");
var_pixel_amount = 700.0;
shader_enabled = true;
full_screen_effect = true;
surf = surface_create(camera_get_view_width(view_get_camera(view_current)), camera_get_view_height(view_get_camera(view_current)));
view_set_surface_id(view_get_camera(view_current), surf);
DrawGUI code:
var_time_var+=0.04;
var_resolution_x = camera_get_view_width(view_get_camera(view_current));
var_resolution_y = camera_get_view_height(view_get_camera(view_current));
if shader_enabled shader_set(shd_mosaic);
shader_set_uniform_f(uni_time, var_time_var);
shader_set_uniform_f(uni_mouse_pos, var_mouse_pos_x, var_mouse_pos_y);
shader_set_uniform_f(uni_resolution, var_resolution_x, var_resolution_y);
shader_set_uniform_f(uni_pixel_amount, var_pixel_amount);
if full_screen_effect draw_surface(surf, 0, 0);
shader_reset();
Alright, now due to some issues with other objects in the game, I want the DrawGUI code to actually be just in the Draw event. The issue is that when I copy this code over the the Draw event instead, I just get a black screen (when the code is in the DrawGUI event it works fine). Is there something I can do to make this code work in the Draw event instead of DrawGUI? Thanks in advance for your answers!
view_set_surface_id
causes the view to be rendered to a surface. As result, it will not be drawn to the screen automatically - you would have to do so yourself, like you do in Draw GUI.
If you direly need to draw the view in a normal draw event, you'll need a second view and filter based on view_current
in a Draw event.