A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Color Math

Threaded View

  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

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