Khatoblepas
Still Fresh
Okay, so I'd be the first to admit I like doing things the hard way. In the game I am making, I am obsessive about file structuring, custom file formats for lower clockspeeds (Compression = Slow ), and making it run on the bare minimum.
Today I have been thinking about Translucency effects. I don't want to run on 16bit colour (Half the framerate? BAH), but I do want the delicious translucent sprites it has. I know how to do translucent shadows and white light glowing (It's all a case of managing your palette well.), but translucency stumped me. So, I wrote out some (hopefully readable) pseudocode for drawing a 50% transparent colour onto a pixel.
Any tips on how to optimise it are VERY welcome. It looks like a LOT for just writing a pixel. I bet it would run terribly, terribly slow with sprites that move =D
Today I have been thinking about Translucency effects. I don't want to run on 16bit colour (Half the framerate? BAH), but I do want the delicious translucent sprites it has. I know how to do translucent shadows and white light glowing (It's all a case of managing your palette well.), but translucency stumped me. So, I wrote out some (hopefully readable) pseudocode for drawing a 50% transparent colour onto a pixel.
Any tips on how to optimise it are VERY welcome. It looks like a LOT for just writing a pixel. I bet it would run terribly, terribly slow with sprites that move =D
Code:
TYPEDEF struct Pixel {
char r;
char g;
char b;
} RGB;
void PlaceTranslucentPixel (targetx,targety,desiredr,desiredg,desiredb){
RGB pixel = GetPixelRGB (targetx,targety);
char i;
RGB result;
result.r = (pixel.r + desiredr) >> 1; //Halfway between each value. I hope I got the bit shifting right =x
result.g = (pixel.g + desiredr) >> 1;
result.b = (pixel.b + desiredr) >> 1;
char success;
while (i<255)
{
RGB temp = GetPalRGB(i); //Load up the current palette entry into an array.
// If current palette entry is equal to the desired palette entry, with a tolerance of 4/63ths either way.
if (temp.r > result.r -4 && temp.r < result.r +4 &&
temp.g > result.g -4 && temp.g < result.g +4 &&
temp.b > result.b -4 && temp.b < result.b +4)
{
break; //You got an entry!
success++;
}
else i++;
}
if (!success) { //If the last loop failed to bring results, repeat with a higher tolerance.
while (i<255)
{
RGB temp = GetPalRGB(i);
if (temp.r > result.r -8 && temp.r < result.r +8 &&
temp.g > result.g -8 && temp.g < result.g +8 &&
temp.b > result.b -8 && temp.b < result.b +8)
{
break;
success++;
}
else i++;
}
PlotPixel (targetx,targety,i); //Write the pixel with the halfway colour!
}