Archive | September 2012

It is saturday, let’s have fun with the beer :)

I finally implemented an approximation of the Beer-Lambert law. Looking at the resulting screenshots (of course looking at the colored bears only) you can see how:

  • correct light transmission gives more realism to the objects;
  • I got less saturated colors.

(Beer-Lambert on)

(Beer-Lambert off)

 

Considerations on light transmission and reflection

I’m just wondering if simply adding Beer-Lambert law and Fresnel’s reflections to my code I can get this kind of result in realtime:

 

Summing up and simplifying a lot, the Fresnel’s law says:

  •  if a surface is pointing at you (angle of incidence=0), the reflection is small (R=0) and the refraction is big (T=1-R).
  • If the surface is pointing to the side of your viewpoint (angle of incidence=90deg), the reflection is big and the refraction is small.

This means a solid object like a sfere or a human face near they borders reflect more light than you can expect.

The effect is noticeable on human skin too, as you can see in this rendering from Halflife with only the fresnel component visible:

A transparent object like a mirror, if the inclination is near 90 deg, transmits less light the expected.

This means that this effect is noticeable mostly along the outline of an object, or anyway in small, limited areas.

 

Beer-Lambert law says the amount of light transmitted through a material diminishes exponentially according to the path length; in the case of jelly materials, small objects and smal objects, I suppose I should give higher priority implementing this law, I’m really sorry for you, Augustin-Jean Fresnel !

The shader code should be something like this:

vec3 Absorbance = MaterialColor * MaterialDensity * -MaterialDepth; //density from 0.0 to 1.0
vec3 Transmittance = Refraction * exp(Absorbance);

I look forward to implement it and make some screenshot to compare the result with and without Beer’s law.

Work in Progress #1

Did you ever wonder how does it feel to be Han Solo sealed in carbonite, or a gummy bear?

I’m working on it, it is possible, in realtime, with some light reflections and refractions (GPU) + face detection and image processing (CPU), on Android.

It is funny to see how my face fits Han Solo body, or a gummy bear candy 🙂

The shaders still miss a lot of math (es. Fresnel equations), but the result is good enough to release some screenshot!

By the way, Han Solo is sealed in ice or crystal, black carbonite version is coming soon.