4
$\begingroup$

I'm making a game that is supposed to like like a early 90s 3D game, so i'm rendering in software on an 8-bit indexed bitmap, using lookup tables for translucency and lighting.

Now I have to draw a translucent, lit sprite in front of an already-lit background (the light level of said background is lost at that point). I'm unsure whether to first darken all the pixels and then average them with the background or the other way round.

$\endgroup$
  • 1
    $\begingroup$ What level of authenticity to early-90s games are you looking for? You could just alpha-blend the sprites over the background and it will look "right". If it must be done using palettes, it's going to be a lot more difficult and limited. Or are you asking about how to do alpha blending? If so, we'll need more info about how your renderer works, which API(s) you're using, etc. $\endgroup$ – Nathan Reed Mar 29 '16 at 16:26
  • $\begingroup$ Alpha blending should work(it's not 100% implemented yet), by the way of 50% blending every two color combination in the palette, finding the best fit color from the palette and writing that to an array. This array is then indexed by the background color and the new pixel's color to get the color that is then put on the screen. $\endgroup$ – Wuerfel_21 Mar 29 '16 at 17:37
  • $\begingroup$ OK, assuming you have a palette that has close enough fits for all the blended colors, that could work. But then, what's the question about? Sounds like you already have a plan for how to do it. $\endgroup$ – Nathan Reed Mar 29 '16 at 17:44
  • $\begingroup$ Whether to first apply lighting to the sprite texel and then blend it with the background or first blend with the background and then apply lighting. (Or possibly something else entirely?) $\endgroup$ – Wuerfel_21 Mar 29 '16 at 19:56
3
$\begingroup$

When blending multiple layers, physically the "right" thing to do is calculating lighting on each layer separately, then composite the lit layers together. This way, for instance, you can have a translucent sprite standing in a spotlight, in front of a dark background, and the sprite will be well-lit while the background visible through it stays dark. Or conversely, you can have a dark sprite silhouetted against a brightly lit background.

If you blended the sprite with the background before lighting, it wouldn't be clear which lighting environment you should use if the sprite and background have different ones.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.