下一步看像素着色器代码

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

  1. half4 fragForwardBaseInternal (VertexOutputForwardBase i)
  2. {
  3. FRAGMENT_SETUP(s)
  4. #if UNITY_OPTIMIZE_TEXCUBELOD
  5. s.reflUVW = i.reflUVW;
  6. #endif
  7.  
  8. UnityLight mainLight = MainLight ();
  9. half atten = SHADOW_ATTENUATION(i);
  10.  
  11. half occlusion = Occlusion(i.tex.xy);
  12. UnityGI gi = FragmentGI (s, occlusion, i.ambientOrLightmapUV, atten, mainLight);
  13.  
  14. half4 c = UNITY_BRDF_PBS (s.diffColor, s.specColor, s.oneMinusReflectivity, s.smoothness, s.normalWorld, -s.eyeVec, gi.light, gi.indirect);
  15. c.rgb += UNITY_BRDF_GI (s.diffColor, s.specColor, s.oneMinusReflectivity, s.smoothness, s.normalWorld, -s.eyeVec, occlusion, gi);
  16. c.rgb += Emission(i.tex.xy);
  17.  
  18. UNITY_APPLY_FOG(i.fogCoord, c.rgb);
  19. return OutputForward (c, s.alpha);
  20. }
  1. FRAGMENT_SETUP(s)等价于

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

  1. struct FragmentCommonData
  2. {
  3. half3 diffColor, specColor;
  4. // Note: smoothness & oneMinusReflectivity for optimization purposes, mostly for DX9 SM2.0 level.
  5. // Most of the math is being done on these (1-x) values, and that saves a few precious ALU slots.
  6. half oneMinusReflectivity, smoothness;
  7. half3 normalWorld, eyeVec, posWorld;
  8. half alpha;
  9.  
  10. #if UNITY_OPTIMIZE_TEXCUBELOD || UNITY_STANDARD_SIMPLE
  11. half3 reflUVW;
  12. #endif
  13.  
  14. #if UNITY_STANDARD_SIMPLE
  15. half3 tangentSpaceNormal;
  16. #endif
  17. };

去掉分支

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

clip不需要去掉

走进UNITY_SETUP_BRDF_INPUT ,默认是SpecularSetup

  1. inline FragmentCommonData SpecularSetup (float4 i_tex)
  2. {
  3. half4 specGloss = SpecularGloss(i_tex.xy);
  4. half3 specColor = specGloss.rgb;
  5. half smoothness = specGloss.a;
  6.  
  7. half oneMinusReflectivity;
  8. half3 diffColor = EnergyConservationBetweenDiffuseAndSpecular (Albedo(i_tex), specColor, /*out*/ oneMinusReflectivity);
  9.  
  10. FragmentCommonData o = (FragmentCommonData);
  11. o.diffColor = diffColor;
  12. o.specColor = specColor;
  13. o.oneMinusReflectivity = oneMinusReflectivity;
  14. o.smoothness = smoothness;
  15. return o;
  16. }

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

  1. inline FragmentCommonData MetallicSetup (float4 i_tex)
  2. {
  3. half2 metallicGloss = MetallicGloss(i_tex.xy);
  4. half metallic = metallicGloss.x;
  5. half smoothness = metallicGloss.y; // this is 1 minus the square root of real roughness m.
  6.  
  7. half oneMinusReflectivity;
  8. half3 specColor;
  9. half3 diffColor = DiffuseAndSpecularFromMetallic (Albedo(i_tex), metallic, /*out*/ specColor, /*out*/ oneMinusReflectivity);
  10.  
  11. FragmentCommonData o = (FragmentCommonData)0;
  12. o.diffColor = diffColor;
  13. o.specColor = specColor;
  14. o.oneMinusReflectivity = oneMinusReflectivity;
  15. o.smoothness = smoothness;
  16. return o;
  17. }

  把

  1. FragmentSetup
  1. FragmentGI 合并到一块
  1. fixed4 frag(v2f i) : SV_Target
  2. {
  3.  
  4. UnityLight mainLight = MainLight ();
  5. half atten = SHADOW_ATTENUATION(i);
  6.  
  7. UnityGIInput d;
  8. d.light = mainLight;
  9. d.worldPos = i.posWorld;
  10. half3 worldViewDir = -normalize(i.eyeVec);
  11. d.worldViewDir = worldViewDir
  12. d.atten = atten;
  13. d.ambient = i_ambientOrLightmapUV.rgb;
  14. d.lightmapUV = ;
  15. d.probeHDR[] = unity_SpecCube0_HDR;
  16. d.probeHDR[] = unity_SpecCube1_HDR;
  17. fixed metallic = _MetallicMin + channel.g * ( _Metallic - _MetallicMin );
  18. half oneMinusReflectivity;
  19. half3 specColor;
  20. half3 diffColor = DiffuseAndSpecularFromMetallic (mainTex.rgb, metallic, /*out*/ specColor, /*out*/ oneMinusReflectivity);
  21. fixed smoothness = ( _GlossinessMin + channel.r * (_Glossiness-_GlossinessMin) )* .99h;
  22. half3 normalWorld = PerPixelWorldNormal(i.tex, i.tangentToWorldAndParallax )
  23. Unity_GlossyEnvironmentData g = UnityGlossyEnvironmentSetup(smoothness, worldViewDir, s.normalWorld, specColor);
  24. // Replace the reflUVW if it has been compute in Vertex shader. Note: the compiler will optimize the calcul in UnityGlossyEnvironmentSetup itself
  25. g.reflUVW = i.reflUVW;
  26. UnityGI gi = UnityGlobalIllumination (d, , normalWorld, g);
  27. half4 c = BRDF(diffColor, specColor, oneMinusReflectivity, smoothness, normalWorld, worldViewDir, gi.light, gi.indirect);
  28. c.rgb += BRDF_GI (diffColor, specColor, oneMinusReflectivity, smoothness, normalWorld, worldViewDir, , gi);
  29. fixed emimask = tex2D(_EmissiveMap, i.uv).r;
  30. fixed3 Emissive = emimask * _EmissiveColor.rgb * _EmissiveIntensity;
  31. float3 _Rim = pow(1.0 - max(, dot(normalWorld, worldViewDir)), _RimArea)*_RimColor.rgb*_RimPower;
  32. c.rgb += Emissive + _Rim;
  33. UNITY_APPLY_FOG(i.fogCoord, c.rgb);
  34. return OutputForward (c, );
  35. }

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

现在只剩下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. 纪念我人生中第一个merge into语句

    做按组织关系汇总功能时,当数据量特别大,或者汇总组织特别多时,运行效率特别低,于是使用了merge into语句. 代码如下: public void updateInsertData(DataSet ...

  2. spring学习笔记(五)

    1.后置通知 需求:调用相应业务方法后,完成资源的关闭. a. 在beans.xml中配置 .... <beans> <!--配置被代理对象--> <bean id=&q ...

  3. 转:EMQTT测试--安装与测试 (windows)

    官网 我下载的是windows版 安装 参考 http://emqtt.com/docs/install.html 将下载的压缩包解压,我解压到了D盘 命令行窗口,cd到程序目录 控制台模式启动: . ...

  4. UVA 1262 Password 暴力枚举

    Password Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVA. Original ID:  ...

  5. Atitit.编程语言新特性 通过类库框架模式增强 提升草案 v3 q27

    Atitit.编程语言新特性 通过类库框架模式增强 提升草案 v3 q27 1. 修改历史2 2. 适用语言::几乎所有编程语言.语言提升的三个渠道::语法,类库,框架,ide2 2.1. 单根继承  ...

  6. 基于Verilog的以2为底取对数函数log2(x)

    参考资料:xilinx AXI4 Stream Peripherals 源码 //*********************************************************** ...

  7. 一些I2S的基础概念

    在数字音频Datasheet中,我们经常看到256FS,384FS,32kHz,44.1kHz MCLK等概念.一般在数字音频芯片用3个pin作为通讯接口:BCLK,ADCLRC,DOUT.现在做个总 ...

  8. ubuntu 12.10 apt-get 源

    更改apt-get源配置文件/etc/apt/sources.list 用一下内容替换掉 deb http://mirrors.163.com/ubuntu/ precise main restric ...

  9. eclipse通过maven远程发布应用到Tomcat

    好久没有写博客了,今天为大家分享一下如何在eclipse通过maven远程发布应用到Tomcat. 一般情况下,我们发布应用到服务器需要现将应用导出成war包,然后连接服务器部署更新,这样是很耗时的, ...

  10. MongoDb数据结构详解

    首先,向数据库插入一条bjson数据 首先是定义文档,然后使用admin用户名密码登录,进入test数据库,向test数据库中插入此文档(“表名称和表中的记录”) 插入结果,查看mongoVUE如下图 ...