gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Graphics > Bloom effect in a 16 colors palette in realtime

#128529 - Chano Marrano - Sat May 12, 2007 12:15 pm

I wonder which is the algorithm to implement a bloom effect in a 16 colors palette:

[Images not permitted - Click here to view it]

I don't look for the overexposure of the image, only to change the colors of the palette.

Thanks.

#128533 - kusma - Sat May 12, 2007 1:23 pm

If you're only going to change the palette, then you're not doing a bloom-effect. Is it the result on the right you want from a picture like the one on the left?

#128534 - keldon - Sat May 12, 2007 1:49 pm

http://en.wikipedia.org/wiki/Bloom_(shader_effect)

#128535 - Chano Marrano - Sat May 12, 2007 1:57 pm

Quote:
Is it the result on the right you want from a picture like the one on the left?


Yes, but I only want to increment the brightness of the colors of the palette like in real bloom. I do not want to change the image that uses the palette. The pseudocode would be like this:

Code:
for(i=1; i<16; i++)
    palette[paletteNum][i] = fakeBloom(
        redComp(palette[paletteNum][i]),
        greenComp(palette[paletteNum][i]),
        blueComp(palette[paletteNum][i])
    );


I would like to know how to implement the fakeBloom function.

#128536 - keldon - Sat May 12, 2007 2:34 pm

The 'fake bloom' that you talk of sounds more like gamma correction

#128540 - Chano Marrano - Sat May 12, 2007 3:27 pm

Thanks! I was looking for that!

Sooo...

Any ideas of how to implement gamma correction in a 16 colors palette in realtime?

#128553 - keldon - Sat May 12, 2007 5:45 pm

Just do it to the palette itself; you don't need to care about what the colours related to, but bear in mind that continuous calculations on those colours will result in some dodgy colours.

#128565 - Chano Marrano - Sat May 12, 2007 7:42 pm

Okay, there is an implementation of dynamic gamma correction for the GBA:

The gamma correction for each color component would be like this:
gammaCorrectedComponent = originalComponent ^ correctionFactor.

Supposing that the color components are expressed in a range of 0 to 1:
- If the correctionFactor is lower than 1, the color is clarified.
- If the correctionFactor is greater than 1, the color is darkened.
I only want to clarify the colors, so the correctionFactor is going to be lower than 1.

The color components in GBA are expressed in a range of 0 to 31 (5 bits), so we should compress the range (divide by 31), correct the gamma and decompress the range (multiply by 31).

The better way to do this is to create a lookup table of 32 colums and 32 rows:
- Each column refers to the possible values that takes each color component (0..31).
- Each row refers to the correctionFactor values allowed: 1/1, 1/1.1, 1/1.2, ... , 1/4.1.

So the gamma correction algorithm would be something like this:

Code:

for(i=1; i<16; i++)
{
    color = sourcePalette[paletteNum][i];

    gammaRed = gammaTable[redComp(color)] [gammaFactor] ;
    gammaGreen = gammaTable[greenComp(color)] [gammaFactor] ;
    gammaBlue = gammaTable[blueComp(color)] [gammaFactor] ;

    palette[paletteNum] [i] = setRGB(gammaRed, gammaGreen, gammaBlue);
}


So what do you think?