# Simple math for 3D Shading

In this tutorial I want to show you how you can benefit from your primary school mathematics:

By using them in the seemingly complicated and confusing world of 3D Shading.

## Simple math for 3D Shading

For me shading in its most simplistic form comes down to two operations: Multiplication and addition. Sounds simple, but it took me quite some time to figure this out. In this tutorial I want to show you a quick way of using those two operations to make the look development and shading process more intuitive and less time consuming.

If you have taken some design classes you have probably encountered the term of additive color.

That means that two colored lights, that are combined will add each others color intensities to form a third color.

3D Renderings are no different: You have different colored layers for the diffuse, specular and subsurface scattering contribution of your object in the form of render passes (or AOVs), that are adding their values to become the beauty image.

In a shader you have settings to tweak the intensity of the light that is being reflected. The multiple options and settings of a shader seem oftentimes overwhelming., but if you think in terms of the idea of reflected light it comes down to two simple questions:

• What percentage of the light do you want to be reflected by your object?
• Within that reflected light what percentage would you assign to the diffuse, the specular and the subsurface scattering?

If you know the answers for those two questions you have already made the most important decisions.

### Multiplication

Using texture maps in your shader will multiply the values that you have set before with the values of your texture map.

For example if you had a diffuse amount of 0.5 and combine it with a red texture map in the diffuse color slot ( RGB =1 0 0), your  resulting diffuse reflectionwill be 0.5*1 0.5*0 0.5*0, so 0.5 0 0.

By knowing that, you can for example leave the shader values at 1 and control all the values by only using texture maps. Or the other way round by using only black and white textures and multipling them with colored shader values.

Another multiplication is happening when we do a render using a lightsource. The color we have set multiplied by the diffuse strength will be multiplied another time with the intensity and color of the light,

### Speeding up the look development

So how can you use the idea of addition of reflected light and the multiplication of shader values in a practical way?

You can use the same operations that you would use, by tweaking the shader, within a 2D program like Photoshop or nuke:

Rather than hitting render button multiple times, make one rendering and save it in different render passes.

Layer those in a 2D compositing program using a blendmode "add" or "plus".

If you have all the passes combined, you should arrive at the beauty image.

If you now multiply the diffuse pass with a certain value you can make the same operation as you would by using the shader value.

Making those adjustments in a 2D compositing program saves render time and makes it more intuitive. Once you are satisfied with the shading you can take the multiplication values from your compositing program to your shader by making another multiplication on top of the old shader values. Now you should get the same image out of your rendering program.

The same workflow can be used to tweak lighting. Since it is also  a multiplication opperation you can change the lighting of a render with a single light source by multiplying a certain color. This helps a lot when trying to find the right color for your HDR. The color value can be put into the light color.

The knowledge of those simple operations helped me a lot to save time, especially for complex models, where Rendertimes slow you down. You can make variations easily and arrive faster at a nice balanced shader.

Often times I render a turntable and make another 3 variations using nuke.

One more contrasty, one less and one completly different.

For everyone interessted in this topic, I can recommend a great  tutorial made by my colleague Julius Ihle: