S
Slothagami
Guest
I have been battling with the shadows in my games for quite a while now and can't seem to do this myself,
I want to have shadows for each object, in the shape of their object, and using a different color based on the color behind the shadow (to fit with the color palette) I am very new to shaders and don't know how I might do this, or if I even need a shader for this. I want to avoid just having a surface with the shadow's making the pixels x% darker, this game is more art focused so I want the shadow colors to have the hue shifting from my color pallet so that it matches the other sprites I've drawn.
This is the desired result:
The sprite's shadow is over two colors and I have a custom shadow color for each I would like to use.
If possible I would also like it to obey the depth like in the second picture (not as important).
Thanks in advance!
I want to have shadows for each object, in the shape of their object, and using a different color based on the color behind the shadow (to fit with the color palette) I am very new to shaders and don't know how I might do this, or if I even need a shader for this. I want to avoid just having a surface with the shadow's making the pixels x% darker, this game is more art focused so I want the shadow colors to have the hue shifting from my color pallet so that it matches the other sprites I've drawn.
This is the desired result:
The sprite's shadow is over two colors and I have a custom shadow color for each I would like to use.
If possible I would also like it to obey the depth like in the second picture (not as important).
Thanks in advance!
The Final result in game:
GML:
// The shader
// the vertex shader has not been changed
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform sampler2D alpha_mask;
void main()
{
vec4 color = texture2D( gm_BaseTexture, v_vTexcoord );
vec4 mask = texture2D( alpha_mask, v_vTexcoord );
if(color == vec4(0.6, 0.756862745, 0.505882353, mask.a)) // green
color = vec4(0.2578125, 0.6, 0.576470588, mask.a);
if(color == vec4(vec3(0.388235294), mask.a)) // grey
color = vec4(vec2(0.207843137), 0.231372549, mask.a);
// add other colors here as needed
// color is vec4(red / 255, green / 255, blue / 255, 1)
gl_FragColor = color;
}
GML:
// Draw GUI Begin Event
surface_set_target(shadow_surf);
draw_clear_alpha(c_black, 0);
shader_set(shd_white);
with all {
if sprite_exists(sprite_index) and visible {
var
cx = camera_get_view_x(view_camera[0]),
cy = camera_get_view_y(view_camera[0]),
cw = camera_get_view_width(view_camera[0]),
ch = camera_get_view_height(view_camera[0]),
scale = GUI_W / cw;
if x <= cx + cw and x + sprite_width >= cx {// if x on screen
if y <= cy + ch and y + sprite_width >= cy {//if y on screen
draw_sprite_ext(sprite_index, image_index, (x - cx) * scale, (y - cy) * scale, scale, -scale, 0, c_purple, 0.2);
}
}
}
}
shader_reset();
surface_reset_target();
var
texture = surface_get_texture(shadow_surf),
sampler = shader_get_sampler_index(shd_shadowcolors, "alpha_mask");
shader_set(shd_shadowcolors);
// send the shadow_surf to the shader as the alpha mask
texture_set_stage(sampler, texture);
draw_surface(application_surface, 0, 0);
shader_reset();
Last edited by a moderator: