查看: 941|回复: 0
打印 上一主题 下一主题

编写表面着色器:表面着色器中的自定义光照模式

[复制链接]
.    

3797

主题

11

听众

5万

积分

首席设计师

Rank: 8Rank: 8

纳金币
32328
精华
41

活跃会员 优秀版主 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2013-2-24 09:58:41 |只看该作者 |倒序浏览
When writing Surface Shaders, you're describing properties of a surface (albedo color, normal, ...) and the lighting interaction is computed by a Lighting Model. Built-in lighting models are Lambert (diffuse lighting) and BlinnPhong (specular lighting).
当你在编写表面着色器的时候,你是描述一个表面的属性(反射率颜色,法线,…)和通过计算光照模式来计算灯光的相互作用。内置的光照模式是 Lambert (漫反射光diffuse lighting) 和 BlinnPhong (镜面反射光(高光)specular lighting)。
Sometimes you might want to use a custom lighting model, and it is possible to do that in Surface Shaders. Lighting model is nothing more than a couple of Cg/HLSL functions that match some conventions. The built-in Lambert and BlinnPhong models are defined in Lighting.cginc file inside Unity ({unity install path}/Data/CGIncludes/Lighting.cginc on Windows, /Applications/Unity/Unity.app/Contents/CGIncludes/Lighting.cginc on Mac).
有时你也许会想使用自定义光照模式( custom lighting model)。这在表面着色器(surface shader)中是可以做到的。光照模式(lighting model)无外乎是几个Cg/HLSL函数的组合。内置的 Lambert 和 BlinnPhong定义在 Lighting.cginc文件中。(这个文件的位置在 windows系统下:{unity安装路径}/Data /CGIncludes /Lighting.cginc,Mac系统下: /Applications/Unity/Unity.app/Contents/CGIncludes/Lighting.cginc)



[Lighting Model declaration 光照模式声明]
Lighting model is a couple of regular functions with names starting with Lighting. They can be declared anywhere in your shader file or one of included files. The functions are:
光照模式是一个以Lighting开头与名字组合在一起的合乎规范的函数。你可以在你的着色器文件(shader file)或导入文件(included files)中的任何一个地方声明它。这个函数是:
    half4 LightingName (SurfaceOutput s, half3 lightDir, half atten); This is used in forward rendering path for light models that are not view direction dependent (e.g. diffuse).

    half4 LightingName (SurfaceOutput s, half3 lightDir, half atten);这是在正向渲染路径(forward rendering path)中使用的光照模式。它不是取决于视图方向的(view direction)。例如:漫反射(diffuse)。

    half4 LightingName (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten); This is used in forward rendering path for light models that are view direction dependent.

    half4 LightingName (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten);这是在正向渲染路径(forward rendering path)中使用的光照模式。它取决于视图的方向(view direction)。

    half4 LightingName_PrePass (SurfaceOutput s, half4 light); This is used in deferred lighting path.

    half4 LightingName_PrePass (SurfaceOutput s, half4 light); 这是在延时光照路径(deferred lighting path)中使用的。
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 will not work in deferred lighting, you just do not declare _PrePass function, and all shaders that use it will compile to forward rendering only.
请注意:你不要声明所有的函数。一个光照模式(lighting model)要么使用视图方向(view direction)要么不使用。同样的,如果光照模式(lighting model)在延时光照(deferred lighting)中不工作,你只要不声明成 _PrePass(第三个)函数就好了。那么所有的着色器在使用它的时候只会在正向渲染(forward rendering)中编译。
Decoding directional lightmaps needs to be customized in some circumstances in a similar fashion as the lighting function for forward and deferred lighting. Use one of the functions below depending on whether your light model is view direction dependent or not. Both functions handle forward and deferred lighting rendering paths automatically.
当定向解码光照贴图用于向前/延迟光照中的光照函数,或类似的函数中时,需要进行定制。使用下面函数中的一个取决于你的光照模式(light model)是否依赖视图方向(view direction)。这两个函数将自动处理正向和延时光照路径(forward and deferred lighting rendering paths)。
    half4 LightingName_DirLightmap (SurfaceOutput s, fixed4 color, fixed4 scale, bool surfFuncWritesNormal); This is used for light models that are not view direction dependent (e.g. diffuse).

    half4 LightingName_DirLightmap (SurfaceOutput s, fixed4 color, fixed4 scale, bool surfFuncWritesNormal);这是使用的不依赖于视图方向(view direction)的光照模式(light model)。例如:漫反射(diffuse)。

    half4 LightingName_DirLightmap (SurfaceOutput s, fixed4 color, fixed4 scale, half3 viewDir, bool surfFuncWritesNormal, out half3 specColor); This is used for light models that are view direction dependent.

    half4 LightingName_DirLightmap (SurfaceOutput s, fixed4 color, fixed4 scale, half3 viewDir, bool surfFuncWritesNormal, out half3 specColor);这是使用的依赖于视图方向(view direction)的光照模式(light model)。
[Examples]
Surface Shader Lighting Examples 表面着色器光照示例
【来源:互联网】

更多精彩教程,尽在web3D纳金网http://www.narkii.com/college/
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-5-9 09:00 , Processed in 0.085521 second(s), 33 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部