Legacy GM Issue using colors with Shaders

C

comatsu

Guest
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?
 

jo-thijs

Member
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.
 
C

comatsu

Guest
Ooops - just wrote that code from memory.
Using the correct function in GMS
 
B

Braffolk

Guest
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);
 
C

comatsu

Guest
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.
 

jo-thijs

Member
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.
 
Top