The small lesson I learned about flashlight brightness in my horror game.

AnnaBSearles

Newly Enlightened
Joined
Jul 17, 2014
Messages
1
So, I was wanting to determine what the best course of action was for adjusting the brightness for the flashlight in my horror game. I oftern see almost all horror games with flashlights keep the light at full brightness until the battery runs out, at which point it "clicks" and turns off. This is different from what I know to be true; the light is variable depending its battery's charge.

I headed over to /r/flashlight for some clarification on what the relationship is between a flashlight's brightness and its charge, as I had a feeling it was not linear (i.e. 50% charge = 50% brightness). What I found there was that incandescent (normal) flashlights' brightness is not in fact linear in relation to the charge of the battery, and is instead has a 4th power relation to charge. This means that 0% charge = 0% brightness, 100% charge = 100% brightness, but 50% charge ~ 93% brightness. Likewise, the light does not hit 50% brightness till the charge is around 15%.

This led me to construct this formula which outputs the final brightness at the ratio shown on this graph (red line is charge, green line is brightness). The formula is comprised of the following variables;

B_Final = Final Brightness (output)
C_Current = Current charge of battery
C_Max = Your max value for the battery's charge (I use 100f for 100%, but if "full charge" for you for some reason is 3864, use that)
C_Min = Your min value for the battery's charge (I use 0f for 0%, which is most common)
B_C_Max = The brightness of the flashlight when the battery is as full charge (I use 0.9f, since 1f is 100% and a little too bright for my needs)
B_C_Min = The brightness of the flashlight when the battery is as C_Min (again, I use 0f for 0% brightness, but if you want it to be no less than 20% you can use 0.2f)

In code (C#) it looks like this:

//in your update method
float chargeCurrent = yourgame.YourBatteryVariable;
float chargeMax = 100f;
float chargeMin = 0f;
float brightMax = 0.9f //1f is full brightness
float brightMin = 0f;
float brightFinal = (brightMin-brightMax)*Math.Pow((chargeCurrent-chargeMax)/(chargeMax-chargeMin), 4)+brightMax;

myLight.Brightness = brightFinal;

After all this, your flashlight will stay above 90% brightness for over 50% of the charge (as it normally would), and the light will dim quickly once it gets below 20% charge. This, to me, would add a lot more planning and fright for any game that requires light to keep your guy safe.

Edit: If you intend the MIN values to always be 0 (0 charge = 0 brightness), then you can eliminate the MIN variables, meaning the equation can actually be simplified to:

-brightMax*Math.Pow((chargeCurrent-chargeMax)/chargeMax, 4)+brightMax;

Edit: spelling

Edit2: Fixed equation
 

js

Flashlight Enthusiast
Joined
Aug 2, 2003
Messages
5,793
Location
Upstate New York
AnnaBSearles,

Welcome to CPF!

What a great first post and first thread!

OK. So, I'm trying to figure this out. First, looking online, I see that Math.Pow(x,y) returns x^y -- i.e. x raised to the yth power. So Math.Pow (2,4) is 2^4 or 2*2*2*2 or 16.

Correct?

Next, if we take current charge equal to .9MaxCharge and run the numbers in your simplified equation, we get the following:

brightMax - brightMax * ( (.9-1)/1)^4)

= brightMax ( 1 - (-.1)^4 )
= 99.9999 percent of full brightness.

Did I utilize your formula correctly?

So, how did you figure this out? Empirically? Did you just use your eye to estimate brightness? What type of battery / battery pack was used?

Because, the relevant parameter for determining the brightness of an incandescent lamp is voltage applied to the filament. Different battery chemistries have different discharge curves, which is how the battery's voltage changes over time with a constant current discharge. SilverFox has posted tons of discharge curves for different batteries and you can look at them. Here is something he did for me while I was working for TigerLight. It is a voltage vs. amp-hours (i.e. time, since it's a constant current discharge) graph of two different six cell NiMH TigerLight packs at 1.7 amps:

TLpacksGraph.jpg


You can see that the initial voltage drop is significant! It doesn't look flat for the initial 10 percent of the discharge.

The next bit of information you need is the laws of lamp physics, aka the re-rating formulas. We all initially got these from the Welch Allyn site, but they are on Wikipedia:

http://en.wikipedia.org/wiki/Lamp_rerating

The one of interest is re-rated lumens:

(Va/Vd)^3.5

So if the applied voltage is just 10 percent higher than the design voltage (or any reference voltage for which you know the brightness--you can chose the starting max brightness if you wish) then the luminous output actually increases by (1.1^3.5) = 1.39 or a 39 percent increase in brightness. A ten percent decrease results in a value of .69, which means a 31 percent decrease.

It would be challenging to fit a polynomial to a typical discharge graph, but it certainly could be done, especially by computer. Then from there you'd need to apply the lumens re-rating formula. Although, I have fudged things a bit, since a battery discharging through a lamp isn't a constant current discharge. So the best thing to do is to measure the voltage vs. time of your actual setup and graph it. Then call the initial point the MaxBrightness and re-rate from it using the re-rating formula. Since the graph has two inflection points, you would be able to model it with a 4th power polynomial, but you'd need contributions from the other powers as well--i.e. aX^4+bX^3+cX^2+dX+e, with b and c and d and e not zero.
 
Last edited:

cland72

Flashlight Enthusiast
Joined
Nov 23, 2009
Messages
3,276
I... I don't... um... *sigh*

Am I the only one who has no idea what's going on here?
 

chillinn

Flashlight Enthusiast
Joined
Jul 19, 2014
Messages
2,527
Location
Mobjack Bay
I... I don't... um... *sigh*

Am I the only one who has no idea what's going on here?

Some are locked in their mother's basement with a flashlight... some with a computer. This is an intersection of those two types. The OP is attempting to make a game, a computer program, more accurate by providing formula for how the flashlight object behaves in a virtual world, the game. Those that have replied are teaching the OP about accuracy (OP likely thought he was doing the world a solid, not realizing where he was posting or what he was getting mixed up in: OP want more realistic virtual flashlight? well, OP, you're going to have to learn about real batteries, the types of which there are legion!)
 
Last edited:

Peace Train

Enlightened
Joined
Jul 13, 2014
Messages
339
Location
Tempe, AZ
Either way, it's turning out to be quite informative on both counts. Thanks for the thorough explanation JS! I'm not a gamer per se, but it's interesting to see how accurate the programmers chose to be with this particular game and scenario. Oftentimes, it's the games, the movies, and the books that shape what happens in the real world, not the other way around.
Kudos to the OP for sharing her insight into this particular world. :welcome:
 

js

Flashlight Enthusiast
Joined
Aug 2, 2003
Messages
5,793
Location
Upstate New York
Peace Train,

You're most welcome! I was a bit unsure if I was missing something--maybe a joke based on C# code?--and where the OP was coming from, but I definitely didn't see her post and thread in any kind of negative light, and I figured that even if I was missing a joke, some good old incan basics couldn't hurt. The OP's intention to provide information and contribute something solid is laudable and a great way to start out. I would, however, love to see some follow up posts!
 

chillinn

Flashlight Enthusiast
Joined
Jul 19, 2014
Messages
2,527
Location
Mobjack Bay
I definitely didn't see her post and thread in any kind of negative light, and I figured that even if I was missing a joke

My apologies for having a little fun! I find it joyous when individuals revel in their expertise, in their excellence... it makes me laugh, and not in a mocking way. And I am sort of from the other side, the technical computer end, and I know how precise those serious about the work like to be... and in being introduced to this forum, its a whole new level of precision within some posts on this forum. I was delighted and surprised by it, and I'm certain the OP will be too, if she returns to see the responses.
 

js

Flashlight Enthusiast
Joined
Aug 2, 2003
Messages
5,793
Location
Upstate New York
chillinn,

For the record I quite enjoyed your post! LOL! No worries! I just wanted to make sure the OP knew we appreciated this thread.
 

yellow

Flashlight Enthusiast
Joined
Oct 31, 2002
Messages
4,634
Location
Baden.at
technically:
the idea is correct BUT whatever you/one will do ... IN THE GAME the OFF of the light will always happen, simply because it is "necessary" for the plot


realisticly:
you must be very lucky when there are no other problems, than to
a) think about that (which we all using lights are aware of, btw)
b) post it "unquestionned" at some forum
:rolleyes:
 
Top