A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Color Math

  1. #1
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139

    Color Math

    Hello, just wanted to get your opinion on something:

    http://littlemofo.soap.com.au/gamedev/color/

    here you can see 4 colored circles over an image. The color of the circle changes the image underneath based on that color. Now does this seem correct to you guys? The blue color is very dark over yellow and red is very dark over blue and green is very dark over red. White is always the same.

    I think its correct, but not sure. The effect I am trying to achieve is to have the color show up on top of every other color but I think this is going beyond simple multiplication.

    The code is actually running from pixel bender, its implemented as a blendMode. Here is the pixel bender kernel, very straightforward.

    Code:
    <languageVersion : 1.0;>
    
    kernel ColorFilter
    <   namespace : "Flash";
        vendor : "Chris Foulston";
        version : 1;
        description : "performs colour overlay blending";
    >
    {
        input image4 background;
        input image4 foreground;
        output pixel4 result;
    
        void evaluatePixel() {
        
            float2 pos = outCoord();
            
            pixel4 pix1 = sampleNearest(background, pos);
            pixel4 pix2 = sampleNearest(foreground, pos);
           
            float a = 1.0 - pix2.a;
            float r = (pix1.r * a) + (pix1.r * pix2.r);
            float g = (pix1.g * a) + (pix1.g * pix2.g);
            float b = (pix1.b * a) + (pix1.b * pix2.b);
            
            result = pixel4(r, g, b, pix1.a);
        }
    }
    Hopefully someone can understand my ramblings
    Last edited by mr_malee; 09-10-2009 at 09:44 AM.
    lather yourself up with soap - soap arcade

  2. #2
    Dance Monkey Dance! Doush.'s Avatar
    Join Date
    Jun 2004
    Posts
    254
    Looks fine here, isn't there a way you could produce the image in red green and blue in something like photoshop and check your results against that?
    "I layed down in my bed last night looked up at the stars, and thought to myself... Where the F*#K is my roof"

  3. #3
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,361
    Wikipedia's entry is confusing: http://en.wikipedia.org/wiki/Blend_modes#Overlay

    Quote Originally Posted by wikipedia
    Overlay combines Multiply and Screen blend modes. Light parts of the picture become lighter and dark parts become darker. An overlay with the same picture looks like an S-curve.
    And they give definitions for Multiply and Screen but I am confused what they mean by "combine". (I mean, I suppose it could just be the result of the first is the background of the other, but seems ambiguous to me)

  4. #4
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    I think the blue is very dark over the flower because there's very little blue in that part of the image ( It's fine up against the blue wall for example ).

    If it's just pulling out the amount of that colour underneath it, then 'cause it's pulling out very little blue you're left with a "low" amount of blue, which makes it so dark.

    Squize.

  5. #5
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    yeah, I'm trying to add blue (red or green too) to a color. As if a colored light was pointed at the image.
    lather yourself up with soap - soap arcade

  6. #6
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    desaturate it, then add the colour
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  7. #7
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766
    I think the blue is too dark, rest is ok!
    If you like me, add me to your friends list .

    PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!

    My Arcade My Blog

    Add me on twitter:

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center