Underwater darkening formula

Status
Not open for further replies.

ulillillia

Distinguished
Jul 10, 2011
68
0
18,590
In the real world, things get darker as you get deeper underwater. I'm trying to replicate this in my game by darkening the entire scene and I need a formula (assume the middle of the ocean where the water is very clear). Relative to the surface, as a percentage, what is the formula for how much darker things get deep underwater? The only things I've seen is that scales exponentially and that only 1% of the light reaches the parts 100 meters (328 1/12 feet) underwater. Thanks for any info on this.
 
Solution
Use equation, use m for depth:

PARz = PAR0 * exp (-ε * z)

PARz: radiation at water depth z
PAR0: radiation entering the water surface
ε: parameter for underwater light extinction, affected by dissolved and suspended matter
z: specific water depth

Since you only need percentage, use PAR0=100 and gives you 100% at depth 0.
Parameter for underwater light extinction ε use 0.3 which is clear water.

You mentioned other sources told you that you still get 1% light at 100m depth and you may wonder why my equation gives you 1% light at 15m depth. This is because blue light may penetrate that deep but all the other light we see don't penetrate nearly as deep. So the useful light we see is pretty much limited to about 15m.

I am a marine...

Pyree

Distinguished
Moderator
Use equation, use m for depth:

PARz = PAR0 * exp (-ε * z)

PARz: radiation at water depth z
PAR0: radiation entering the water surface
ε: parameter for underwater light extinction, affected by dissolved and suspended matter
z: specific water depth

Since you only need percentage, use PAR0=100 and gives you 100% at depth 0.
Parameter for underwater light extinction ε use 0.3 which is clear water.

You mentioned other sources told you that you still get 1% light at 100m depth and you may wonder why my equation gives you 1% light at 15m depth. This is because blue light may penetrate that deep but all the other light we see don't penetrate nearly as deep. So the useful light we see is pretty much limited to about 15m.

I am a marine biologist.
 
Solution

ulillillia

Distinguished
Jul 10, 2011
68
0
18,590


I got that information here. 100 meters has 0.53% light penetration given that site which is the closest I got. So then, basically, all I need is this:

BlackOpacity = (BYTE)(255.5-(255.0*exp(-0.3*Depth)));
ActualOpacity = (BYTE)BaseOpacity;

BaseOpacity is the opacity of an all-black image that otherwise covers the entire screen - the higher the opacity, the darker the scene. Given this (plugging it in to Excel first), something is far from correct - a depth of 100 meters has 9.21E-12% of the original light, way off. At 10 meters depth, the kinds of depths scuba divers go to (if I recall), of which I know is still very light, has a tiny 4.98% of the original light, next to nothing. It's like getting 4 1/2 times further from a single light source. If I change ε to 0.0528, I get something closer to what that one source states for 100 meters. If I change ε to 0.1505, I match that of that source's 10-meter depth data. I'm assuming that depth is also in meters, as per the scientific standard. Perhaps that one site's formula is based on the blue light that can penetrate this deep rather than the more useful light (like red)? Something is strange here.

My game won't be finished for another year yet, unfortunately, considering it's only half finished. I spent 5 or so hours searching Google for this formula so I had a more realistic water darkening effect, especially for the ocean-themed world that drops down about 90 meters below the surface.
 

Pyree

Distinguished
Moderator
Ok first of all, that site probably use distill water not clear water. Secondly, yes, the site probably use blue as the reference to find ε value. I think it is better to separate the color component. The equation I provide is for the red orange spectrum since for what I do, I deal with photosynthesis. So for modeling the red spectrum, you can use the ε I provide. For other spectrum, you will have to change the ε value. Once you go deeper in water, you can still see but you quickly can't see red and orange then green and as you go deeper, you really can only tell dark colour from light colour because of the lost of spectrum component. I will see if I can find something on at what depth you will start to lose other colour.
 

ulillillia

Distinguished
Jul 10, 2011
68
0
18,590
Since the background is based on being blue, (a hue of about 220 degrees), having it for this hue would help the most. A reasonable approximation is good enough. Thanks a lot though for the formula. I thought a square root was involved (starts fast but slows down as per what I was seeing), but 2.718 (if I recall) is fairly close, though a more intense curve.

The player being able to see is critically important so I may need to change the depth limit or something (90 meters seems a bit high - around 50 to 70 meters should be about the maximum instead). It seems that a value around 0.039 (based on 5/128) is about optimal (anything from 0.03 to 0.05 seems best for the player), though how that particular shade of blue fits in, that I don't know.
 

Pyree

Distinguished
Moderator
Ok if you are only using blue hue. I just found out the depth at which percentage intensity occur for the colours.

1% at 7m for red, 1% at 19 for yellow, 6% at 70m for yellow, 31% at 70m for violet, 46% at 70m for green and 69% at 70m for blue.

I just post it anyway in case you want to add other color later.
 

ulillillia

Distinguished
Jul 10, 2011
68
0
18,590
Given those figures, the value of ε in each case is, listed in order of the spectrum (to 4 significant figures though the first 2 are sufficient enough):

red (hue 0°): 0.6579
orange (hue 30°): 0.2424
yellow (hue 60°): 0.06579
green (hue 120°): 0.01109
blue (hue 240°): 0.005301
violet (hue ~270°): 0.01673

Since you have 2 "yellow" colors, I'm assuming that the first yellow is supposed to be orange. Thus, given this, for my hue of 220°, a value around 0.006 would do. There is a large gap where cyan would be (that's 180° for the hue) would be. It can at least be estimated based on your info as being something around 60% at 70 meters. This is definitely all the information I need. Very well done. Thanks.

One last thing - where did you find the information you just gave me to find those values (I just adjusted values in my spreadsheet)?
 

Pyree

Distinguished
Moderator
Yes sorry, typo. I just find it in the pile of note I took at my undergrad years. I keep them because they are useful for numbers and facts. Much faster than going through books over again. It turn out it is useful doesn't it.
 
Status
Not open for further replies.