Vray Materials – Part 3 – Metals

Let’s continue the shader theme a bit further. Todays topic will be METALS

Metals are a special case – in their pure form, they do not have a Diffuse component, only reflections.
As if that were not enough, those reflections behave differently from non-metals.

They are much stronger, the fresnel equation (and the resulting curve) is more complex and the reflections are colored in a lot of cases.
Here is a comparison of reflection curves of aluminum and plastic.

curves

Notice that overall reflections are stronger and that there is a dip towards the right end of the graph for the aluminum. The math to create this graph needs multiple values, not just a simple number for IOR.
Vray doesn’t natively support the complex fresnel equation with n and k values used for metals. So to get accurate reflections, we must use some tricks.

The first method (popularized by Grant Warwick in his Mastering VRay course) is by creating custom falloff curves by hand in the material editor.
This method works, although it is quite tedious to set up. If you watch his course you will see how to use it, I’m not going to repeat it here.

However, there is one important thing that Grant didn’t quite get correctly, so I feel like I should ‘fix’ it.
The falloff map in 3ds max works in a strange way, the actual values are not really exactly what they seem. It seems that the falloff goes from 0 to 90 degrees in a linear fashion, but that is simply not true. So if we place a point at 50% and expect it to represent the color at 45 degree incidence angle… it doesn’t really show up at 45 degrees.
Here’s a simple test setup and the results. The lines on the sphere are rotated at exactly 45 and 22.5 degrees As you can see, it simply does not match.

edit

***Edit***

Thanks to on Wobi on chaosgroup forums for writing this osl you can use to ‘fix’ the falloff precisely. Just unzip and load this FILE as both Front and Side of the falloff and you can use the curves like Grant suggests in his videos.

FIX

The second method (the one I prefer) uses a custom OSL shader as the reflection texture (load it into the reflection slot through VrayOSLTex node and make sure the Fresnel is off in the shader settings) and it’s a bit easier to use. You just have to enter the n and k values taken from the refractiveindex.info site for R, G and B wavelengths.

nkvalues

rgb
The actual values for red, green and blue are somewhat open to interpretation, Different sources use different numbers but the approximate range is similar.
I use values from NASA’s site: 0.650, 0.510, 0.475

Now the resulting reflection map has the correct color and the correct falloff calculated by the complex fresnel equation.
When you’ve set up the values for a particular metal, save the osl file for future use.

If the color feels a bit wrong or you need a slightly different alloy, just run the map through a color correction node and adjust the hue saturation there. This way you still have the correct starting point with correct falloff curve and are just making color changes.

color_tweak

Another interesting thing about metals is that they are actually almost never pure metals. As soon as they are exposed to air, they start to oxidize (tarnish, rust).
tarnishThe resulting metal oxides behave like dielectrics. So this means they actually have a completely different set of properties. There are a couple of ways to deal with this: Blend materials and complex map setups in single layered shaders. I’ll demonstrate these workflows in detail pretty soon as a premium video.

That’s it for this chapter in the vray PBR material guide :)

Vray Materials – Part 2 – Reflection

Reflections, or specular reflections are what we see when the light is reflected back from the outermost layer of the surface.
For non-metals 99% of the time, these reflections are grayscale.

They also always have something called the Fresnel effect, which means that the strength of reflections depends on the angle of incidence. The reflections are at their weakest when the surface normals are pointing directly at the viewer (0 degree incidence angle) and they are 100% strong when the surface normals are pointing at a perpendicular angle relative to the viewer (90 degree incidence angle)

Measured data for real world objects (non-metals) defines the strength of reflections at 0 degree incidence angle to be about 2~5%. No more and no less.

This part is actually easy to do in vray, no calculations or anything. Just set the Reflection value to pure white and make sure Fresnel is on and set to the IOR value of 1.5
The frensel calculation takes care of the rest and the reflectivity at 0 degrees is exactly 4%
For liquids, lower the Fresnel IOR 1.3~1.49
If you need to boost reflections a bit increase it up to 1.6
That’s it, 90% of the shaders should just use 1.5 value.

reflect

A lot of folks take the measured reflectance values and use them incorrectly – The reflection amount combined with Fresnel makes sure that the full strength is only reached at grazing angles, The measured amount at 0 degrees is set by the IOR. You don’t have to calculate anything, just use white and adjust Fresnel IOR. Even adjusting Fresnel IOR for non liquids is non essential. It’s quite hard to tell the difference between 4% reflectance and 6% reflectance, so you probably shouldn’t even bother.

Here’s a simple test setup so you can see that it works correctly for yourself. Pure white environment, simple sphere with pure black Diffuse and pure white Reflection.
When measuring linear reflection channel values in VFB we can see they match perfectly.

test_percent

The only exception for non-metallic materials, where you might go higher with the Fresnel value is for gemstones and coated reflective glass. These can have the IOR go up to 2.4 (actual reflectance at 0 degrees up to ~17% )

The specular look of the shader is mostly controled by the Glossiness, or roughness. This value imitates microscopic imperfections of the surface and makes the reflections appear blurrier.
For pure, clean materials you don’t need to use a Reflection texture, only a Glossiness map.

It get’s a bit more complicated for dirty/layered/mixed/rough/metallic surfaces but I’ll cover that later.

The glossiness itself is worthy of our attention – there is something similar to the Fresnel effect going on in respect to the blurriness of reflections. Even relatively rough surfaces have sharp reflections at grazing angles.

Here’s a simple example photo (yes, that’s my actual phone, I’m still stuck in the last century).
As you can see the reflection becomes sharper as the viewing angle approaches parallel to the surface normals.
Try it for yourself with a relatively rough object against a brighter object.

gloss_falloff

Even things like cardboard have sharpish, strong reflections at glancing angles.

To imitate this effect, my standard practice has become using a Falloff map with a custom curve in the Glossiness slot.
The texture, if needed is used in the First color slot, while the second slot sets the upper limit for Glossiness. For most materials it should be just pure white. For rougher surfaces you should lower it to medium/light gray, as rougher surfaces never seem to reach full sharpness even at grazing angles.

gloss_fall

The falloff curve itself looks something like this. It’s not set in stone and you can tweak it a bit in either direction, I’m afraid there’s no convenient measured data to use here, so you will have to use your own judgement. The important thing is that the effect itself is present.

gloss_curve

I use this approach for all my shaders, except for perfectly smooth surfaces (float glass, water, etc)

Interestingly enough, even things like painted walls, fabrics, bricks and other surfaces that don’t ‘seem’ reflective, should have pretty strong reflections.
They should just be blurred quite a lot.
Here’s a link to an interesting article with some examples of specular reflections – http://filmicgames.com/archives/557

Overall the light is bounced more around the scene and it looks a bit brighter and more physically correct, when using reflections for all surfaces, even ones where the reflections are very blurred. The downside is longer rendertimes than with “cheat” materials (no reflections on things like plastered ceiling, or other seemingly non-reflective objects).

To make things a bit more balanced, reduce the amount of bounces on materials with blurry reflections, it could help out a bit with rendertimes, while still keeping a more physically accurate look. I’ve found that 1~2 bounces on blurry surfaces is all it takes to make a difference.

bounces

One final note about reflections – you really should be using the new GGX (GTR) BRDF for all your shaders, it gives a much more realistic rendering of the highlight areas ,especially when using falloff maps in the glossiness slot.

ggx

In the next lesson, I’ll focus on Metallic materials. They are a whole different beast and require some advanced techniques, so stay tuned!

Vray Materials – Part 1 – Diffuse

I think it’s time to redo my vray material guide with updated techniques and software.
The old one is still valid and a good reference for ‘how’ the vray shaders work, but there are a few changes in my approach and understanding of the shading process.

I’ll break this guide up into multiple posts so it’s not a huge essay that takes hours to read.

Let’s start with the basics.

PBR or physically based rendering

PBR is currently a hot topic, everyone from Disney to game engines are using it. So what exactly is PBR?

Until recently, the dominant approach in CG was using any means necessary to get the final render. If it looks good, it’s good. So there’s a lot of guesswork for the settings and a lot of artistic decisions that make the final image. This method still works, but overall the industry is slowly shifting towards a different approach – PBR

For PBR the main idea is that you should use realistic data from real world to make your 3d scenes. This means realistic light intensities and realistic diffuse/specular/etc settings for your shaders.

The main advantage, I think, is that it’s harder to make your images look ‘fake’ or ‘CG’. The strict rules imposed by PBR make sure that the renderer is at least working with a realistic inputs and thus is much more likely to create a realistic output. I’m not saying the images will look better (there’s plenty of shitty real photos), but they will look more realistic.
If your goal is to make ‘realistic’ renderings, this is absolutely the way to go. If your values are set right, you can spend more time working on the design, composition, lighting and postwork – things that actually matter.

So let’s get started on the actual practical information:

Diffuse

Diffuse color is the light that is reflected from an object in random directions. Some lightwaves are absorbed and some are reflected, if different wavelengths are absorbed by different amounts, the result is a colored.
Measured data from real world suggests that almost all surfaces reflect 3~90% of the light as Diffuse color.

The main exceptions are metals, which do not scatter the light but instead bounce it right back from the surface. Their Diffuse should be set to pure black. At least for pure, clean, non-oxidized metals…

Once we convert this to RGB range it’s something like [8;8;8] for blackest coal and [230;230;230] for the whitest snow. Most surfaces fall somewhere in between. Even things like paper sheet or white paint are only something like ~70% [179;179;179] and 85% reflective [204;204;204] definitely no higher than that.

If you are using Textures instead of color values, it’s a good idea to make sure that your image falls within this range, but there’s a catch… Gamma
Photo sourced textures come with a burned in srgb gamma correction of 2.2. This means that to get the image to look the same in 3ds max, it must be loaded with the gamma setting of 2.2
The side effect of this is that the values you use in photoshop do not match with the linear values that vray outputs. If your texture is medium gray in photoshop, the actual amount of reflected diffuse light is going to be only 22% instead of 50%.

bitmap gamma

When we convert the diffuse color range to sRGB, we get values of 50~243
The formula used: sRGB=(linearpercent/100)^(1/2.2)*255.
As an example, to get 4% reflectance from an srgb texture we can use this calculation. (4/100)^(1/2.2)*255=59
You don’t actually have to do the math every time, scroll down for a chart that allows you to easily convert between the two.

All these numbers seem complicated, but the things that you should take away from this are:

  • Diffuse is darker than we think it is most of the time.
  • The blacks are not as black as we think.
  • Make sure that gamma correction doesn’t fu*k up your values

To get a rough idea on where different material diffuse brightness falls in linear and srgb color space – just use this handy little graph I made (click to enlarge)


Simply pick the color in photoshop and see the value in either of the gradients. This is not something that you have to use as a law, but just to give you a basic approximation. Nobody is going to get upset if your sand is 47% bright instead of 45%.

So how do we actually get the texture to fall within the range we need in Photoshop?
You need to use either Levels or Curves. Here’s quick guide:

Open up your texture and decide the range where it’s values should fit in.
For example – here’s a dirty concrete texture that should be about 75% reflective or [190;190;190] in srgb space.

photo

Open it up in photoshop and press Ctrl+L for levels tool.

1. Make sure the black and white points are adjusted to just touch the histogram on left and right and adjust the output values.
2. Since the main color of clean concrete should be about 190, move the whites down to 195 (some dirt streaks seem brighter than actual concrete). Now move the blacks up to about 65, since the dirt and grime is probably about as dark as dark soil, not darker.

lvls

That’s it – the image should now be a realistic, usable Diffuse map. The difference is not very strong in this case, but it’s noticeable. Overall texture is a bit darker, whereas before it was too bright.

after

If you are used to work with full 0~255 range of color in your scenes, the resulting renders might seem flat or low contrast.
While this might be the initial impression, working in a linear space gets you more than enough color range to bring in some contrast in post.
So don’t be afraid of flat images coming out of your renderer, it’s nothing that some simple postwork can’t make as crisp and contrasty as any other workflow.

Here’s a simple example with coal-black material looking quite light in the render but rich and dark after adjusting the curves.

sample_post

So that’s it for the Part 1 – Diffuse
Stay tuned for the next part where I’ll cover Reflection settings!