Unity3D 的物理渲染和光照模型(3)

简单来说就是,光是电磁波啊,其行为因接触到的是导体还是绝缘体而不同(电磁波唱由电场和磁场组成,但电场属性实际上比磁场属性更重要)。在镜面工作流中, 所提供的是镜面映射。尽管被当做两个不同的东西呈现出来, 金属材料和镜面材料实际上以不同的方式初始化同一个着色器;Marmoset 上有一个很好的例程展现了同样的材料如何通过金属和镜面工作流分别创建。这也是为什么当第一次接触 Unity5 着色器时会因为源代码中出现了同一事物却有两个工作流现象时会产生误解。 Joe Wilson 创建了一个相当清晰的例程来知道我们的艺术家:如果你想学习怎么通过 PBR 创建非常逼真的材质,这将是非常好的开始哟。如果需要更详细的技术信息,在 Unity5 博客里关于 PBR 的地方猛戳a very well done primer

metallic

Unity5 中新光照模型名字既简单又标准。取这个名字是因为现在 PBR 是每一个 Unity3D 中新建对象的初始材料。而且,每一个新建的着色器文件会被自动配置为一个 PBR 表面着色器:

Shader "Custom/NewShader" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
 
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
 
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
 
sampler2D _MainTex;
 
struct Input {
float2 uv_MainTex;
};
 
half _Glossiness;
half _Metallic;
fixed4 _Color;
 
void surf (Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
Shader "Custom/NewShader" {Properties {_Color ("Color", Color) = (1,1,1,1)_MainTex ("Albedo (RGB)", 2D) = "white" {}_Glossiness ("Smoothness", Range(0,1)) = 0.5_Metallic ("Metallic", Range(0,1)) = 0.0}SubShader {Tags { "RenderType"="Opaque" }LOD 200CGPROGRAM// Physically based Standard lighting model, and enable shadows on all light types#pragma surface surf Standard fullforwardshadows // Use shader model 3.0 target, to get nicer looking lighting#pragma target 3.0sampler2D _MainTex;struct Input {float2 uv_MainTex;};half _Glossiness;half _Metallic;fixed4 _Color;void surf (Input IN, inout SurfaceOutputStandard o) {// Albedo comes from a texture tinted by colorfixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;o.Albedo = c.rgb;// Metallic and smoothness come from slider variableso.Metallic = _Metallic;o.Smoothness = _Glossiness;o.Alpha = c.a;}ENDCG}FallBack "Diffuse"}

soldier standard

14行将告知 Unity3D 该表面着色器将使用 PBR 光照模型。17行 意味着该着色器将使用高级特性,因而其将不同在落后的硬件上使用。同样的, SurfaceOutput 也不能同 PBR 一起使用;而是必须使用  SurfaceOutputStandard

PBR 表面输出

SurfaceOutputStandard 中不光是 Albedo,Normal,Emission 和 Alpha 这些属性,还有三个新的:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/fb366dea235f5a11bd4d198e9f0d2501.html