• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Shaders Shader to lighten or darken a sprite?

J

JapanGamer29

Guest
Hi all, I've been using image_blend to highlight puzzle pieces in my game, but it only works well with some colors, not others.

I have a grayscale shader which I found here ages ago, and I'm able to change the values so that it lightens or darkens, but I can't figure out how to remove the graying.

It would be great to adapt this or get something similar that keeps the color and just changes the brightness. Can anyone help? Thanks.

GML:
//shadGrayScale.vsh
attribute vec4 in_Position;
attribute vec2 in_TextureCoord;
varying vec2 vTc;
void main() {
  gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * in_Position;
  vTc = in_TextureCoord;
}

//shadGrayScale.fsh
varying vec2 vTc;
void main() {
  vec4 irgba=texture2D(gm_BaseTexture,vTc);
  float luminance=dot(irgba.rgb,vec3(0.2125,0.7154,0.0721));
  gl_FragColor=vec4(luminance,luminance,luminance,irgba.a);
}

// Draw event in my object
if (shader_is_compiled(shadGrayScale))
{
   shader_set(shadGrayScale);
   draw_self();
   shader_reset();
}
 
Last edited:
J

JapanGamer29

Guest
Sweet! Great video, and it works great! I'll post the code here for anyone who stumbles on this thread.

GML:
// obj_brightness Create
shader = shd_brightness;
u_brightness = shader_get_uniform(shader, "brightness");

// obj_brightness Draw
var brightness = 0.5 // range -1 to +1
shader_set(shader);
shader_set_uniform_f(u_brightness, brightness);
draw_self(); // make sure obj_brightness has a sprite
shader_reset();

// shd_brightness.fsh
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform float brightness;
void main()
{
    vec4 base_col = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord );
    gl_FragColor = vec4(base_col.rgb + brightness, base_col.a);
}
 

Deb;

Member
I found an even easier way of doing that without a shader
Just put this in the "Draw end" script:
GML:
draw_sprite_ext(spr_sprite_you_want_to_lighten/darken, 0, x, y, image_xscale, image_yscale, image_angle, c_black, brightness)
 
Top