Z
zendraw
Guest
so we have a regular sprite with color, but we draw it with blend modes to be all white.
can blend modes do that or do i need to make a shader?
can blend modes do that or do i need to make a shader?
var x2, y2;
x2 = x + sprite_get_width(spr_sprite);
y2 = y + sprite_get_height(spr_sprite);
//you can do this on a surface to manage it
draw_clear_alpha(c_black, 0);
draw_sprite(spr_sprite, 0, x, y);
gpu_set_blendmode_ext(bm_dest_alpha, bm_one);
draw_set_color(c_white);
draw_rectangle(x, y, x2, y2, false);
gpu_set_blendmode(bm_normal);
that turns the whole screen black for some reason.You can actually do it with blendmodes, using something like this:
You can play around with the different blendmodes in the gpu_set_blendmode_ext() function, but I think this one works for what you want.GML:var x2, y2; x2 = x + sprite_get_width(spr_sprite); y2 = y + sprite_get_height(spr_sprite); //you can do this on a surface to manage it draw_clear_alpha(c_black, 0); draw_sprite(spr_sprite, 0, x, y); gpu_set_blendmode_ext(bm_dest_alpha, bm_one); draw_set_color(c_white); draw_rectangle(x, y, x2, y2, false); gpu_set_blendmode(bm_normal);
draw_clear_alpha(c_black, 0);
draw_sprite_ext(costume, -1, x, y, image_xscale, image_yscale, 0, -1, 1);
gpu_set_blendmode_ext(bm_dest_alpha, bm_one);
draw_set_color(c_white);
draw_rectangle(bbox_left, bbox_top, bbox_right, bbox_bottom, false);
gpu_set_blendmode(bm_normal);
main
function with this:gl_FragColor = vec4(vec3(1.0), texture2D(gm_BaseTexture, v_vTexcoord).a);
so i want to controll the amount of whiteness. im not sure if i just add a value 0 to 1 will that break the color, like if red ends up 1.4 or are they clamped betwean 0-1 by default.In case you want the shader solution, it's extremely simple. All you need to do is create a new shader asset, go to the fragment shader (the .fsh window), and replace the one line of code in themain
function with this:
Code:gl_FragColor = vec4(vec3(1.0), texture2D(gm_BaseTexture, v_vTexcoord).a);
Colors in shaders are clamped 0.0-1.0. 0.0 = 0 (obviously) and 1.0 = 255. You'd have to modify the shader a bit if you want to get that effect, but the easier solution would be:so i want to controll the amount of whiteness. im not sure if i just add a value 0 to 1 will that break the color, like if red ends up 1.4 or are they clamped betwean 0-1 by default.
// In fragment shader
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform float WhiteBlend;
void main()
{
vec4 Base = texture2D(gm_BaseTexture, v_vTexcoord);
vec3 White = vec3(WhiteBlend);
vec4 BlendedColor = vec4(Base.rgb + White.rgb, Base.a);
gl_FragColor = BlendedColor;
}
// Create event of object drawing sprite
uWhiteBlend = shader_get_uniform(shd, "WhiteBlend");
// Draw event
var blendFactor = 0.5; // Just here for testing, you can modify this from elsewhere
shader_set(shd_white);
shader_set_uniform_f(uWhiteBlend, blendFactor);
draw_sprite(sprSprite, 0, x, y);
shader_reset();
the shader replaces the alpha aswell.Colors in shaders are clamped 0.0-1.0. 0.0 = 0 (obviously) and 1.0 = 255. You'd have to modify the shader a bit if you want to get that effect, but the easier solution would be:
EDIT: Fragment shader solution:
- Draw normally the sprite you want to blend white
- Draw a duplicate of the sprite you want to blend white with the shader I posted
- Start with duplicate's alpha at 0 and increase it the more you want it white
Code:// In fragment shader varying vec2 v_vTexcoord; varying vec4 v_vColour; uniform float WhiteBlend; void main() { vec4 Base = texture2D(gm_BaseTexture, v_vTexcoord); vec3 White = vec3(WhiteBlend); vec4 BlendedColor = vec4(Base.rgb + White.rgb, Base.a); gl_FragColor = BlendedColor; }
GML:// Create event of object drawing sprite uWhiteBlend = shader_get_uniform(shd, "WhiteBlend"); // Draw event var blendFactor = 0.5; // Just here for testing, you can modify this from elsewhere shader_set(shd_white); shader_set_uniform_f(uWhiteBlend, blendFactor); draw_sprite(sprSprite, 0, x, y); shader_reset();