当前位置: 首页 > news >正文

unity shader——BRDF分析

在这里插入图片描述
在这个文件中,我们先来看一个函数:

// Based on Minimalist CookTorrance BRDF 
// Implementation is slightly different from original derivation: http://www.thetenthplanet.de/archives/255
// * NDF (depending on UNITY_BRDF_GGX):
//  a) BlinnPhong
//  b) [Modified] GGX
// * Modified Kelemen and Szirmay-​Kalos for Visibility term
// * Fresnel approximated with 1/LdotH
half4 BRDF2_Unity_PBS (half3 diffColor, half3 specColor, half oneMinusReflectivity, half smoothness,
    float3 normal, float3 viewDir,
    UnityLight light, UnityIndirect gi)
{

最简化的CookTorrance模型的BRDF。

参数的解释:
diffColor——漫反射颜色
specColor——镜面反射颜色
oneMinusReflectivity——1减去反射率
smoothness——光滑度
normal——法线
viewDir——视角向量
light——unity内置光源结构体,直接光UnityLight
gi——全局光照gi结构体,间接光UnityIndirect

这两个结构体在UnityLightingCommon.cginc中:

struct UnityLight
{
    half3 color;
    half3 dir;
    half  ndotl; // Deprecated: Ndotl is now calculated on the fly and is no longer stored. Do not used it.
};

struct UnityIndirect
{
    half3 diffuse;
    half3 specular;
};

接着函数:

float3 halfDir = Unity_SafeNormalize (float3(light.dir) + viewDir);
half nl = saturate(dot(normal, light.dir));
float nh = saturate(dot(normal, halfDir));
half nv = saturate(dot(normal, viewDir));
float lh = saturate(dot(light.dir, halfDir));

1、计算了光方向和视角向量的半角向量
2、ndotl
3、nh
4、nv
5、lh

// Specular term
half perceptualRoughness = SmoothnessToPerceptualRoughness (smoothness);
half roughness = PerceptualRoughnessToRoughness(perceptualRoughness);

perceptual是知觉的意思。SmoothnessToPerceptualRoughness 函数和PerceptualRoughnessToRoughness函数的原型如下:

float SmoothnessToPerceptualRoughness(float smoothness)
{
    return (1 - smoothness);
}
float PerceptualRoughnessToRoughness(float perceptualRoughness)
{
    return perceptualRoughness * perceptualRoughness;
}
#if UNITY_BRDF_GGX

    // GGX Distribution multiplied by combined approximation of Visibility and Fresnel
    // See "Optimizing PBR for Mobile" from Siggraph 2015 moving mobile graphics course
    // https://community.arm.com/events/1155
    half a = roughness;
    float a2 = a*a;
    float d = nh * nh * (a2 - 1.f) + 1.00001f;
#ifdef UNITY_COLORSPACE_GAMMA

https://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.pdf

5.1 choosing F, D, and G
using equations 20 and 21, requires appropriate choices for the F, D, and G, terms. the fresnel term is the best understood, and exact equations are available in the literature. the fresnel term is typically small at normal incidence (e.g., 0.04 for glass with ηt = 1.5) and increases to unity at grazing angles or for total internal reflection. a convenient exact for mulation for dielectrics with unpolarized light is:
在这里插入图片描述

note that if g is imaginary 虚数, this indicates total internal reflection and F=1 in this case. cheaper approximations for F are also sometimes used.
a wide variety of microfacet distribution functions D have been proposed. in this paper, we discuss three different types: beckmann, phong, and ggx. the beckmann distribution arises from guassian roughness assumptions for the microsurfuace and is widely used in the optics literature. the phong distribution is purely empirical one developed in the graphics literature; however, with suitable choices of width parameters it is very similar to the beckmann distribution. the ggx distribution is new, and we developed it to better match our measured data for transmission. equations for the three distribution types and related functions are given at the end of this section.

the shadowing-masking term G depends on the distribution function D and the details of the microsurface, so exact solutions are rarely possible. cook & torrance used a G based on a 1D model of parallel grooves that guarantees energy conservation for any distribution D, but we do not recommend using it because it contains first derivative discontinuities and other features not seen in real surfaces. instead we will use the smith shadowing-masking approximation. the smith G was originally derived for gaussian rough surfaces, but has since been extend to handle surfaces with arbitrary distribution functions though in some cases, (e.g…, phong), the resulting integrals have no simple closed form solution.

the smith G approximates the bidirectional shadowing masking as the separable product of two monodirectional shadowing terms G1:
在这里插入图片描述
where G1 is derived form the microfacet distribution D as described in [SMITH B. G.: Geometrical shadowing of a random rough surface. IEEE Trans. on Antennas and Propagation (1967), 668–671.] and appendix A.
smith actually derived two different shadowing functions: one when the microsurface normal m is known, and another averaged over all microsurface normals. although the latter is more frequently used in the literature, in microfacet models, where we know the microsurface normal of interest, the former is more appropriate and we use it in this paper.

相关文章:

  • 基于Redis实现简单的分布式锁【理论】
  • 学习java编程艺术文章的储存与整理第一章
  • 关于BRDF的一些总结——转自其他博客
  • js map 、filter 、forEach 、every、some 的用法
  • 【视频版】PDF合并器破解视频教程
  • git 随笔(随时更新)
  • C# 使用Exchange WebService读取联系人
  • Crafting 手工 Physically Motivated Shading Models for Game Development
  • 001 Android TextUtils工具类的使用
  • windows下安装oracle11g测试是否成功与监听器问题和网页控制台登录
  • unity复制到剪切板
  • 软件开发的权限控制和权限验证
  • PBR论文链接
  • 词频统计
  • 云时代架构阅读笔记四——深入的、详细的介绍Map以及HashMap
  • 【5+】跨webview多页面 触发事件(二)
  • Android开发 - 掌握ConstraintLayout(四)创建基本约束
  • vue从创建到完整的饿了么(18)购物车详细信息的展示与删除
  • vue总结
  • Webpack4 学习笔记 - 01:webpack的安装和简单配置
  • Web标准制定过程
  • windows下mongoDB的环境配置
  • 面试总结JavaScript篇
  • 全栈开发——Linux
  • 为物联网而生:高性能时间序列数据库HiTSDB商业化首发!
  • 一道面试题引发的“血案”
  • 教程:使用iPhone相机和openCV来完成3D重建(第一部分) ...
  • ​如何防止网络攻击?
  • #mysql 8.0 踩坑日记
  • #vue3 实现前端下载excel文件模板功能
  • #宝哥教你#查看jquery绑定的事件函数
  • #使用清华镜像源 安装/更新 指定版本tensorflow
  • (26)4.7 字符函数和字符串函数
  • (Ruby)Ubuntu12.04安装Rails环境
  • (第61天)多租户架构(CDB/PDB)
  • (十八)devops持续集成开发——使用docker安装部署jenkins流水线服务
  • (十一)图像的罗伯特梯度锐化
  • (原創) 系統分析和系統設計有什麼差別? (OO)
  • (转)C#调用WebService 基础
  • (转)Java socket中关闭IO流后,发生什么事?(以关闭输出流为例) .
  • (转)linux下的时间函数使用
  • (转)大型网站架构演变和知识体系
  • (转)我也是一只IT小小鸟
  • ..回顾17,展望18
  • .NET Core 2.1路线图
  • .NET Core 网络数据采集 -- 使用AngleSharp做html解析
  • .Net Core/.Net6/.Net8 ,启动配置/Program.cs 配置
  • .NET 使用 JustAssembly 比较两个不同版本程序集的 API 变化
  • .NET 依赖注入和配置系统
  • .netcore如何运行环境安装到Linux服务器
  • .NET使用存储过程实现对数据库的增删改查
  • ??在JSP中,java和JavaScript如何交互?
  • [ Algorithm ] N次方算法 N Square 动态规划解决
  • []我的函数库
  • [Android 13]Input系列--获取触摸窗口