Y
yeahbuddy28
Guest
So I have a cursor object and when it hovers over any object that is a child of "selectable" I want the object to have a outline around it. The way I would like to accomplish this is through a with statement located in the cursor object that applies a shader to the object it is hovering over. This is my first time working with shaders so I really just kinda copied stuff from this video. The code I have in the cursors step event is as follows
The code for the fragment part of the outline shader is as follows
When I hover the cursor over the object nothing happens, I think the reason may be that part of the code in the with statement is supposed to be done in a draw event, however i'm not sure how to use a draw event when I am accessing the object through a with statement. Also I am on gamemaker 1.4.
Code:
///behavior
//stay with mouse
x = mouse_x
y = mouse_y
//selecting objects
var selected = instance_place(x,y,selectable)
with (selected){
upixelH = shader_get_uniform(shader_outline_1, "pixelH");
upixelW = shader_get_uniform(shader_outline_1, "pixelW");
texelW = texture_get_texel_width(sprite_get_texture(sprite_index,0));
texelH = texture_get_texel_height(sprite_get_texture(sprite_index,0));
//this part is supposed to be in a draw event I think
shader_set(shader_outline_1);
shader_set_uniform_f(upixelW, texelW);
shader_set_uniform_f(upixelH, texelH);
draw_self();
shader_reset();
}
Code:
//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform float pixelH;
uniform float pixelW;
void main()
{
vec2 offsetx;
offsetx.x = pixelW;
vec2 offsety;
offsety.y = pixelH;
float alpha = texture2D(gm_BaseTexture, v_vTexcoord).a;
alpha = max(alpha, texture2D(gm_BaseTexture, v_vTexcoord + offsetx).a);
alpha = max(alpha, texture2D(gm_BaseTexture, v_vTexcoord - offsetx).a);
alpha = max(alpha, texture2D(gm_BaseTexture, v_vTexcoord + offsety).a);
alpha = max(alpha, texture2D(gm_BaseTexture, v_vTexcoord - offsety).a);
gl_FragColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord );
gl_FragColor.a = alpha;
}