Custom lighting models in Surface Shaders 表面着色器自定义光照模型 - Unity Shader Reference 系列4

本文详细介绍了如何在Unity的Surface Shaders中创建自定义光照模型,包括漫射、包裹漫射、卡通渐变和简单高光等效果。通过自定义光照模型,可以实现对物体表面光照的精细控制,模拟各种视觉效果。
摘要由CSDN通过智能技术生成

Custom lighting models in Surface Shaders 表面着色器自定义光照模型

本文档主要是对Unity官方手册的个人理解与总结(其实以翻译记录为主:>)
仅作为个人学习使用,不得作为商业用途,欢迎转载,并请注明出处。
文章中涉及到的操作都是基于Unity2018.2版本
参考链接:https://docs.unity3d.com/Manual/SL-SurfaceShaderLighting.html
https://docs.unity3d.com/Manual/SL-SurfaceShaderLightingExamples.html

When writing Surface Shaders, you describe the properties of a surface (such as albedo color and normal), and a Lighting Model computes the lighting interaction.
当你在写表面着色器时,你描述了一个表面的属性(比如albedo颜色和法线),一个光照模型计算了灯光的相互作用。

There are two built-in lighting models: Lambert for diffuse lighting, and BlinnPhong for specular lighting. The Lighting.cginc file inside Unity defines these models (Windows: /Data/CGIncludes/Lighting.cginc; macOS: /Applications/Unity/Unity.app/Contents/CGIncludes/Lighting.cginc).
有两种内置的光照模式:用于漫射光照的兰伯特(Lambert ),以及用于高光光照的BlinnPhong光照。Lighting.cginc文件在Unity中定义了这些模型(Windows: /Data/CGIncludes/Lighting.cginc; macOS:/Applications/Unity/Unity.app/Contents/CGIncludes/Lighting.cginc).

Sometimes you might want to use a custom lighting model. You can do this with Surface Shaders. A lighting model is simply a couple of Cg/HLSL functions that match some conventions.
有时您可能想要使用自定义的光照模型。你可以用表面着色器来做。光照模型仅仅是一些与某些约定相匹配的Cg/HLSL函数。

Declaring lighting models 声明光照模型

A lighting model consists of regular functions with names that begin Lighting. You can declare them anywhere in your shader file, or one of the included files. The functions are:
光照模型名称是由Lighting开始的常规函数组成。您可以在shader文件的任何地方声明它们,也可以在其中一个包含的文件中声明它们。函数有:

  1. half4 Lighting (SurfaceOutput s, UnityGI gi); Use this in forward rendering paths for light models that are not dependent on the view direction. 在不依赖于观察方向的光照模型的正向渲染路径中使用它。
  2. half4 Lighting (SurfaceOutput s, half3 viewDir, UnityGI gi); Use this in forward rendering paths for light models that are dependent on the view direction. 在基于观察方向的光照模型的正向渲染路径中使用它。
  3. half4 Lighting_Deferred (SurfaceOutput s, UnityGI gi, out half4 outDiffuseOcclusion, out half4 outSpecSmoothness, out half4 outNormal); Use this in deferred lighting paths. 在延迟光照路径中使用。
  4. half4 Lighting_PrePass (SurfaceOutput s, half4 light); Use this in light prepass (legacy deferred) lighting paths. 在光照预通道(传统延迟)光照路径中使用。

Note that you don’t need to declare all functions. A lighting model either uses view direction or it does not. Similarly, if the lighting model only works in forward rendering, do not declare the _Deferred or _Prepass function. This ensures that Shaders that use it only compile to for

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值