<p>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.</p>

<p>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.</p>

CC BY-SA 3.0
2016-03-30T18:16:14.740Z
2016-03-30T18:16:14.740Z
Nathan Reed
<p>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.</p>

<p>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.</p>

CC BY-SA 3.0
2016-03-29T16:26:05.513Z
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.
Nathan Reed
CC BY-SA 3.0
2016-03-29T17:37:58.307Z
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.
Wuerfel_21
CC BY-SA 3.0
2016-03-29T17:44:44.280Z
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.
Nathan Reed
CC BY-SA 3.0
2016-03-29T19:56:43.433Z
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?)
Wuerfel_21
<rendering><texture><real-time><lighting><transparency>
In what order to apply lighting and translucency?
Wuerfel_21
# In what order to apply lighting and translucency?

(Asked by: username_0 on 2016-03-29)

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.

**Tags:** rendering, texture, real-time, lighting, transparency

> **Comments:**
> **username_1**: 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.  
> **username_0**: 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.  
> **username_1**: 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.  
> **username_0**: 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?)  

---

## 1 answers

### Answer by username_1 on 2016-03-30. Score: 3 | Accepted answer

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.


---

