unity着色器_Unity 5中基于物理的着色:入门
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.
什么是基于物理的阴影? 基于物理的阴影(简称PBS)以模仿现实的方式模拟材料和光线之间的相互作用。 PBS直到最近才在实时图形中成为可能。 在照明和材料需要直观和现实地融合的情况下,这是一个巨大的胜利。
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.
Unity 5包括我们所谓的Standard Shader,它汇集了完整的PBS模型,并易于Unity用户访问。 标准着色器在设计时考虑到坚硬的表面(也称为“建筑”材料),并且可以处理大多数现实世界中的材料,例如石材,陶瓷,黄铜,银或橡胶。 它甚至可以对皮肤,头发或布料等非硬质材料起到不错的作用。
那“我的”内容呢? (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!
对于制作基于平面2D精灵的游戏的人来说-PBS不在您的必备列表中。 但是……如果您想使用PBS并从标准着色器中获得最大的收益,我们将为您提供一些技巧!
让我们潜入吧! (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.
在考虑Unity 5中的照明时,将概念划分为所谓的Context很方便,这是来自Unity本身的信息和Content,这是您直接编写的信息。
上下文 (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:
照明物体时,重要的是要了解物体周围的环境。 传统上,Unity拥有助手,例如光探测器,可以在某个位置对漫射照明进行采样。 在Unity 5中,我们可以更进一步:
覆盖整个范围 (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.
HDR信息是PBS的重要元素之一。 例如,它有助于获得太阳比蓝天明亮十倍的环境信息。 Unity 5有一个用于HDR格式的新本机管道,您可以直接导入.hdr和.exr图像。
增加光泽 (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.
反射探针表示存在于特定位置的反射。 默认情况下,Unity 5中的场景中只有一个(可以在“编辑”->“场景渲染设置”->“默认反射”中查看)。 反射可以是自定义的,也可以完全取决于天空,并且没有位置。
You can, of course, create your own reflection probes. Just go to GameObject->Light->Create Reflection probe.
当然,您可以创建自己的反射探针。 只需转到GameObject-> Light-> Create Reflection探针。
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.
多亏了Unity 5的动态GI,光探测器现在还包含间接的光反弹,“标准”着色器按像素应用此反弹。 现在,无论光线是否直接照射到法线贴图,它们都看起来很棒。
In this scene there is a single light pointing downwards, the sides and bottom of the barrel get no contributions from directional lighting.
在此场景中,只有一个灯光指向下方,发条盒的侧面和底部均不受定向照明的影响。
动态GI (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
全局照明是PBS所需的上下文的重要组成部分。 要全面了解它如何在Unity 5中工作,最好的方法就是查看我们关于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.
PBS和标准着色器在“线性”和“伽玛”模式下均可工作。 HDR编码,反射探针中的数据以及其余内容将适应您选择的色彩空间。 但是您应该尽可能地保持在线性空间中,以获得最正确(通常最令人愉悦)的视觉效果。
内容 (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.
内容是您直接创作的数据。 标准着色器确实对我们希望您喜欢的传统Unity材质工作流进行了一些更改。
材质编辑器 (The Material Editor)
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.
标准着色器引入了新的材质编辑器。 新的编辑器试图使使用PBS材料的工作比以前使用非PBS材料的工作更容易。
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.
您有许多纹理插槽(不是必须的),任何保留为空的插槽都会优化其代码,因此您不必担心。 Unity将获取您输入到编辑器中的所有数据,并创建正确的代码以使其以最高效率运行。
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!
提示:您可以按住Ctrl键并单击纹理以进行大预览,这也可以让您分别检查颜色和Alpha通道的内容!
如您所愿照明 (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.
当然,整个PBS演讲也结合了Unity 5的动态GI工作流程,GI系统完全了解标准着色器的行为方式,并在照明场景时将其考虑在内。
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!
PBS和Enlighten GI的组合使快速更改整个场景的照明条件成为可能,并获得有意义的结果!
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.
对于这个村庄,您会注意到上一张照片的照明设置与我们打开此帖子的场景不同。 静止的物体看起来坚实而深沉,一切都就位。 这正是基于物理的着色魔术的全部含义。 一旦构建了考虑了PBS的材料,它们就完全不受光照条件的影响,使用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!
当5.0发货时,维京村将入侵您附近的资源商店!
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!
接下来,我们将深入研究如何精确地组合材质通道,有关如何编写纹理的提示和提示以及更多内容! 请继续关注您对深入的资产创建细节的兴趣!
翻译自: https://blogs.unity3d.com/2014/10/29/physically-based-shading-in-unity-5-a-primer/
unity着色器