Dynamically Lighting Characters

Started by geork, Thu 03/07/2014 16:41:12

Previous topic - Next topic

geork

Hello Everyone!

I'm speculatively creating a kind of lighting system, although it will probably be very slow and useless. Still, the idea is that the user can create an area which contains a certain colour and a certain saturation (the saturation changes depending how far the pixel is away from the light source). The complex part is that it is possible for only part of a character or object to be lit up, depending on which pixels overlap. Therefore, the relevant parts of the character are transferred over to a DrawingSurface to be tinted. So far so good. However, I don't want to use a DynamicSprite to Tint the whole image, because there are certain colours (i.e. Black) which I would like to be left alone due to stylistic reasons. I also don't want to use a dynamic sprite for every single pixel and tint that, as that seems like it holds an extra risk of further slowing things down. Is there a way to use the GetPixel() and SetPixel() Drawing Surface functions to combine the colours of both the original pixel and overlay tint, so that the original comes out tinted? I guess I'm referring to some kind of colour theory, which I don't know much about... :s

I know this is very speculative, and it'll probably be too slow anyway :P But thanks in advance! :)

Calin Leafshade

You're talking about multiplicative blending. You basically take the colour in question and multiply it by your tint value. This means that black is left alone and white is made the tint colour.

So you break the tint colour into r,g,b and then multiply each component of the tinted pixel by that.

selmiak

sounds useful for flashlights and moving sunrays and moving transparent bottles of radioactive stuff and the like ;-D

geork

Perfect, thanks very much Calin, I shall test it today :) It might work faster coded on an engine level, but I'm guessing it's the same principle :)

@selmiak:
Hmm...moving sunrays is a pretty cool idea - I might look into defining a light region by its source and strength, and allowing the player to define 'solid' (i.e. light blocking) objects and areas :)

Calin Leafshade

I should note that you multiply them assuming that their ranges is 0..1.

if the range is 0..255 then you have to take out a factor of 255 to make the range sensible.

geork

Hello again!

Thanks very much for your advice Calin - it's working very well so far :) (although has a wonderful habit of fragmenting the image)

I was wondering whether it is possible to apply the tint in part - so fulfill the same function as the 'Saturation' parameter in commands such as 'SetAmbientTint'. The Saturation paremeter I've set in place is also from 0...1, but I'm not sure how to employ it. My best Idea so far was to bring the numerical gap between the original colour and the tint colour for each component (R,G and B) closer in accordance to the saturation parameter.

So if my original R (oR) was say 20, and my tint R (tR) was 10, and the saturation was 0.1, then tR would turn to 19 (0.1 x the gap) - However, I don't think this is working correctly, and it was only a wild guess.

Am I on the right track, or am I wildly off target in terms of saturation?

Thanks again! :)

Calin Leafshade

Well basically a "null tint" is white. So just bring your tint colour closer to white. Pink tints less than red.

Essentially just think of it like this: "If I put a white piece of paper under this light, what colour should it be?" and use that colour as your tint colour.

geork

Thanks very much Calin - works a treat :)

SMF spam blocked by CleanTalk