The Science Of CG


#1

I happened across this thread by the same name from 2004.
Which, IMO, there should be more of.

And I couldn’t believe that it didn’t generate any real discussion.

A guy wanted to discuss the physics of CG to learn his app better.
Although some of the replies were generally helpful, it didn’t give the man any real direction.

He mentioned wanting to know how light travels so that he could work out some ground rules to base his work on.
Which is something that I think everyone wonders about at one point or another.

Most of the replies were “study art”, or, “it’s all a hack anyway so just do what looks right”.
Which have merit, but there has to be an inbetween.

While studying traditional art to gain a better understanding in CG is just a given, it leaves alot of gray area in the cracks.
Particularly in lighting.

There ARE physical rules that govern light, that if you understand them make it easier to make choices concerning CG lighting.

If you’ve been doing 3D for years, you understand them out of necessity.
But if you’re not that experienced with lighting, you might not know them unless you have a physics background or interest.

For instance, the “inverse square law” which doesn’t only apply to light, but in the case of CG it’s application would be in lighting.

In particular the inverse-square law applies in the following cases: doubling the distance between the light and the subject results in one quarter of the light hitting the subject.

Some more experienced artists here are probably thinking, well who doesn’t know that.
But if you look in the WIP section, there are many people here that probably don’t.

IMO, this is very important information to have when you’re new to lighting, and want to get some reasonably realistic results.

I enjoy lighting personally, because I have an interest in physics.
And discussion of lighting is xtremely helpful since it’s one of the more difficult aspects for most people.


#2

i think this might be quite interesting thread, i prefer to do things rather “physically correct” way when i can choose. But: from my experience only very few people care about physics. mostly in movie production youre forced to work rather “artistic way”. you have to make things look nice and interesting. whether its physically correct or not mostly doesnt matter and moreover its common that director wants something that is definitely not physically correct. but its just more interesting. dont mentioning render times which can reach astronomic values with “physically correct” approach. so maybe thats main reason why this topic havent catched much attention. but i must agree that knowing these things is important and may help you to make better work.


#3

Finally, I organized the best from this thread into an article. So if you just start reading this thread, it may be the best to read this compressed version. You can download it to read offline. Just drop it into your browser to open.
Here is a link to the compressed article file
http://www.sendspace.com/file/hdvd8f

This is a valid question, dude. Most users start to explore controls but not the principles. Once understood, they are forever your non-aging friends and renderer-independent.

In raytracing the calculations are physically-based(mimic in a realistic way, but still not physically precise of course), that’s what they say in manuals for raytracers. So you need to study physics but not cg lighting then. And if you want to study lighting you also need not only a cg lighting knowledge but a traditional lighting.

You cannot study lighting without concerns about materials and real-world cameras imo.
There is a direct and indirect lighting. A direct lighting is just a ray that hits a surface but stops there, so we have no light bounce. That’s what never happens in real world.

I think that the law of energy conservation applies and any reflected value cannot be stronger than at the start, so reflection most probably will be a bit dimmer, and so is lighting has an inverse-square faloff.

(read further for more correct explanations of reflection and refraction as those mine are not very correct)
Light hits the surface and may either be
absorbed(looks like no light information - black)
transmitted
reflected(or all of this to some extent)


Reflection or transmission may be more of a diffuse quality or specular.

If a light bounces off a diffuse surface a color-bleeding happens.
If a light bounces off a specular surface a caustics reflection happens.
If a light travels through a refracted surface a refracted caustics happens.
If a light is absorbed by a surface with slight diffused refraction a subsurface scaterring happens. And you need a degree of refraction for subsurface scaterring to work. An absorbed light is a diffuse refraction+diffuse value, i.e skin consists of water and flesh(generally speaking), so this causes i to be both refractive and diffuse…

There is also a caustics dispersion of refraction but quite rare, mostly happens in diamonds and produces dispersed caustics(not sure about this last term).It looks like a colored refraction http://farm1.static.flickr.com/45/135751439_3d8ed79d4b.jpg?v=0
and colored caustics http://www.moissaniteco.com/includes/templates/Custom/images/education/fire-dispersion.jpg

Light may be very distant and so we don’t use the inverse-square falloff fot it(but as far as I understand it does have it but we don’t use it for conveniency - fake! Or we need to plavce it in zillions of miles away as the real sun is and insane intensity. So, we fake it), or if not as bright and distant - we use an inverse-square decay(faloff). And this brings a very important note - the realistic scale of a scene is important, because light decaying in a realistic way is tied to the scale by its strength.
Light shadow may be sharp or diffused depending on the size of a source.

There is a law that reflection overrides diffuse, and refraction overrides reflection. What that means is that if you have a highly reflective material such as metal, your diffuse won’t be seen almost at all. So 100% reflective=0% diffuse. 100% refractive - still some little reflection is present, and no diffuse at all(also must be set to black).

All surfaces reflect! The least reflective surface known is having a 0.045 light reflectance http://forums.cgsociety.org/showthread.php?f=21&t=584234 . Most surfaces have a diffused reflection, mirror-like are rare. Why some surfaces have a mirror-like reflection and others are diffuse? Because any surface has a microfaceted structure which is invisible by a naked eye but the rays which hit it go either in one direction(mirror) or hit facets with different orientations and the reflection becomes diffuse.

There are 2 types of materials: metals and all other one. All materials have a fresnel reflection type, all! So you should use it always. A fresnel reflection differs from a straight falloff by its curve: it’s more gradual at the beginning and very steep at the end. But metals have a much more prominent reflection, something like 80\100 value, and your diffuse should be black as long as it overridden by reflection.

Only metals have a colored reflection, so if you need to make a reflection for any other than metal reflection it’s just black-and white.

There is also an index of reflective refraction and refractive refraction, which is always equal(reflective refraction is the same as refractive refraction). The numbers you can find in tables. The index of refraction controls how distorted reflection or refraction will be and for metals brightens the reflection a bit.
See below for part two.


#4

Nice post misetr3d!

Depth of field occurs because a lens focuses light rays coming from a single point in a cone toward the film back. The length of this cone is dependent on the distance of the subject from the camera and the arrangement of the lenses in the camera. If the film back does not lie exactly at the apex of this cone, then the intersection of the cone and the film forms a circle (the circle of confusion). This essentially means that 3d points become circles when projected onto the film and the image becomes blurred.

Your explanation of surface reflection modes is a little confusing. I hope the following is slightly clearer.

There are 2 types of material as far as we’re concerned: conductive materials (metals) and dielectrics (everything else). When a photon hits a surface, one of 3 things happens (at least that we typically model in CG): absorption, reflection or transmission.

  1. Aborption. The light energy is converted to heat energy and is ‘lost’. Of course it isn’t really lost, but in rendering we’re only concerned with light and not heat. In practice this means that no material should ever be 100% reflective if you want things to look real.

  2. Reflection. The photon bounces off the surface. The exact direction at which is leaves the surface depends on the surface microgeometry: i.e. how rough or smooth the surface is at a micropscopic level. Very smooth surfaces will scatter light mostly along directions close to the mirror direction, while very rough surfaces will scatter light in many directions (though never quite evenly in all directions). We call reflections from very smooth surfaces “specular reflections”, from rough surfaces “diffuse reflections” and from surfaces in between “glossy reflections”.

Dielectrics always reflect light exactly as it hit it, i.e. their reflections are “white”, whereas conductors will colour their reflections. What colour the reflected light is tinted by a conductor is dependent on its chemical makeup as well as the angle at which the light hits it. For instance light hitting a gold surface at a glancing angle is less yellow once reflected than light hitting the surface head-on.

  1. Transmission. The light enters the material and is “refracted”, i.e. its direction is changed. The exact direction the refracted beam takes is dependent on the index of refraction for the material, as well as the orientation of the surface relative to the light. Surface microgeometry can cause the light to scatter in multiple directions in a similar way to glossy and diffuse reflections. This causes effects like the transmission seen through frosted glass.

Only dielectrics transmit light. Whether light is transmitted or reflected at the surface depends the angle at which it hits the surface and the index of refraction of the material. We model this using the fresnel equations. Essentially light that hits a dielectric head-on is almost certain to be transmitted, while light that hits at a glancing angle is almost certain to be reflected.

Only one of the above events can occur for any photon/surface interaction, but we’re modelling the net result of unimaginable numbers of these interactions, so for modelling a given surface we deal with the percentage of photons that undergo a particular type of interaction. So a metal might reflect 50% of the photons that hit it and absorb the other 50%, or we might model glass by saying that it transmits 90% of the photons that hit it dead-on, reflects 5% and absorbs the rest.

These rules reflect what is known as conservation of energy: you should never reflect more light than you recieve. The situation is complicated somewhat by the way most renderers model materials. The usual way is to additively layer BRDFs (illumination models), i.e. have a diffuse and a specular section in your shader. You have to make sure that the sum of your diffuse and specular do not go to 1 in order to be physically plausible. Of course this is not the way real materials behave as we’ve seen above, but it makes the maths easier to handle things separately. As far as I know, the only renderers to handle things ‘properly’ are maxwell and fry.

Subsurface scattering occurs when light enters a material (i.e. is transmitted), bounces around a bit inside, and exits at a different location from which it entered. The interactions inside the material cause some of its energy to be absorbed, usually different amounts at different wavelengths, so when the light exits it is dimmer and tinted. Subsurface scattering only occurs for materials that have a dielectric interface and is actually how every non-metallic material gets its colour (remember that dielectric reflections are always white). i.e. every time you see a coloured object that’s not a metal, the light has entered the material, bounced around a bit becoming coloured in the process, then left the material again at a different point. Thankfully, most materials are so hard that the entry and exit points are almost identical and we can pretend that they are so.


#5

part two

About the diffuse, I don’t know if it has a physically-based reason, but unless it is overriden by refraction or reflection(in which case it is black), it should be in 20-80% of brightness range, the same about saturation on most cases. This produces a better lighting interaction - less washed-out whites and black holes.

Specular may be isotropic or anisotropic. An anisotropic specular is stretched-out in a direction perpendicular to the grooves in the surface, whereas isotropic is evenly distributed.

Then if to talk about cameras, there is an exposure, motion blur, depth of field, white balance. Those are essential. But there are many others, which are caused by effect filters, and so on and so forth.

Exposure is for how long a film exposes itself to light. Longer – brighter, shorter – darker images. The controls are:f-number(also controls depth of field), shutter speed and film speed (ISO).

Motion blur is caused by the shutter opened long enough so the moving object leaves a trace on the film.

Depth of field is controlled mostly by f-number but also by the size of lens and film gate, and creates an effect of falling out of focus, which is very important for a realistic rendering as long as in many shots such as macroshooting it must be present. In real life an extreme depth of field is desirable to create the feeling of depth and is expensive to achieve.
Hell knows why depth of field happens, maybe it’s partially shadowed by shutter areas of lenses that blur the image.

Every light has a relative color temperature, but our eyes lie about it(and about many other things) because adapt very cuickly and we see most lights as white. A white balance is a color temperature which will be taken as white, and hotter will be more blueish and cooler more reddish. http://www.mediacollege.com/lighting/colour/images/colour-temperature.gif

The next question is how you achieve these effects in your cg application, and this is another big question.

And also there is a monitor physics: your software must have a proper calibration http://forums.cgsociety.org/showthread.php?f=2&t=188341 , a color temperature(6500k) and gamma-correction applied http://forums.cgsociety.org/showthread.php?t=610790 always.

All of these effects should be under your control(where, how and when) if you want a physically resalistic rendering. The next step is how you achieve them in your renderer, either with a more advanced algorithm(raytracing) or more fake-based(reyes).

This is quite a basic explanation of course.


#6

The most reflective material available is Spectralon, which reflects about 90% of incident light in a roughly lambertian fashion (but definitely NOT lambertian). A sheet of white paper is about 80% reflective.

The darkest materials you find commonly sit around 3% iirc. You can produce materials which reflect as little as 1% of incident light, but you don’t find them anywhere except in a laboratory.


#7

Don’t forget gamma and exposure control to achieve photorrealistic results.


#8

Playmesumch00ns, this is the best scientifically-based explanation of materials I’ve read, thank you, it is much more correct than mine. And especially thank you for the exsplanation of dof.

I’m not fure about this

If it would be true, than in mental ray and vray a reflection would be more than 1, right? This is not so. Or you’re talking about another kind of maths in maxwell and fryrender?

Bao2, you’re right, I mentioned it in my second post at the end.

Yet I want to mention about light distribution. In real life light diffuses most of the time, it’s really rarely you can see sharp shadows or a sharp cone from a spotlight. But when you create a spotlight in 3d software, usually it has a 1\1 rate of hotspot\faloff, which is wrong. It should have a rate of 1\10, and you get a more soft falloff which is correct. Just compare it with an area light which is a perfect example how realistic light works.


There is also an air perspective:objects dim with distance because air contains small particles of dust etc. It should be present in realistic outdoor scenes as long as it is physically-based.

To illustrate the color temperature, the rule to me is that there are no rules. There are kelvins and lumens, but if you stick to them you are a robot, you should work with color.The general rule is that outdoor light are much brighter than indoor and there is a color of light sources. Some artists don’t use any color for sources. This is because when they look at a light they see it white because their eyes adapt quiclky. But if you take a shot you will see that there is not such a thing as white light(unless it is at the whitebalance point). Remember: color creates mood, and in films they use colored gels etc. so study film shots for color temperature and mood.


#9

This is somewhat outdated now; most modern renderers force the engergy preservation law by default and do not require the user to think about it - this includes renderers like V-Ray and mental ray.


#10

No I’m talking about the reflection models they use. As far as I can tell it’s based on the Schlick BRDF (but seems to be better since my own implementations of that never quite worked right). The difference being that they only have 1 reflection model that’s anisotropic and has a continuum from lambertian diffuse to perfect specular. Thus they can much better represent real-world materials than the arbitrary blinn-phong models you typically see in a lot of other places.

The old-school-style diffuse+specular shaders you still see a lot of work reasonably well because most surfaces you see around you are layered or substrate materials, e.g. paint, plastic or varnished wood. What that means is that the material has an underlying diffuse layer, covered by a specular layer (in the case of paint and plastic the diffuse material is suspended in the specular medium). The kinds of materials can be well-represented by these sorts of shaders. You can even do skin reasonably well as oils on the surface form a specular layer in a similar way to varnished wood.

As thev pointed out I may be slightly out of date with this now, perhaps other renderers offer similar setups, I haven’t experimented with v-ray/brazil/finalrender et al for a couple of years now and I stay away from mental ray out of principle.


#11

There is currently no single analytic BRDF model that can accurately represent all real-world materials; the Cook-Torrance model comes fairly close, but it is not very convenient to work with from a sampling point of view. It would be most accurate to use measured BRDF data, but even then, a certain number of approximations and assumptions are typically involved.


#12

There is one thing that concerns hard-surface modelling but is related to lighting - fillets. They are added to create highlights from lights and therefore enhance the feeling of form.

But think about the actual scale of fillets when adding them. Don’t do a 10 meters fillet on a distant building for a fancy highlight, add fillets with a realistic scale.

I already mentioned that everything reflects to some extent. So add a fresnel reflection to all materials without an exception if you want a realistic result.
Reflections are perhaps the second by importance factor of realism after global illumination(technically speaking, talent is still valid)
Here is an illustration I did without reflection and added reflection. Look how much richer the second image looks. This is what archvizers use constantly - fresnel reflections.

Yet to notice, reflections in real world are mostly blurred, not mirror-like. The same about harsh and soft shadows. Use soft shadows most of the time and you will make no mistake. Though in many beginner’s works you can see a car on a mirror-like surface with a harsh shadow.


And yet quite an advanced topic, but still importand about realistic lighting. In very bright areas a rendered image might look too saturated, which is not correct and should be corrected in postwork, either in photoshop or in a compositing program. In photographs shadows are saturated but the more bright the luminance the less saturated the colors are.


#13

Got a question about reflections - specificaly the coloring. How do you mean that reflections of dielectrics are allways white? When you look around you, all reflections are obviously colored. My opinion is that color of reflection doesnt depend on receiving surface, but on the wave length of the ray that is hitting the surface (talking about dielectrics). In other words when the ray hitting the surface has wavelength equal to red, the reflected energy should be red as well, am i not right? So i would rather say that dielectrics do not tint reflection, while metals do add its own color, thus make reflection more yelowish, blueish or whatever. But correct me if i understand it wrong…


#14

Reflections look colored because they reflect color, but do not color them themselves, so when you apply a black-and-white map it will reflect colors, it just won’t tint the reflection. Maybe I said in a wrong way - not white, but not having color of themselves. I meant a map or a falloff is black-and white, not that reflection won’t reflect colors.


#15

ok, i understand it correctly then. dielectrics doesnt tint the reflection while metals does.


#16

Absolutely. All the work I’ve seen testing the validity of different BRDFs has been fitting to measured data (A&S came out top in the most recent paper I seem to remember) using multiple lobes. This isn’t something a user’s going to want to tweak.

What I mean is the BRDF models in maxwell and fry better represent conceptually what’s really going on at the surface: where in nature is there a specular lobe plus a lambertian component? I find their model much more attractive for the purpose of artistically tuning shaders, although having said that, I’ve yet to see a realistic skin material from either of those renderers :slight_smile:

EDIT: Just seen quite a nice one in the fry thread in general discussion. I stand corrected!


#17

Man, the information you guys have provided here has to be some of the best and most detailed information that I’ve ever seen given on the whole cgtalk forum, ever.

I’d buy you guys a handful of hookers if it was appropriate. :wink:


#18

Great, I’m gonna organise it into PDF then! Granted a proper credit for Playmesumch00ns. :slight_smile:


#19

That’s great!

I was thinking about that, I put it into a word file for personal reference but it would be too big a deal to download all the images and place them accordingly so I just got the text.

A PDF would be ideal though.
I can’t thank you guys enough. :bowdown:


#20

Dtox, this is kind of my interpretation of cg science, but if you want something interesting and understand it at a great depth, I suggest you this book, which I bought recently and it is simply amazing, it has everything you may need about surfaces, light and so on http://www.amazon.com/Langfords-Basic-Photography-Eighth-photographers/dp/0240520351/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1216178159&sr=8-1 Excellent color illustrations, the 8-th(!) edition first in color I guess, it is a real gem for your cg book collection. And for this price, man.