1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GM:S 1.4 Issue using colors with Shaders

Discussion in 'Programming' started by comatsu, Jun 25, 2016.

  1. comatsu

    comatsu Member

    Joined:
    Jun 20, 2016
    Posts:
    22
    I've made a shader which tints a sprite with a selected color. So far I am passing the tint color to the shader with this code:

    Code:
    var col = c_yellow;
    col_r = colour_get_red(col);
    col_g = colour_get_green(col);
    col_b = colour_get_blue(col);
    and

    Code:
    shader_set_uniform_f(tint_color,col_r,col_g,col_b,1.0);
    However now I am trying to set the tint to a color of my choosing, and have changed the first line above (var col = c_yellow) to the following:

    Code:
    var col = color_make_rgb(115,51,212);
    I am leaving the rest exactly the same. For some reason, this code does not work, resulting in the sprite being drawn as white, whatever color I set. I've tried using other preset colors (c_red, c_blue etc) and they all work fine, however any color I try to create does not work.

    Any thoughts on what I am missing?
     
  2. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,844
    I'm not sure why yo use color_make_rgb and don't get an error,
    while the actual function you want to use is make_colo(u)r_rgb.
     
  3. comatsu

    comatsu Member

    Joined:
    Jun 20, 2016
    Posts:
    22
    Ooops - just wrote that code from memory.
    Using the correct function in GMS
     
  4. Braffolk

    Braffolk Member

    Joined:
    Jun 20, 2016
    Posts:
    51
    If I remember correctly, the colour has to be in a range of 0-1. So simply divide those colours with 255.
    Code:
    shader_set_uniform_f(tint_color,col_r/255,col_g/255,col_b/255,1.0);
     
    jo-thijs likes this.
  5. comatsu

    comatsu Member

    Joined:
    Jun 20, 2016
    Posts:
    22
    I've been trying to figure this out for over 2 hours now! This was it - thanks a lot.

    How come the values are returned correctly when using a preset color though?
    Using show_message(color_get_blue(c_blue)) and show_message(color_get_blue(col)) shows the same value, despite only the former working fine with the shader.
     
  6. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,844
    It works for c_blue, because it has the value 0 as red and green components and the maximal value for the blue component.
    This will make it work well for c_red, c_green, c_yellow and whatever cyan and magenta are.
    Other values, like c_gray and c_maroon and such should also be treated wrongly.
     

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