Lighting Models and BRDF Maps

Bi-directional Reflectance Distribution Function (BRDF) is a mathematical function that describes how light is reflected when it hits a surface. This largely corresponds to a lighting model in Unity-speak (although note that BDRFs are concerned only with reflected light, whereas lighting models can also account for emitted light and other lighting effects).

The “bi-directional” bit refers to the fact that the function depends on two directions:

  • the direction at which light hits the surface of the object (the direction of incidence, ωi)
  • the direction at which the reflected light is seen by the viewer (the direction of reflection, ωr).

These are typically both defined relative to the normal vector of the surface, n, as shown in the following diagram (rather than simple angles, each direction is actually modelled in the BRDF using spherical coordinates (θφ) making the BRDF a four-dimensional function):

File:BRDF Diagram.svg

 

Given that our perception of a material is determined to a large extent by its reflectance properties, it’s understandable that several different BRDFs have been developed, with different effectiveness and efficiency at modelling different types of surfaces:

  • Lambert: Models perfectly diffuse smooth surfaces, in which apparent surface brightness is affected only by angle of incident light. The observer’s angle of view has no effect.
  • Phong and Blinn-Phong: Models specular reflections on smooth shiny surfaces by considering both the direction of incoming light and that of the viewer.
  • Oren-Nayar: Models diffuse reflection from rough opaque surfaces (considers surface to be made from many Lambertian micro-facets)
  • Torrance-Sparrow: Models specular reflection from rough opaque surfaces (considers surface to be made from many mirrored micro-facets).

In addition to the preceding links, there’s a good article explaining some of the maths behind these models at http://www.cs.princeton.edu/courses/archive/fall06/cos526/tmp/wynn.pdf

 

BRDF Maps

In the case of game development, it’s often not necessary to strive for physically-accurate BRDF models of how a surface reacts to light. Instead, it’s sufficient to aim for something that “looks” right. And that’s where BRDF maps come in (sometimes also called “Fake BRDF”).

A BRDF map is a two-dimensional texture. It’s used in a similar way to a one-dimensional “ramp” texture, which are commonly used to lookup replacement values for individual lighting coefficients. However, the BRDF map represents different parameters on each of its two axes – the incoming light direction and the viewing direction as shown below:

image

 

A shader can use a tex2D lookup based on these two parameters to retrieve the pixel colour value for any point on a surface as a very cheap way of modelling light reflection. Here’s an example Cg BRDF surface shader:

Shader "Custom/BRDF Ramp" {
  Properties {
    _MainTex ("Texture", 2D) = "white" {}
    _BRDF ("BRDF Ramp", 2D) = "gray" {}
  }
  SubShader {
    Tags { "RenderType" = "Opaque" }
    CGPROGRAM
    #pragma surface surf Ramp
 
    sampler2D _BRDF;
 
    half4 LightingRamp (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) {
         
        // Calculate dot product of light direction and surface normal
        // 1.0 = facing each other perfectly
        // 0.0 = right angles
        // -1.0 = parallel, facing same direction
        half NdotL = dot (s.Normal, lightDir);
         
        // NdotL lies in the range between -1.0 and 1.0
        // To use as a texture lookup we need to adjust to lie in the range 0.0 to 1.0
        // We could simply clamp it, but instead we'll apply softer "half" lighting
        // (which Unity calls "Diffuse Wrap")
        NdotL = NdotL * 0.5 + 0.5;
         
        // Calculate dot product of view direction and surface normal
        // Note that, since we only render front-facing normals, this will
        // always be positive
        half NdotV = dot(s.Normal, viewDir);
         
        // Lookup the corresponding colour from the BRDF texture map
        half3 brdf = tex2D (_BRDF, float2(NdotL, NdotV)).rgb;
         
        half4 c;
         
        // For illustrative purpsoes, let's set the pixel colour based entirely on the BRDF texture
        // In practice, you'd normally also have Albedo and lightcolour terms here too.
        c.rgb = brdf * (atten * 2);
        c.a = s.Alpha;
        return c;
    }
 
    struct Input {
        float2 uv_MainTex;
    };
    sampler2D _MainTex;
    void surf (Input IN, inout SurfaceOutput o) {
        o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
    }
    ENDCG
  }
  Fallback "Diffuse"
}

 

And here’s the image it produces – notice how the shading varies from red to yellow based on view direction, and from light to dark based on direction to the light source.

image

 

As a slightly less trivial example, here’s another BRDF texture map that again uses light direction relative to surface on the x axis, but this time, instead of using view direction, uses curvature of the surface on the y axis (the gradient in the y axis is quite subtle but you should be able to note reddish hue towards the top centre of the image, and blueish tint at the top right):

This map can be used to generate convincing diffuse reflection of skin that varies across the surface of the model (such that, say, the falloff at the nose appears different from the forehead), as shown here:

From:https://alastaira.wordpress.com/2013/11/26/lighting-models-and-brdf-maps/

展开阅读全文

Git 实用技巧

11-24
这几年越来越多的开发团队使用了Git,掌握Git的使用已经越来越重要,已经是一个开发者必备的一项技能;但很多人在刚开始学习Git的时候会遇到很多疑问,比如之前使用过SVN的开发者想不通Git提交代码为什么需要先commit然后再去push,而不是一条命令一次性搞定; 更多的开发者对Git已经入门,不过在遇到一些代码冲突、需要恢复Git代码时候就不知所措,这个时候哪些对 Git掌握得比较好的少数人,就像团队中的神一样,在队友遇到 Git 相关的问题的时候用各种流利的操作来帮助队友于水火。 我去年刚加入新团队,发现一些同事对Git的常规操作没太大问题,但对Git的理解还是比较生疏,比如说分支和分支之间的关联关系、合并代码时候的冲突解决、提交代码前未拉取新代码导致冲突问题的处理等,我在协助处理这些问题的时候也记录各种问题的解决办法,希望整理后通过教程帮助到更多对Git操作进阶的开发者。 本期教程学习方法分为“掌握基础——稳步进阶——熟悉协作”三个层次。从掌握基础的 Git的推送和拉取开始,以案例进行演示,分析每一个步骤的操作方式和原理,从理解Git 工具的操作到学会代码存储结构、演示不同场景下Git遇到问题的不同处理方案。循序渐进让同学们掌握Git工具在团队协作中的整体协作流程。 在教程中会通过大量案例进行分析,案例会模拟在工作中遇到的问题,从最基础的代码提交和拉取、代码冲突解决、代码仓库的数据维护、Git服务端搭建等。为了让同学们容易理解,对Git简单易懂,文章中详细记录了详细的操作步骤,提供大量演示截图和解析。在教程的最后部分,会从提升团队整体效率的角度对Git工具进行讲解,包括规范操作、Gitlab的搭建、钩子事件的应用等。 为了让同学们可以利用碎片化时间来灵活学习,在教程文章中大程度降低了上下文的依赖,让大家可以在工作之余进行学习与实战,并同时掌握里面涉及的Git不常见操作的相关知识,理解Git工具在工作遇到的问题解决思路和方法,相信一定会对大家的前端技能进阶大有帮助。
©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值