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 Professional Discussion / Color that are overlapping finding the new color average help me I'm going nuts.

Author
Message
david w
19
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 20th Dec 2007 02:55
Say you have two colors that overlap. one is red, the other is blue. how can I calculate using RGB values what the new color should be at the point where they overlap?

I know that sounds vauge, but I'm having a hard time trying to understand this.

I want the red to transition smoothly into the blue and vice versa.



say I have color



rgb(100,50,50) and color rgb(50,50,100)




and at some point they overlap, how can I determine the new color value? for the one that is most intense from its source.

I am making a software lighting program and the problem is when two lights overlap, the color from the last drawn light is overpowering into the place where the light sources merge and they should be gradients of each.

Attachments

Login to view attachments
Sven B
20
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 20th Dec 2007 09:02 Edited at: 20th Dec 2007 09:04
Well, If your working with colors, I'd do something like this:


(pseudocode because I don't know how you made your terrain)
Notice that you have to do this with the red, green and blue values! (color1, color2 and newColor aren't full color values)

Gradient is a value from 0 to 1, where 0 gives you just color1 and 1 gives you color2 completely overlapping.
The gradient depends on the intensity of the light, though it can never be 0 (I don't really know how to calculate it). But that's in the direction.

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 20th Dec 2007 09:16
You first need to split the colours up into RGB elements, like:

AR=RGBR(ColorA)
AG=RGBG(ColorA)
AB=RGBB(ColorA)

BR=RGBR(ColorB)
BG=RGBG(ColorB)
BB=RGBB(ColorB)

Then work out the difference between them all:

DR=BR-AR
DG=BG-AG
DB=BB-AB

Then using a multiplier with ColorA you work out the new color:

Col=RGB(AR+(DR*mul#),AG+(DG*mul#),AB+(DB*mul#))

Personally I'd use a little function to return a colour based on 2 given colours and a multiplier:



I think that should work at least, untested.


less is more, but if less is more how you keeping score?
TinTin
19
Years of Service
User Offline
Joined: 16th May 2006
Location: BORG Drone Ship - Being Assimilated near Roda Beta (28)
Posted: 20th Dec 2007 10:59
Dang you Van-B, thats what I'dv done, pipped me at the post again. hehe

Cyberspace was becoming overcrowded and slummy so I decided to move. These nice chaps gave me a lift.
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 20th Dec 2007 11:04
You snooze you loose!


less is more, but if less is more how you keeping score?
David Gervais
Retired Moderator
19
Years of Service
User Offline
Joined: 28th Sep 2005
Location: Montreal, Canada
Posted: 20th Dec 2007 11:14 Edited at: 20th Dec 2007 11:25
If you mean to make the overlap a new color (based on the 2 other colors).. like this..



it's (R1+R2)/2, (G1+G2)/2, (B1+B2)/2. (note this is not actual code, just an example)

Basically you add the Red value from the first color to the Red value from the second color and divide the result by 2. Repeat this for the Green and Blue to get the new RGB values.

In your example R100,G50,B50 + R50, G50,B100 the result would be R75,G50,B75. (as seen in the sample pic I did above)

The example posted by Van B seems to give 'negative' numbers in some cases,.. {(BB-AB)=-50 }the RGB values cannot be negative. But his mojo multiplier might fix the negative numbers but it's all gibberish to me. I'm 80% artist 20% programmer so if the math is too complicated it boggles my mind.

Anyways this is my 2 cents.

Cheers!

Edit,.. here is a color sample taken from your picture..



Have a god day.
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 20th Dec 2007 11:37
Yeah, the negative number is needed when the second colour is less than the first, so it needs to go backwards if you know what I mean.

Like in the figures stated AR=100, and BR=50, so
DR=50-100 = -50
But the result is 100+(-50*mul#)

So it will range from 100 to 50 depending on the multiplier.


less is more, but if less is more how you keeping score?
David Gervais
Retired Moderator
19
Years of Service
User Offline
Joined: 28th Sep 2005
Location: Montreal, Canada
Posted: 20th Dec 2007 11:48
lol, now my brain is boggled and hurts.. LoL

I can see this type conversation with you...

David G: "Van B, please keep it simple"
Van B: "But the Algorythms are Simple!"
David G: "What's an Algorythm? It's Calculus right? nothing simple about Calculus. Keep it simple Van B, please."
Van B: "Trust me I know what I'm doing"
David G: "Ok, but it doesn't look simple to me!"

LoL,.. thanks you made my day Van B.

Cheers!
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 20th Dec 2007 12:05
Hehe - I only know that because I had to figure it out for myself a while ago, otherwise I'd leave this thread alone .

Calculus is not even proper maths, it's like the opposite, kinda like learning how to make violins, just so you'd have a lot of sawdust for your pet hamster.


less is more, but if less is more how you keeping score?
david w
19
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 20th Dec 2007 12:17
well I cant seem to get it to work


I have to go to work. So I cant work on this for 8 more hours. anyways this isnt for me. Im trying to help someone else. But if I can get this figured out, I can turn it into a lighting and lightmapping system, using only software and an unlimited number of lights.

here is the full code so far.





and the model is attached


thank you.

Attachments

Login to view attachments
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 20th Dec 2007 12:27
Ahh, see the Tweencolor function uses actual colours, not just the elements, so you'd just pass the old colour and new colour to that.


less is more, but if less is more how you keeping score?
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 20th Dec 2007 18:30
Quote: "Calculus is not even proper maths, it's like the opposite, kinda like learning how to make violins, just so you'd have a lot of sawdust for your pet hamster."


Van-B ... there you go again - making us all laugh!

Thanx for the Anti-alias'ish logic. Makes Sense for Color and Pixels

david w
19
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 21st Dec 2007 12:05
thanks for the help. works great now. Im gonna add some software lightmapping also. I've got a few days off work so I can actually get this done.

anyways thank you.

Login to post a reply

Server time is: 2025-06-03 18:33:56
Your offset time is: 2025-06-03 18:33:56