Jump to content
  • Advertisement
Sign in to follow this  
pauljan

Light passing through alpha-transparent surface

This topic is 4845 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am adding alpha transparency support to our simple raytracing lightmapper, and I just realized I am not quite sure how exactly the color of a ray of light is affected when it passes through a surface, given a color and alpha value at the point of intersection. Let's say a ray of bright white light (R: 1, G: 1, B: 1) passes through a red surface (R: 1, G: 0; B: 0), 1) When Alpha is 0, the result should be bright white 2) When Alpha is 1, the result should be black 3) When Alpha in (0, 1), the result should be somewhere in between, with a hue based on the red material color. I tried things like light * color * ( 1-alpha ), that don't work for obvious reasons. I am now considering simple 2-part linear interpolation from black -> materialColor -> white, based on the alpha. However, I can't shake the feeling that there should be a much more direct solution. Maybe I am looking at this problem the wrong way? Any input on this issue would be most welcome. Best regards, Paul-Jan p.s. Note how I am not looking for physically correct behaviour of light here, I am not doing refraction or anything similar, I just want the result to look... ok.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by pauljan
I tried things like light * color * ( 1-alpha ), that don't work for obvious reasons. I am now considering simple 2-part linear interpolation from black -> materialColor -> white, based on the alpha. However, I can't shake the feeling that there should be a much more direct solution. Maybe I am looking at this problem the wrong way?

Depends on what you'd like to achieve. In the real world, a perfect red filter will produce perfectly red monochromatic light, that will never turn white even at high intensities. Now, a typical sheet of red transparent plastic (or similar) is far from being a perfect filter. It will not completely absorb other wavelengths, just attenuate them. This is why at high intensities, this residual light is still strong enough to saturate the receptors on your retina. The net result is a white light.

Now, let's transpose this to computer graphics. If you have a perfectly red filter, ie. (1, 0, 0), then the resulting light must always be perfectly red (assuming white incident light), regardless of the intensity. So this behaviour is correct. But if your filter is not perfect, for example (1, 0.3, 0.3), then the light must saturate to white from a certain intensity on.

The way to simulate this effect is by using HDR, high dynamic range lighting. Essentially, your light sources have a larger dynamic range than your usual 0 to 1. Maybe 0 to 2, or more. Then, use the equation you showed above, a simple colour filter, and clamp the end result to the [0..1] range.

Share this post


Link to post
Share on other sites
Thanks, that clears things up, a lot. Using HDR (clamping) crossed my mind, but that didn't solve the problem of the light staying red. Following your explanation, I now see that that is how things are supposed to work. Just like a perfectly black filter will never let any light through, no matter what alpha it has. In real life, there is no such thing as a pitch black yet transparent surface.

I am not sure yet wether I'll want to simply extend the dynamic range of my lights and clamp, or put things through an exposure-type exp function, but the basic principles are clear now. Thanks!

Share this post


Link to post
Share on other sites
it seems you can approximate this with an exponecial funcition for example

1 - e^(-L*k)

the bigger L the more close the result is to one, this gives high (infinate to be eact)dynamic range and the sharpness of the thing is controled by the constant k.

filters are controled by beers law anyway, and this has a similar form

Tim

Share this post


Link to post
Share on other sites
Yes, that's what I refered to as 'exposure'. It's Huge Elias' photography analogy used to describe exactly this solution to the HDR problem, see http://freespace.virgin.net/hugo.elias/graphics/x_posure.htm for details.

For the moment I've settled with a 4x range for the color filtering with local clipping, simply because it looks good. For the next version I'll probably add exposure type HDR handling for the light equation as a whole.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!