Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Pigment Mixing Function

Author
Message
Libervurto
13
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 6th Jun 2013 03:13
This function mixes two colours as if they were pigments (as in paint or ink) rather than light sources.


The difficulty in learning is not acquiring new knowledge but relinquishing the old.
Latch
13
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 6th Jun 2013 05:06
Neat. It's like an alpha blending routine.

Enjoy your day.
Libervurto
13
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 6th Jun 2013 06:27 Edited at: 6th Jun 2013 07:17
Hi Latch. You're right, I hadn't thought of it like that but it makes a lot of sense.

hmm... turns out it's the same as


I think I have this slightly wrong, I'm pretty sure magenta+yellow is supposed to make a primary red. Oh well, I'll just call this an alpha-transparency function for now.

Yeah I thought so, this is what I want:


I think it's just an AND... I'll try it. I think I actually tried this first but found difficulty getting different ratios, that's why I tried a negative OR, but it seems that was useless.

Inverting one of the colours and subtracting it from the other seems to have the same effect so maybe that's workable.

No that's not right, neither are right. White + Black would be Black instead of Grey like it should be. Ahh! This is harder than it looks.

The difficulty in learning is not acquiring new knowledge but relinquishing the old.
Silverman
12
Years of Service
User Offline
Joined: 18th Jan 2007
Location: France
Posted: 6th Jun 2013 08:47 Edited at: 6th Jun 2013 12:27
hi,
(I was wrong in this post, I re-edited)
If you want to find a solution by itself, does not look the snippet!




DirectX 9.0c (February 2010)/ DBClassic v1.20
Pincho Paxton
16
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 6th Jun 2013 12:13 Edited at: 6th Jun 2013 12:15
Magenta and yellow do make red if the paint is pure enough. I was watching an advert on TV where paint is allowed to spill into water, and mix together. It looks like lumpy clouds of colour. I wanted to make something like that in DBP. I don't know if it is possible in 3D however.

Libervurto
13
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 6th Jun 2013 19:00 Edited at: 7th Jun 2013 02:59
@Silverman - Thanks, I'll hold back from reading your solution but good to know it is there.

The trouble I'm having is it seems like the algorithm changes depending on the colours mixed. If we say that n is the maximum value for each component of RGB:

Magenta = n 0 n
+
Yellow = n n 0
=
Red = n 0 0


It's a simple & comparison. But look at this:

Red = n 0 0
+
Yellow = n n 0
=
Orange = n n/2 0


Why is the green element not discarded like it was in the previous example?

@Silverman - I had a look at your code but it has the same problem I mentioned above. It mixes magenta+yellow=red but it cannot mix red+yellow=orange.


I've made a colour mixing diagram that might help:



The difficulty in learning is not acquiring new knowledge but relinquishing the old.

Attachments

Login to view attachments
Libervurto
13
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 7th Jun 2013 03:26 Edited at: 7th Jun 2013 09:16
[edit: Removed the older versions of the function]
This is as streamlined as I can get it: (I changed the intensity value to an integer from 0 to 255)

I really don't understand why the mixLight function is messing up, it looks like it should work perfectly.

You may have noticed that I stumbled across a simple way to limit the brightness of a colour:


[edit]
Bugger, mixPigment still not working quite as it should. I tested Ped + Yellow and it gives Red.

[edit]
FINALLY! Wow that was surprisingly challenging. This can probably be simplified but it works just like paints:


The difficulty in learning is not acquiring new knowledge but relinquishing the old.
Pincho Paxton
16
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 7th Jun 2013 15:16
I tried to test it in DBPro but it doesn't like & sign for some reason.

Libervurto
13
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 7th Jun 2013 20:08
@Pincho - DBP uses double symbols for bitwise comparisons, so && and ||.

The difficulty in learning is not acquiring new knowledge but relinquishing the old.
Pincho Paxton
16
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 7th Jun 2013 20:13
OK thanks!

Silverman
12
Years of Service
User Offline
Joined: 18th Jan 2007
Location: France
Posted: 9th Jun 2013 12:34
I made it like this:


What's going on there if you makes: color = yellow + cyan, followed by: color = color + magenta ?
naturally white, but I'm not sure of the result with your code (and mine too). I think there is still something to improve(with mine )

DirectX 9.0c (February 2010)/ DBClassic v1.20
Libervurto
13
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 9th Jun 2013 22:25
@Silverman - C+Y+M should be black when mixing pigments or white when mixing light.

The difficulty in learning is not acquiring new knowledge but relinquishing the old.

Login to post a reply

Server time is: 2019-08-22 06:36:06
Your offset time is: 2019-08-22 06:36:06