rtps
Yipe! This page's days could end on July 30. Click here to see how you can help keep this service on the web!


Raytracing, a rendering technique that excels at calculating shadows, reflections, and refractions, is often held up as a standard against which to judge all other 3D rendering. Proponents of raytracing cite its accurate lighting model -- detractors of raytracing point to other more-accurate models (such as radiosity calculation) and like to point out that ray-tracing's "accurate" model is actually an idealized one; well-suited for antiseptic otherworldliness, but unlike reality (Actually, this is true of all computer rendering, even with RenderMan). And both advocates and antagonists agree that raytracing is often very slow and CPU-intensive, for even the most advanced and optimized raytracing programs.
Still, there are some things that just look great raytraced. Raytracing effects have worked their way firmly into the iconography of computer picture-making, and so we often expect to see it.
But what if we don't have a raytracing renderer handy? Or we don't have the time to use it? Or we find it a tremendous hassle to endlessly iterate through the eccentricities of refraction coefficients, or we want to use a particular model made with our favorite modeling program and have no way to read it into our favorite raytracer?
This article will show you how to add raytracing effects without a raytracer. Furthermore, you may be surprised that we can add these effects with just about any renderer, even sometimes even with shaded preview renderings. The program I used in these simple examples was Macromedia MacroModel, but you could use 3DStudio, Lightwave, Alias, anything. All it takes is a little bit of theory, a little bit of forethought, and a copy of Adobe Photoshop.



Base, Shade, & Highlight
Theory, Part 1
When we render a 3D surface, each pixel gets a color by summing-up the component sources of illumination as they reflect or refract through the surface. 3D renderers don't take light away, they only add. Thus the classic illumination equation (the only equation in here, honest!):

Ci = (Ka * Ia) + (Kd * Id) + (Ks * Is)

Or in English: "the final color will be the sum of the ambient, diffuse, and specular colors." Base, shade, and highlight. Fancier versions of the very same equation can add terms for opacity, reflections, and refractions, and might vary the surface colors for diffuse and specular reflection; but down there, in every renderer's secret heart of hearts, is that same simple addition.
We can start fiddling and having fun with the rendering when we realize that we can add the portions together ourselves, the way we want them, not the way some distant programmer thought they should be. We just render the different light components separately and add them up in Photoshop. Along the way, we can play all sorts of mischief on the image -- we can even "raytrace" it.



Chalk and Obsidian
Practice, Part 1
For our first experiment, let's snazz-up an opaque ball (typical idealized solid shapes for raytracing) by giving it a super-glossy highlight. The first figure shows a basic scene, unaltered. We will need to render it a couple of times to get the effect we're after -- once with no highlights, and then once with only the highlights. I call this pairing "chalk and obsidian." Since we will be manipulating the results, and I'm not texturing, even the simple "preview" rendering in MacroModel is adequate for our needs.
First, we render the objects with highlights turned off, or turned to zero. Some renderers have a ready- made "matte" surface for just this effect. The result is a dull chalky look in our base color.
Next, we render with highlights on and nothing else, once for each highlight. This is usually easy to do -- just turn highlights on and color the object itself black, like obsidian. For this example, you can leave the highlight fairly wide -- we don't need to make it very tight, as we might normally do to get a "glossy" look.

Unadorned simple "plastic" rendering

Blue "chalk"

"Obsidian" lit by key

"Obsidian" lit by fill

A Curve to Sharpen Hilights
Now we read our two images into Photoshop. We display the highlight image and perform the following bit of magic: We call up the Image>Adjust>Curves menu and change the curve to something like the one in the figure (I have this curve saved for quick retreival).
What did this do to our highlight? It spread-out the bright center and gave the edge transition a sharper drop-off. The effect is to accentuate gloss and to emulate the reflection of a larger-area light source -- like a photographer's studio light source.
Now we select Image>Calculate>Add and add our revised highlight to the chalk image. *voila*


Original "plastic"

Glossy Photoshop Result


Getting Bent
Theory, Part 2
Refraction occurs when light crosses from one medium, such as air, into another, such as glass or water, and is deflected at the transition. The amount of deflection depends on the materials in question and the angle the light hits the surface at. For a raytracer, these material definitions (the indices of refraction) can be very annoying and difficult to get just right; while you can look at an object and say "that's a red glossy object," there's no easy way to just look at it and say: "That should have an index of about 6.127." Refraction indices are fairly abstract.
Simulating raytraced refraction effects is in some way easier than just raytracing them. Savvy Photoshop hacks may already suspect we will use the Photoshop "displace" filter. But how do we get a perfect displacement map for an arbitrary model? By subverting a little bit more of CG rendering theory to our own use.
Since refraction depends on the incident angle of light-to-surface, we can make a displacement map where the greatest displacement occurs in areas that are the most perpendicular to the view. How can we do this? With our old friend the "chalk" surface.



Lit Like a Musical
Practice, Part 2
Set the surface to white chalk and turn all lights off -- including any ambient light. Now set a pure-red infinite light coming directly from the right (X = infinity), and a pure-green infinite light directly from the top (Y = infinity). Render this (let's call the image "RtTop"). Be sure to leave shadowing turned off.


Pure Red and Green Lights on a Dull White Surface

Next rotate the lights: the red shining straight up from the left (X = -infinity) and the green straight down from below (Y = -infinity). Render again (we'll call it "LfBot").
We can now combine the "RtTop" and "LfBot" images into a perfect-fit displacement map. Open both of them in Photoshop.
Select each image and pull down the Image>Levels menu item. Reduce the RGB output levels so that what was 100% in each channel (white) is now only 50% intensity (mid gray).


Renormalizing the intensities to 50% grey

Look at each channel of this image. Because we had our lights set to pure red and pure green, and the chalk to pure white, the lighting for each side is in a completely separate channel.


gray plus half of "RtBot" less half of "RtTop"

Hit New and start a new RGB image the same size as the others. Fill it with "128" grey.
Using Photoshop's Image>Calculate>Add, add "LfBot" to the new gray image and write it to yet another new "Untitled" image.
Now Image>Calculate>Subtract and subtract "RtTop" from the previous result. Save the result as, say, "myPic.dmap"


myPic.dmap
For refraction to mean anything, we must have some background image. It could be rendered, painted, scanned, anything, as long as it's the same size as our rendered frames. Open the background image (the image here is from my photo page).



Undistorted background

Now select Filter>Distort>Displace. Set the displacement amount to any value you like -- try 10 to begin. The radio buttons in the displace dialog can be set however you like -- they won't make much difference for images that line up perfectly, like these. Now displace, and use "myPic.dmap" as the displacement. Instant refraction! Don't like it? Just hit undo, select the filter again, and alter the displacement amounts. This is much faster than repeatedly tweaking the index of refraction and raytracing over, and over, and over...


Background with Displacements of 5, 10, 20, 40 pixels

By diplacing the red, green, and blue channels with slightly different displacement strengths, we can create a prismatic effect.


Prismatic Displacement

Now to add color. Call up our original colored chalk-shaded view, and composite it over a white field (If it has an alpha channel, try Select>Load_Selection, Select>Invert_Selection, and then fill with white). Now use Image>Calculate>Multiply and multiply the white-bg image with our distorted background. Too heavy? Try adjusting the levels of the white image before the multiply. Remember, you can undo and alter the intensities as much as you like.

Multiply by render-on-white to "tint"
Finally, for more solidity use Image>Calculate>Add and add our old obsidian highlight pass to create highlights on the glass surface.
That's the bare-bones approach to Photoshop refraction. It might seem like a lot of steps are nessesary to "raytrace" this way, but once the look is figured out, the whole thing can be quickly set up as a QuicKey or similar macro. It's fast, interactive, and can even be an effective shortcut if you already use a "real" raytracing renderer.


...with extra highlights and "Anti-Zed" (see below)


To Infinity and Beyond
Practice, Part 3
Many variations and improvements can be introduced:

A slightly different version of this article originally appeared in 3D Artist #16


...& The Revs Go On, & On, & On...
Postscript
This article was originally written waaaaaay back, before the advent of Photoshop 3.0. The addition of layers to Photoshop makes these sorts of manipulations easier and more flexible than ever. You can now revise each layer independantly, regardless of stacking order.
And using Photoshop 4.0's "big data" layers and the MoveTool, you can also create even further tricky distortions between the layers... to say nothing of automating most of the laborious parts of the process using PS4 Actions.


Ripple Glass with Highlights

Photoshop 3's "Lighting" effects filter makes possible ray tracing effects completely contained within Photoshop. In the example above...
  1. "Difference Clouds" created the pattern on the left.
  2. Lighting Effects, using the clouds as a texture channel, and with red and green lights, created the displacement map at the center.
  3. The displacement was applied to our previous background to ripple the photo.
  4. Finally, another layer was added, containing more ("standard") lighting effects based on the same cloud texture, to add glassy hilights over the image that align perfectly with the displacements.
If you get really ambitious, you can even use the same displacement map to distort dropshadows that you may project onto the "glass..."

Related Pages
More Photoshop Displacement Maps
Using Photoshop To Build Avatars for The Palace
Making Fur with Natpix Blizzard
National Pixel Products
Björke Photo Page


© 1994,1997 Kevin Björke,
c/o natpix@natpix.com

Updated 21 May 97

Photoshop is a trademark of Adobe Systems.
RenderMan is a trademark of Pixar.
Ray Dream is a trademark of Ray Dream Inc.
3D Studio is a trademark of Autodesk.
Macromodel is a trademark of Macromedia.
Lightwave is a trademark of Newtek.
Alias is a trademark of Silicon Graphics.