Monday, April 8, 2013

From a View to a Pixel

I admit I was tempted, for this next article on building custom content for Poser, to go into the history of 3D graphics.

Instead I'll be satisfied with a mini-lecture -- poorly illustrated -- on some important concepts in optics.





3D rendering is a complicated set of approximations, compromises, and historical artifacts.

In the real world, light gets everywhere.  In the darkest corner of our universe, there are still infrared photons bringing the coldest object into thermal equilibrium with the CMBR -- the fading fires of some of the earliest moments of the expanding universe.  You see an object because photons came off it and entered your eyes (and interacted with chemistry at the back).

This means, in the real world, everything is a light source.  Distinctions between primary sources (those things that emit light) and secondary (those objects that reflect light) are somewhat arbitrary.  I say "somewhat," because our unaided eyes can't see the thermal radiation of a human being, or the various minor phosphorescences about them ; we only see the (visible wavelength) light they reflect.

As a reflection of this arbitrary distinction, in the world of 3D we draw a line between diffuse reflection and the various forms of reflected light that do not meet that perfect Lambertian distinction.






Okay, enough words.  Time for a few diagrams!

SPECULAR: 

In the perfect case, a photon comes along, and bounces off an object with exactly the same energy and at a perfectly reciprocal angle.  In 3D, this behavior is grossly split up into the concept of the Specular Reflection (the reflection of lights in the scene), and Reflection (aka mirror surfaces, returning ALL the photons that hit them, in perfect order.)

DIFFUSE:

The base model of 3D rendering; a photon comes along, and bounces off at a random angle.  In the real world, this happens because of small irregularities in the surface, and thus is never actually perfectly random.  This divergence from random we call "anisotropy."



TRANSPARENCY:

Of course, the photon might not bounce.  It might pass through.  In 3D, this is what we start with; the assumption that some or all of the photons merely pass through the object without interacting.

Of course I made all these renders with a polished reflective metal surface, so the example rather gets clouded in the other optical effects!

The first approximation of material we make by juggling what in most 3D engines are referred to as the Diffuse and Specular channels.  100% diffuse makes a perfectly flat surface.  Then we add a specular highlight to suggest shininess; the smaller the spot, the higher the polish.  Thus, a bit of varnished wood gets a larger spot, a piece of glass a smaller spot. 

By toying around with specular reflections we can sort of simulate various metals.  The simplistic rule of thumb is that plastics and glass and ceramics have white specular highlights, and metals like copper and gold have highlights the color of the metal.  This is not, of course, entirely accurate!  Since, technically, it is the same light, we should also remember to dial down the diffuse percentage as we dial up the amount of specularity.  Practically speaking, though, that tends to get lost in the shuffle of setting a decent value for color and luminosity of the overall effect.




In most 3D engines, the other ways photons can interact with a surface are approximated with secondary passes added to the diffuse and specular render.


CAUSTICS:

Light reflects.  That's how we see.  In most 3D engines, though, we arbitrarily single out reflected primary lights.  This is the most effective way to simulate light from reflectors with a complex shape; those distinctive patterns cast by, say, sunlight reflecting off of water.  In the render to the left, I've faked a caustic reflection from the textured metal by sticking a pattern into the spotlight.

The light reflected from non-primary lights -- aka everything else in the scene -- is treated in ways variously called "Ambient Occlusion," "Indirect Light," or "Radiosity."  More on that some other day!

GLOW:

To the left is illustrated phosphorescence; a photon of one frequency is absorbed by the material, and it re-emits one of a different frequency.  Materials may release photons via chemical changes, electro-luminscence, because they are heated....anyhow, we lump all this together as "glow," and there is no way in most 3D engines to model the contribution of primary photons.




 Which brings us to color.  Surfaces don't of course return all frequencies of light equally.  Some colors are reflected, some are not.  Similarly, some are transmitted, some are not.  In 3D, the latter might show up as "Translucence Color."

And when there is inter-object reflection, the color sent back into the scene from reflective objects is colored by those objects.







And just to confuse things even more thoroughly:


REFRACTION:

Light doesn't just pass through materials.  It may be reflected multiple times.  It also has a different velocity, giving rise to an angle change at the interface; this is what we call refraction.  In 3D, refraction is a calculated lighting effect that has to be specifically called for by a material, with specialized lighting nodes.  Otherwise the render engine assumes the material in question has an identical Index of Refraction as air.
 SUBSURFACE SCATTERING:

Light can bounce around inside an object, and be emitted in essentially random directions.  This is how clouds work.  Other substances in which a striking part of their appearance comes from SSS effects are milk, wax, and skin.  One long-established fake is to use shader nodes that brighten the off-angle parts of skin slightly (or darken the parts that are facing the light most directly).



And at this point, my illustrative model is entirely inadequate for talking about how these various effects interact in the real world, and how you juggle them to create decent-looking materials.  So we will adjourn, and next article will be more of a more practical turn.

No comments:

Post a Comment