Search Unity

What is Physically Based Shading? Physically Based Shading (PBS for short) simulates the interactions between materials and light in a way that mimics reality. PBS has only recently become possible in real-time graphics. In situations where lighting and materials need to play together intuitively and realistically, it’s a big win.

The idea behind Physically Based Shading is to create a user friendly way of achieving a consistent, plausible look under different lighting conditions. It models how light behaves in reality, without using multiple ad-hoc models that may or may not work.

To do so it follows principles of physics, including energy conservation (meaning that objects never reflect more light than they receive), Fresnel reflections (all surfaces become more reflective at grazing angles), and how surfaces occlude themselves (what is called Geometry Term), among others.

Unity 5 includes what we call Standard Shader, which puts together a full PBS model and makes it easily accessible to Unity users. The Standard Shader is designed with hard surfaces in mind (which are also known as “architectural” materials), and can deal with most real world materials like stone, ceramics, brass, silver or rubber. It will even do a decent job with non-hard materials like skin, hair or cloth.

What about “my” content?

Keep in mind that Physically Based Shading doesn’t necessarily mean “realistic”, and it doesn’t mean it will dictate how the game (or the assets) look by imposing limitations. It adapts to different styles and esthetics ranging from accurately scanned- , to traditionally photographed-, to hand-painted textures.

For you guys making a flat-lit 2D sprite based game – PBS is not on the top of your need-to-have list. But… if you want to play with PBS and get the best out of the Standard shader we have a few tips for you!

Let’s dive in!

When thinking about lighting in Unity 5, it is handy to divide concepts into what we called the Context, which is information that comes from Unity itself and the Content, which is the information that is authored by you directly.

The Context

When lighting an object it is important to have an understanding on what the environment around the object looks like. Unity has classically had helpers, like light probes, that would be able to sample the diffuse lighting in a location. In Unity 5 we go much further:

Covering the whole range

HDR information is one important element for PBS. For instance, it helps to have information of environments where the sun can be ten times brighter than a blue sky. Unity 5 has a new native pipeline for HDR formats, you can just import .hdr and .exr images directly.

Adding shine

Reflection probes represent the reflections that exist at a certain location. There is one by default in a scene in Unity 5 (which you can look at in Edit->Scene Render Settings->Default Reflection). That reflection can be custom or depend purely on the sky and have no location.

You can, of course, create your own reflection probes. Just go to GameObject->Light->Create Reflection probe.

You’ll get something that looks like the image to the right:

You can then just drag it to whatever location in the scene and it’ll take care of getting information on what the surroundings look like.

Every reflection probe has an area of influence (that shows as a yellow box around the probe). Objects inside that box will pick their reflection data from the probe.

More per-pixel:

Thanks to Unity 5’s dynamic GI, light probes now also contain indirect light bounces, which the Standard shader applies per pixel. Normal maps now look great whether or not light is hitting them directly.

In this scene there is a single light pointing downwards, the sides and bottom of the barrel get no contributions from directional lighting.

Dynamic GI

Global illumination is an important part of the context that’s needed for PBS. To get a comprehensive overview of how it will work in Unity 5 nothing better than to check our blogpost on Dynamic GI

Color Space

PBS and the Standard shader work both in Linear and Gamma modes. HDR encoding, the data in reflections probes and the rest of the content will adapt to the color space you choose. But you should keep in Linear space whenever possible for the most correct (and usually most pleasing) visual results.

The Content

Content is the data that is directly authored by you. The Standard shader does bring a few changes to the traditional Unity material workflow that we hope you will like.

The Material Editor

(as introduced in an earlier blogpost)

The Standard shader introduces a new material editor. The new editor tries to make it easier to work with PBS materials than what it was with non-PBS materials before.

The editor is more compact now, with all possible options for the material there, from the get go. No need to choose a different shader to change texture channels, no more “texture unused, please choose another shader” messages. No more changing shader to change the blending mode.

You have a number of texture slots, which are not mandatory, any slot that is left empty will have its code optimised away so you don’t have to worry about it. Unity will take whatever data you put on the editor and create the right code to make it run at maximum efficiency.

Tip: You can Ctrl+click on textures for a large preview, which will also let you check the contents of the color  and alpha channels separately!

Lighting as you would expect

Of course this whole PBS talk also combines with Unity 5’s dynamic GI workflow, the GI system is totally aware of the way the Standard shader behaves and takes that into account when lighting a scene.

The combination of PBS and Enlighten GI make it possible to change the lighting conditions of an entire scene quickly, and get results that make sense!

For this village, you will notice that the last shot has a different lighting setup than the scene with which we opened this post. Still objects look solid and deep, everything just falls in place. That’s exactly what the physically-based shading magic is all about. Once materials are built taking PBS into account, they become completely independent of the lighting conditions, it actually is a ton less work to work with PBS.

That’s why we love it, and that’s why we think you’ll love it too.


The Viking Village will be invading an Asset Store near you when 5.0 ships!

Next we’ll be digging into how exactly material channels are put together, tips and hints on how to author textures and a lot more! Stay tuned in you are interested on in-depth asset creation details!

55 replies on “Physically Based Shading in Unity 5: A Primer”

[…] download start creating games, Unity account you need a unity account to shop in the online and asset stores, […]

Will it be possible to adjust specular reflection based on normal angle to the camera. Usually done by using fresnel approximations. It’s quite important to be able to create realistic materials and I can’t see any input value that allows us to do that here. For example there is a big difference in how glass and chrome works. With glass the reflection becomes a lot stronger when you look at the surface at glancing angles, while it is almost invisible when you look directly towards the glass surface. On a chrome surface the angle of the surface compared to the camera matters less.

I guess you expect us to add this ourselves? Not hard to do, I just thought it should be part of the standard shader.

I have to change the way i create my 3d assets/models or texture to tale the benefits PBS? Or i just create the models and apply the texture ad i did before (ie with a diffuse map, a normal map and if its the case a specular map) ? There is a tutorial that explain what change from the 3d asset creation side so that pple that sells 3d models on the asset store knows right now how to prepare their models to being used with PBS instead of making their work not compatible with PBS?

Can this system be customized like ShaderLab or is it a closed system? What if I want to pack data into a single texture (for example albedo, spec, occlusion and masks) for single texture read? Is that possible?

that would be great added some features like image effects, at least not as many as there are in unity pro, but at least some basic effects to the free version of unity. :)

I have a scene with ocean all around and a offshore vessel that is moving (floating).. the cranes and equipment on the ship is also dynamic..
How should I set that scene up to get good lightning…
Earlier I could bake the ship as Static, and then just uncheck the static box, and still have baked lightmaps on the ship even it was moving…. this is not possible now.. because I cannot move object when checked as lightmap static…

There is a little triangle. Where you can specify what type of static you want.
Eg. you can specify lightmap static vs batching static.

That said, the workflow you describe is also possible in unity 5, you simply go out of iterative mode and into on demand mode, thus you have a traditional bake button style workflow if that is what you prefer.
(That said, the approach you describe with mark static / hit bake / revert mark static is a poor workflow and it is definately recommended to use the accurate static setting for your boat)

Nice post! I really can’t wait for the release of the Viking Village Asset and of course, Unity 5! The new PBS is awesome!

The new material editor GUI looks nice, but I have one question, where can I place my roughness map on that material editor?

Roughness you can plug into the alpha of the Specular map. Keep in mind that we use smoothness rather than roughness (the brighter the map the shinier the object)

i have a question: is the new shader modular? as in can i write a parallax occlusion effect and a tessellation effect and mix/match? if so this would be awesome for the asset store as people could make individual shader parts instead of full shaders. more compatibility.

In lighting an outdoor scene like the VIking example you showed, What percentage of light in the scene should be handled by the Dynamic GI / Skyboxes vs Directional Lights to get a nice out door look? Finding a balance between the two has been a struggle for me.

Btw, there is also a bug on the website. I read all the comments until the bottom, but for some reason I can’t scroll all the way up to the header of the website. The top part of the website is unreachable after reading all comments. I use Google Chrome

it’s good to read that the viking scene is comming to the assets store. I think a lot of people could learn from that kind of scenes.

I’ve also looked trough the videos about Unity 5.x and I was wondering if we can expect more demo scenes. I saw this transporter scene and the scene with a living room in a glass cilinder. Can we expect those to appear in the asset store as well? Would be cool to be honest.

Last thing to notice with this PBS workflow. In some cases you want this whole sky to appear, have your materials nicely reflecting but in some cases you do not want this sky but you do want the reflections. What I mean is product visualisation, where materials appear to be realistic with reflections and GI, but the sky is pitch black or a gradient. For now what I’ve played with, they sky influences GI and reflections, but can I have all the goodies without the sky appearing?

Further on, keep these blog posts comming, I enjoy reading them. :)

Can’t wait to start using PBS in my games. One question though, is this fully supported targeting iOS? performance? Limitations?

The 5 version of Unity will have the browser of assets enhanced, or will be satanically slow as in version 4.5.5 ???

Someone said that disabling some network devices improves the speed who you acess the assets, but this is a bug, so I wonder if it will continue the same hell to access the Unity Asset Store?

If you’re talking about the in-editor asset store interface… I think it’s much, much smoother in 5.0.

Yes, I talked the internal web browser, this buggy it is very very slow, it takes 10 minutes for me to to access the page from a plugin, the 3D model, etc.

But this bug can not be fixed in version 4.6 for example ??? The sooner the better, and should not be complex.

For you Blender users, this of it as rendering with the internal rendering engine and cycles. The internal engine can certainly render it fine, but cycles renders it in a more realistic manner with better lighting behavior.

Not sure what you mean. There’s a texture map for specular color (RGB) and glosiness aka smoothness (aka “inverse of roughness”) in alpha channel right there in the material.

This is cool, but I was expecting something along the lines of the UE4 Meterial Editor… any hope to see something like that happen?

Would love to get my hands on that viking village. There isn’t too much public info on PBR and most of it’s limited to very shiny materials. I struggled a bit trying to create convincing unfinished wood since that is very much not shiny so I’ll be studying your examples and I hope you guys could give some info on how the materials were created.

Look in the learn section of the Unity website, and watch the video on the standard shader. There is one point where the spec. maps on diffuse materials are shown. They’re all a very dark grey.

The standard shader, PBR lighting, GI and Enlighten will be part of the Unity 5 foundation. As far as I know, any discussion on where the “free/pro feature split” will be hasn’t happened yet. Rest assured, you will be able to make your game successfully in whatever version you choose.

Very cool. Is there any information about what will be available in free vs pro? It seems like this is replacing the current lighting system. How about mobile lightning?

The standard shader, PBR lighting, GI and Enlighten will be part of the Unity 5 foundation. As far as I know, any discussion on where the “free/pro feature split” will be hasn’t happened yet. Rest assured, you will be able to make your game successfully in whatever version you choose.

(Whoops! Replied to the wrong post!)

So hype us up with features only to announce they are for pro users.. I have to say I do tire of this strategy Unity Tech.

Comments are closed.