GMS 2 Light shader

Discussion in 'Programming' started by NNNIKKI, Dec 9, 2018.

Tags:
  1. NNNIKKI

    NNNIKKI Member

    Joined:
    Apr 9, 2018
    Posts:
    40
    I wanted to make a shader for hovering over buttons, which made them lighter.

    v_vColour = vec4(in_Colour.r + 128, in_Colour.g + 128, in_Colour.b + 128, in_Colour.a);

    For some reason I can't use "+"-es.
    WHY?!?!!?
     
  2. Paskaler

    Paskaler Member

    Joined:
    Jul 4, 2016
    Posts:
    315
    The RGB values might be floating point numbers here. If it is so, the range goes from 0.0f to 1.0f, maybe try putting 0.5f instead. The 'f' might not be needed, so try putting numbers in without it, too.
     
  3. Jordan Robinson

    Jordan Robinson Member

    Joined:
    Jun 22, 2016
    Posts:
    86
    Also if you are adding 128 to a floating point value, you would need to add it as 128.0 otherwise it is an integer
     
  4. NNNIKKI

    NNNIKKI Member

    Joined:
    Apr 9, 2018
    Posts:
    40
    I replaced 128 with 128.0 and it works.

    Edit: Actually, what was black stayed black, but I solved the problem by replacing all black with R1 G1 B1.
     
    Last edited: Dec 18, 2018
  5. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,035
    Sounds like you solved this, but another easy way to 'highlight' a sprite, is to simply draw it over itself at reduced alpha with additive blendmode. Probably slower than a shader though. Example:

    Code:
    
    draw_self();
    if (selected) {
        gpu_set_blendmode(bm_add);
        draw_sprite_ext(sprite_index, image_index, x, y, image_xscale, image_yscale, image_angle, image_blend, image_alpha * 0.5);
        gpu_set_blendmode(bm_normal);
    }
    
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice