下一步看像素着色器代码

half4 fragBase (VertexOutputForwardBase i) : SV_Target { return fragForwardBaseInternal(i); }

half4 fragForwardBaseInternal (VertexOutputForwardBase i)
{
FRAGMENT_SETUP(s)
#if UNITY_OPTIMIZE_TEXCUBELOD
s.reflUVW = i.reflUVW;
#endif UnityLight mainLight = MainLight ();
half atten = SHADOW_ATTENUATION(i); half occlusion = Occlusion(i.tex.xy);
UnityGI gi = FragmentGI (s, occlusion, i.ambientOrLightmapUV, atten, mainLight); half4 c = UNITY_BRDF_PBS (s.diffColor, s.specColor, s.oneMinusReflectivity, s.smoothness, s.normalWorld, -s.eyeVec, gi.light, gi.indirect);
c.rgb += UNITY_BRDF_GI (s.diffColor, s.specColor, s.oneMinusReflectivity, s.smoothness, s.normalWorld, -s.eyeVec, occlusion, gi);
c.rgb += Emission(i.tex.xy); UNITY_APPLY_FOG(i.fogCoord, c.rgb);
return OutputForward (c, s.alpha);
}
FRAGMENT_SETUP(s)等价于

FragmentCommonData s= FragmentSetup(i.tex, i.eyeVec, IN_VIEWDIR4PARALLAX(i), i.tangentToWorldAndParallax, IN_WORLDPOS(i));

struct FragmentCommonData
{
half3 diffColor, specColor;
// Note: smoothness & oneMinusReflectivity for optimization purposes, mostly for DX9 SM2.0 level.
// Most of the math is being done on these (1-x) values, and that saves a few precious ALU slots.
half oneMinusReflectivity, smoothness;
half3 normalWorld, eyeVec, posWorld;
half alpha; #if UNITY_OPTIMIZE_TEXCUBELOD || UNITY_STANDARD_SIMPLE
half3 reflUVW;
#endif #if UNITY_STANDARD_SIMPLE
half3 tangentSpaceNormal;
#endif
};

去掉分支

struct FragmentCommonData
{
half3 diffColor, specColor;
// Note: smoothness & oneMinusReflectivity for optimization purposes, mostly for DX9 SM2.0 level.
// Most of the math is being done on these (1-x) values, and that saves a few precious ALU slots.
half oneMinusReflectivity, smoothness;
half3 normalWorld, eyeVec, posWorld;
half alpha;
half3 reflUVW;
};
oneMinusReflectivity 看单词意思反射率,不知道干嘛的,存疑
看函数FragmentSetup
inline FragmentCommonData FragmentSetup (float4 i_tex, half3 i_eyeVec, half3 i_viewDirForParallax, half4 tangentToWorld[], half3 i_posWorld)
{
i_tex = Parallax(i_tex, i_viewDirForParallax); half alpha = Alpha(i_tex.xy);
#if defined(_ALPHATEST_ON)
clip (alpha - _Cutoff);
#endif FragmentCommonData o = UNITY_SETUP_BRDF_INPUT (i_tex);
o.normalWorld = PerPixelWorldNormal(i_tex, tangentToWorld);
o.eyeVec = NormalizePerPixelNormal(i_eyeVec);
o.posWorld = i_posWorld; // NOTE: shader relies on pre-multiply alpha-blend (_SrcBlend = One, _DstBlend = OneMinusSrcAlpha)
o.diffColor = PreMultiplyAlpha (o.diffColor, alpha, o.oneMinusReflectivity, /*out*/ o.alpha);
return o;
}
i_tex = Parallax(i_tex, i_viewDirForParallax);忽略,没用视差贴图,这句等于没用
half alpha = Alpha(i_tex.xy);
#if defined(_ALPHATEST_ON)
clip (alpha - _Cutoff);
#endif

clip不需要去掉

走进UNITY_SETUP_BRDF_INPUT ,默认是SpecularSetup

inline FragmentCommonData SpecularSetup (float4 i_tex)
{
half4 specGloss = SpecularGloss(i_tex.xy);
half3 specColor = specGloss.rgb;
half smoothness = specGloss.a; half oneMinusReflectivity;
half3 diffColor = EnergyConservationBetweenDiffuseAndSpecular (Albedo(i_tex), specColor, /*out*/ oneMinusReflectivity); FragmentCommonData o = (FragmentCommonData);
o.diffColor = diffColor;
o.specColor = specColor;
o.oneMinusReflectivity = oneMinusReflectivity;
o.smoothness = smoothness;
return o;
}

但是在standard.shader里有#define UNITY_SETUP_BRDF_INPUT MetallicSetup,所以其实是

inline FragmentCommonData MetallicSetup (float4 i_tex)
{
half2 metallicGloss = MetallicGloss(i_tex.xy);
half metallic = metallicGloss.x;
half smoothness = metallicGloss.y; // this is 1 minus the square root of real roughness m. half oneMinusReflectivity;
half3 specColor;
half3 diffColor = DiffuseAndSpecularFromMetallic (Albedo(i_tex), metallic, /*out*/ specColor, /*out*/ oneMinusReflectivity); FragmentCommonData o = (FragmentCommonData)0;
o.diffColor = diffColor;
o.specColor = specColor;
o.oneMinusReflectivity = oneMinusReflectivity;
o.smoothness = smoothness;
return o;
}

  把

FragmentSetup 和
FragmentGI 合并到一块
fixed4 frag(v2f i) : SV_Target
{ UnityLight mainLight = MainLight ();
half atten = SHADOW_ATTENUATION(i); UnityGIInput d;
d.light = mainLight;
d.worldPos = i.posWorld;
half3 worldViewDir = -normalize(i.eyeVec);
d.worldViewDir = worldViewDir
d.atten = atten;
d.ambient = i_ambientOrLightmapUV.rgb;
d.lightmapUV = ;
d.probeHDR[] = unity_SpecCube0_HDR;
d.probeHDR[] = unity_SpecCube1_HDR;
fixed metallic = _MetallicMin + channel.g * ( _Metallic - _MetallicMin );
half oneMinusReflectivity;
half3 specColor;
half3 diffColor = DiffuseAndSpecularFromMetallic (mainTex.rgb, metallic, /*out*/ specColor, /*out*/ oneMinusReflectivity);
fixed smoothness = ( _GlossinessMin + channel.r * (_Glossiness-_GlossinessMin) )* .99h;
half3 normalWorld = PerPixelWorldNormal(i.tex, i.tangentToWorldAndParallax )
Unity_GlossyEnvironmentData g = UnityGlossyEnvironmentSetup(smoothness, worldViewDir, s.normalWorld, specColor);
// Replace the reflUVW if it has been compute in Vertex shader. Note: the compiler will optimize the calcul in UnityGlossyEnvironmentSetup itself
g.reflUVW = i.reflUVW;
UnityGI gi = UnityGlobalIllumination (d, , normalWorld, g);
half4 c = BRDF(diffColor, specColor, oneMinusReflectivity, smoothness, normalWorld, worldViewDir, gi.light, gi.indirect);
c.rgb += BRDF_GI (diffColor, specColor, oneMinusReflectivity, smoothness, normalWorld, worldViewDir, , gi);
fixed emimask = tex2D(_EmissiveMap, i.uv).r;
fixed3 Emissive = emimask * _EmissiveColor.rgb * _EmissiveIntensity;
float3 _Rim = pow(1.0 - max(, dot(normalWorld, worldViewDir)), _RimArea)*_RimColor.rgb*_RimPower;
c.rgb += Emissive + _Rim;
UNITY_APPLY_FOG(i.fogCoord, c.rgb);
return OutputForward (c, );
}

后面部分加了自发光和边缘光

现在只剩下BRDF和BRDF_GI 了

standard pbr(二)的更多相关文章

  1. unity里standard pbr(一)

    关注forwardbase下的 standard.shader #pragma vertex vertBase #pragma fragment fragBase #include "Uni ...

  2. standard pbr(三)-BRDF

    // Default BRDF to use: #if !defined (UNITY_BRDF_PBS) // allow to explicitly override BRDF in custom ...

  3. PowerHA完全手册(二)

    http://www.aixchina.net/home/space.php?uid=1006&do=blog&id=40117 第二部分--安装配置篇2.1. 准备2.1.1. 安装 ...

  4. (转)PowerHA完全手册(一,二,三)

    PowerHA完全手册(一) 原文:http://www.talkwithtrend.com/Article/39889-----PowerHA完全手册(一) http://www.talkwitht ...

  5. Unity3d 屏幕空间人体皮肤知觉渲染&次表面散射Screen-Space Perceptual Rendering & Subsurface Scattering of Human Skin

    之前的人皮渲染相关 前篇1:unity3d Human skin real time rendering 真实模拟人皮实时渲染 前篇2:unity3d Human skin real time ren ...

  6. Jmeter遇到的坑

    一.分布式获取不到结果需要改配置文件   在jmeter.properties文件找到mode=Standard去掉# 二.有一个请求要循环查询进度,当进度为100为,跳出循环.这个要怎么操作? ${ ...

  7. elasticsearch系列三:索引详解(分词器、文档管理、路由详解(集群))

    一.分词器 1. 认识分词器  1.1 Analyzer   分析器 在ES中一个Analyzer 由下面三种组件组合而成: character filter :字符过滤器,对文本进行字符过滤处理,如 ...

  8. 小峰servlet/jsp(6)jstl核心标签库

    一.引入jstl 需要jstl.jar;standard.jar; 二.jstl核心标签库: c:out         内容输出标签; c:set      用来设置4种属性范围值的标签: c:re ...

  9. 看雪论坛 破解exe 看雪CTF2017第一题分析-『CrackMe』-看雪安全论坛

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 逆向 黑客 破解 学习 论坛 『CrackMe』 http://bbs.pediy.co ...

随机推荐

  1. C# socket编程 使用udp实现单对单的连接对话

    ipLocalPoint = new IPEndPoint(IPAddress.Parse("192.168.31.122"), 5000); //定义网络类型,数据连接类型和网络 ...

  2. EF中多表公共字段,以及设置EntityBase使所有实体类继承自定义类

    使用EF框架访问数据库时,如果某些表具有公共字段,例如在审核流程中,对于各类申请单资料的创建人.创建时间.修改人.修改时间,这些可能多表都需要的字段,如果在每个实体中进行赋值操作显然是类似和重复的,下 ...

  3. list操作总结. dict操作及文件操作

    1: 列表的操作 help(list) # 列表的帮助,列出所有列表的用法 type(name) # type判断数据类型是列表还是字典或者元组 isinstance("字符", ...

  4. iOS Framework: Introducing MKNetworkKit

    MKNetworkKit介绍,入门.翻译 这片文章也有塞尔维亚-克罗地亚语(由Jovana Milutinovich翻译)和日语(由@noradaiko翻译)  假设有个一个网络库可以自己主动的为你处 ...

  5. oracle10g安装,卸载

    一.安装 1.因为oracle的特殊性,笔者选择通过虚拟机安装windows7旗舰版安装数据库,大家的系统假设是windows xp.windows 7,windows 8能够直接安装,windows ...

  6. javacript计时

    简单的计时: var t=setTimeout("alert('5 秒!')",5000) 无限计时: var c=0 var t function timedCount() { ...

  7. 关于linux系统下 无法解析主机的问题

    linux无法解析主机 xxx: 解决方法: 1. sudo gedit /etc/hosts 找到如下行: 127.0.1.1       XXX 将其修改为: 127.0.1.1       (你 ...

  8. [转]详解JS闭包

    闭包(closure)是Javascript语言的一个难点,也是它的特色,很多高级应用都要依靠闭包实现. 闭包的特性 闭包有三个特性: 1.函数嵌套函数 2.函数内部可以引用外部的参数和变量 3.参数 ...

  9. FD_CLOEXEC用法及原因_转

    转自:使用FD_CLOEXEC实现close-on-exec,关闭子进程无用文件描述符 我们经常会碰到需要fork子进程的情况,而且子进程很可能会继续exec新的程序.这就不得不提到子进程中无用文件描 ...

  10. Linux gcc编译器

    GNU CC(通常称为GCC)是GNU项目的编译器,他能够编译C.C++语言编写的程序. 使用gcc,程序员可以对编译过程有更多控制,编译过程分为3个阶段. --预处理 --汇编 --链接 程序员可以 ...