• 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!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code [SOLVED] blend colours as paint blend

Y

yoyowan

Guest
Trying to blend colours of simple shapes like this :

// set colour
colour1 = make_colour_rgb(0,255,255); // cyan
colour2 = make_colour_rgb(255,255,0); // yellow

// draw circle 1 cyan (I would prefer blue)
gpu_set_blendmode_ext(bm_dest_colour,bm_zero);
draw_circle_colour(x,y,global.size_b,colour1,colour1,false);
gpu_set_blendmode(bm_normal);

// draw circle 2 yellow
gpu_set_blendmode_ext(bm_dest_colour,bm_zero);
draw_circle_colour(x,y,global.size_b,colour2,colour2,false);
gpu_set_blendmode(bm_normal);

Here when I blend the two circles : cyan + yellow = green (what I am looking for)
BUT it is not working as paint blend with other colours...

I would like to have a unique method to have the blends dealing with paint that is :

blue (not cyan) + yellow = green
red + blue = purple
red + yellow = orange

white or black background

thanks for helping me finding a neat solution to this problem ;)

(I have taken some time on gpu_set_blendmode_ext function and this excellent article https://www.yoyogames.com/blog/57/explaining-blend-modes-part-2 but my conclusion is that it is not possible this way...)
 
Last edited by a moderator:
Y

yoyowan

Guest
try to explain the mathematical way :

for example cyan + yellow = green

cyan is RGB (0,255,255) and yellow is RGB (255,255,0) now converted to 0 - 1 it gives :
cyan (0,1,1) and yellow (1,1,0)

I use gpu_set_blendmode_ext(bm_dest_colour,bm_zero) that is

(Rs,Gs,Bs,As)*(Rd,Gd,Bd,Ad)+(Rd,Gd,Bd,Ad)*(0,0,0,0) = (Rs,Gs,Bs,As)*(Rd,Gd,Bd,Ad)
Source color * dest color + dest color * zero = source color * dest color

so (0,1,1) * (1,1,0) = (0,1,0) GREEN

if I keep this mode and try red + blue :

(1,0,0) * (0,0,1) = (0,0,0) BLACK
 
Y

yoyowan

Guest
an image of what I am trying to do :

 
Last edited by a moderator:
Y

yoyowan

Guest
Is it not subtractive blending that you want?
kind of...
In pure substractive blending cyan + yellow = green
I would like blue + yellow = green

In pure substractive blending red + blue = black
I would like red + blue = purple
 
Last edited by a moderator:
Y

yoyowan

Guest
Thanks sp202 but I have clarified a little bit see :

kind of...
In pure substractive blending cyan + yellow = green
I would like blue + yellow = green

In pure substractive blending red + blue = black
I would like red + blue = purple
 
Y

yoyowan

Guest
Ok I solved it my way
I can now blend "2" colours to any colour in realtime. My solution is to add a dummy object under one colour, this object also has a colour and playing with blend modes of the different colors give me the good results.

I can now have pure blue (0,0,255) + pure yellow (255,255,0) = pure green (0,255,0)
 
Y

yoyowan

Guest
I'm interested to know how you did it.
here is my recipe to have pure blue (0,0,255) + pure yellow (255,255,0) = pure green (0,255,0)

the instance order has an influence, from oldest to newest :

1 - draw yellow (255,255,0) with gpu_set_blendmode_ext(var1,var2);
var1 = bm_src_alpha;
var2 = bm_inv_src_alpha;

2 - draw blue (0,0,255) with gpu_set_blendmode_ext(var1,var2);
var1 = bm_zero;
var2 = bm_src_color;

3 - draw green (0,255,0) with gpu_set_blendmode_ext(var1,var2);
var1 = bm_one;
var2 = bm_one;

now make move together yellow.x = green.x and yellow.y = green.y over a white background and voila

You see a pure blue circle and a pure yellow circle that can blend together in a pure green circle.
I have tried other recipes and it is very interesting, you can create the colour blend you want out of 2 colours.
 

sp202

Member
It seems like you're not actually blending the colours but rather painting the intersection of colours with the colour you want?
 
Y

yoyowan

Guest
Yes it is not pure blending but the effect is the one I am looking for. If you have an other solution please feel free to post here ;)
I am sure shader can help but is a little out of my knowledge so far.
 

sp202

Member
Well, for one thing you can replace the different objects with multiple draw calls from within the same object. You can also look into using HSV instead of RGB. Generally the average of two HSV colours is a somewhat bright version of what you'd get if you blended paints together.
 
Y

yoyowan

Guest
Well, for one thing you can replace the different objects with multiple draw calls from within the same object. You can also look into using HSV instead of RGB. Generally the average of two HSV colours is a somewhat bright version of what you'd get if you blended paints together.
Thank you for the feedback sp202
Can you be a bit more specific for multiple draw calls from within the same object ? Will I be able to move the objects ?
For the HSV I have tried the make_color_hsv but I have not seen any differences using gpu_set_blendmode_ext. I assume set_blendmode works only in RGB values, am I right ?
 

sp202

Member
Instead of giving each colour its own object, use the blend modes and draw the circles sequentially in the one object.

Here's some code from an older version of GM:
Code:
draw_set_blend_mode_ext(bm_src_alpha,bm_inv_src_alpha)
draw_circle_color(x-16,y,32,col1,col1,false)

draw_set_blend_mode_ext(bm_zero,bm_src_color)
draw_circle_color(x+16,y,32,col2,col2,false)

draw_set_blend_mode_ext(bm_one,bm_one)
draw_circle_color(x-16,y,32,blend,blend,false)
As for whether you'll be able to move the objects, you can position the circles wherever you want in the draw calls obviously, but if you're planning to move them around unpredictably through user input (moving the circles by mouse) then yeah, stick to objects. Otherwise, use the one object with code similar to above.

If you're using the HSV method, you'd have to define the HSV colour yourself. So, in your example, instead of green you'd make the hue of the third colour the average hue of blue and yellow, you'd use colour_get_hue to read the hue of blue and yellow. When defining the third colour in HSV, saturation and value could either be averaged from the two colours to be mixed or you can tweak them to suit the look you want.
 
Top