Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!rutgers!sri-spam!mordor!lll-lcc!ames!oliveb!sun!peregrine!falk From: falk@peregrine.UUCP Newsgroups: comp.graphics Subject: Re: Ray Tracing & filter references Message-ID: <12680@sun.uucp> Date: Wed, 4-Feb-87 01:27:57 EST Article-I.D.: sun.12680 Posted: Wed Feb 4 01:27:57 1987 Date-Received: Thu, 5-Feb-87 05:26:09 EST References: <179@ndmath.UUCP> <628@elrond.UUCP> Sender: news@sun.uucp Reply-To: falk@sun.UUCP (Ed Falk) Organization: Sun Microsystems, Mountain View Lines: 77 Keywords: references, ray tracing, box filters > ... Also, >getting a shading algorithm isn't real easy (at least I haven't found it >to be) because they tend to be published with lots of greek letters that >you (and I) don't seem to like... Ok, here's a shading algorithm in plain english. I implemented 2/3 of this in microcode once, so it's pretty simple. Disclaimer: It's only a model (shh!) There are three kinds of light that can hit and bounce off an object: ambient, incident and specular. Ambient light is the light that's all around the object and illuminates it evenly from all directions. Incident light is light that hits the surface from a particular direction; light that hits directly (at a right angle) lights the object the most, light that grazes the surface lights the object the least. The angle you *view* the surface from does not affect the brightness. Specular reflection is the "shininess" of the object. Light bounces off the surface and reaches your eye. If you and the light source are close to the same angle from the surface, the specular reflection is bright. eye light \ / \ / \ / \ / _______\/_______ surface For example, paper has a low amount of specular reflection. A polished table has a high amount. For color images, the ambient and incident reflections are the color of the object; the specular reflection is the color of the light source. so: The object has three parameter that describe its appearance: A coefficient of incident reflection; Ci, a coefficient of specular reflection; Cs and an exponent of specular reflection; Es. Let A = the amount of ambient light. I is the intensity of the light. Let L be the vector from the surface to the light source. E is the vector from the surface to the eye. N is the normal vector for the surface. R is the vector of light bouncing off the surface as if it were a mirror. All vectors should be normalized. R is calculated as R = 2N(N.L)-L ["." is dot-product] The amount of light received from ambient light is A*Ci The amount of light received from incident light is I*Ci*(N.L) The amount of light received from specular reflection is I*Cs*(R.L)**Es Brightness = A*Ci + I*Ci*(N.L) + I*Cs*(R.L)**Es If you have more than one light source, just sum over all of them. Notes: Ci, Cs are values from 0 to 1. Higher values make a brighter object. Higher values of Cs make a shinier object. Es varies from 8 to about 50. Powers of two make easier computations. Higher values make a "better polished" impression. Metal should have high values, things like billiard balls should have medium values. Experiment. Color is not much harder. In this case, Ci and I are (R,G,B) triples (colored object, colored light). Cs is still a scalar. The red component would be Red = A*Ci(r) + I(r)*Ci(r)*(N.L) + I(r)*Cs*(R.L)**Es and so forth. -ed falk, sun microsystems sun!falk, falk@sun.com terrorist, cryptography, DES, drugs, cipher, secret, decode, NSA, CIA, NRO.