The Fat Bastid
Member
Hello all,
I have a newbie shader problem in gamemaker2 (2.1.5.246)
I apply a blur shader to my background layer from an object's create event and it looks fine. However, when I call shader_reset() in the object's draw event (to draw something unblurred on top), the background looks funny. The shader is still applied but the effect isn't as sharp. I don't understand what is going on. Code below and thank you!
The background layer is 100, the object's layer is 80.
the object's create event:
the object's draw event:
The blur_on script:
The shader itself:
Standard Vertex shader
Fragment shader
I have a newbie shader problem in gamemaker2 (2.1.5.246)
I apply a blur shader to my background layer from an object's create event and it looks fine. However, when I call shader_reset() in the object's draw event (to draw something unblurred on top), the background looks funny. The shader is still applied but the effect isn't as sharp. I don't understand what is going on. Code below and thank you!
The background layer is 100, the object's layer is 80.
the object's create event:
Code:
layer_script_begin(global.l_background,blur_on)
Code:
shader_reset()
draw_set_halign(fa_middle)
draw_set_valign(fa_center)
draw_set_color(c_black);
draw_text(room_width/2,room_height/2,"<animation of picking up thing>")
Code:
if event_type == ev_draw and event_number == ev_draw_begin
{
shader_set(sha_guassianblur)
}
Standard Vertex shader
Code:
//
// 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;
}
Code:
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
vec3 size = vec3(512,512,8);
//uniform vec3 size;//width,height,radius
const int Quality = 8;
const int Directions = 16;
const float Pi = 6.28318530718;//pi * 2
void main()
{
vec2 radius = size.z/size.xy;
vec4 Color = texture2D( gm_BaseTexture, v_vTexcoord);
for( float d=0.0;d<Pi;d+=Pi/float(Directions) )
{
for( float i=1.0/float(Quality);i<=1.0;i+=1.0/float(Quality) )
{
Color += texture2D( gm_BaseTexture, v_vTexcoord+vec2(cos(d),sin(d))*radius*i);
}
}
Color /= float(Quality)*float(Directions)+1.0;
gl_FragColor = Color * v_vColour;
}
Last edited: