Unity 的“Vertex Lit Rendering path“中 shader Pass 的注意事项
"MADFINGER/Environment/Unlit (Supports Lightmap)"是 ShadowGun 示例中最简单的 shader 了,如下:
// Unlit shader. Simplest possible textured shader.
// - SUPPORTS lightmap
// - no lighting
// - no per-material color Shader "MADFINGER/Environment/Unlit (Supports Lightmap)" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_Color ("HACK: temporary to fix lightmap bouncing light (will be fixed in RC1)", Color) = (,,,)
} SubShader {
Tags { "RenderType"="Opaque" }
LOD // Non-lightmapped
Pass {
Tags { "LightMode" = "Vertex" }
Lighting Off
SetTexture [_MainTex] { combine texture }
} // Lightmapped, encoded as dLDR
Pass {
Tags { "LightMode" = "VertexLM" } Lighting Off
BindChannels {
Bind "Vertex", vertex
Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
Bind "texcoord", texcoord1 // main uses 1st uv
} SetTexture [unity_Lightmap] {
matrix [unity_LightmapMatrix]
combine texture
}
SetTexture [_MainTex] {
combine texture * previous DOUBLE, texture * primary
}
} // Lightmapped, encoded as RGBM
Pass {
Tags { "LightMode" = "VertexLMRGBM" } Lighting Off
BindChannels {
Bind "Vertex", vertex
Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
Bind "texcoord", texcoord1 // main uses 1st uv
} SetTexture [unity_Lightmap] {
matrix [unity_LightmapMatrix]
combine texture * texture alpha DOUBLE
}
SetTexture [_MainTex] {
combine texture * previous QUAD, texture * primary
}
}
}
}
在 Unity 中每一个 Pass 都会使得对象渲染一次,一般来讲 VertexLit 的 shader 只有一个 Pass,里面都是些简单状态设置和纹理混合,相当于 dx 的 .fx 文件。那么以上的 shader 中出现了3个不同的 Pass,是渲染3遍吗?
答案是否,请看官方的另一个说明:Unity's Rendering Pipeline, 文章最后一段写到(重点看红色粗体部分):
Vertex Lit Rendering path
Since vertex lighting is most often used on platforms that do not support programmable shaders, Unity can't create multiple shader permutations internally to handle lightmapped vs. non-lightmapped cases. So to handle lightmapped and non-lightmapped objects, multiple passes have to be written explicitly.
Vertex
pass is used for non-lightmapped objects. All lights are rendered at once, using a fixed function OpenGL/Direct3D lighting model (Blinn-Phong)VertexLMRGBM
pass is used for lightmapped objects, when lightmaps are RGBM encoded (this happens on most desktops and consoles). No realtime lighting is applied; pass is expected to combine textures with a lightmap.VertexLMM
pass is used for lightmapped objects, when lightmaps are double-LDR encoded (this happens on mobiles and old desktops). No realtime lighting is applied; pass is expected to combine textures with a lightmap.
Unity 在使用 Vertex lit 模式时无法在内部自动分别处理使用了光照图的对象和未使用的,所以需要作者自己显式的针对 Vertex, VertexLMRGBM, VertexLMM 这三个 LightMode 的 PassTag 分别写一个 Pass,以便适应没有光照图,以及使用了光照图但编码不同的情况。
在 UnityCG.cginc 中的 DecodeLightmap 里包含了上述的两种光照图解码:
// Decodes lightmaps:
// - doubleLDR encoded on GLES
// - RGBM encoded with range [0;8] on other platforms using surface shaders
inline fixed3 DecodeLightmap( fixed4 color )
{
#if defined(SHADER_API_GLES) && defined(SHADER_API_MOBILE)
return 2.0 * color.rgb;
#else
// potentially faster to do the scalar multiplication
// in parenthesis for scalar GPUs
return (8.0 * color.a) * color.rgb;
#endif
}
参照这个代码就能知道第一个 shader 中后两个 Pass 的算法和这个函数是对应的。
Unity 的“Vertex Lit Rendering path“中 shader Pass 的注意事项的更多相关文章
- Unity Lighting - Choosing a Rendering Path 选择渲染路径(三)
Choosing a Rendering Path 选择渲染路径 Unity supports a number of rendering techniques, or ‘paths’. An i ...
- shader 3 rendering path
渲染通道, rendering path. vertexlit, forward 和 Deferred lighting 旧有的非统一架构下: 分为顶点着色引擎和像素渲染通道 渲染通道是GPU负责给图 ...
- Thinking in Unity3D:渲染管线中的Rendering Path
关于<Thinking in Unity3D> 笔者在研究和使用Unity3D的过程中,获得了一些Unity3D方面的信息,同时也感叹Unity3D设计之精妙.不得不说,笔者最近几年的 ...
- Unity加载模块深度解析(Shader)
作者:张鑫链接:https://zhuanlan.zhihu.com/p/21949663来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 接上一篇 加载模块深度解析(二 ...
- Unity shader学习之Forward Rendering Path
Forward rendering path shader如下: // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObje ...
- 【原】实时渲染中常用的几种Rendering Path
[原]实时渲染中常用的几种Rendering Path 本文转载请注明出处 —— polobymulberry-博客园 本文为我的图形学大作业的论文部分,介绍了一些Rendering Path,比较简 ...
- 渲染路径-实时渲染中常用的几种Rendering Path
http://www.cnblogs.com/polobymulberry/p/5126892.html?utm_source=tuicool&utm_medium=referral 回到顶部 ...
- Unity Shaders Vertex & Fragment Shader入门
http://blog.csdn.net/candycat1992/article/details/40212735 三个月以前,在一篇讲卡通风格的Shader的最后,我们说到在Surface Sha ...
- Unity 3d中Shader是什么,可以吃吗?
众所周知,Unity3d是一款跨平台非常广的游戏引擎,上手容易,界面友好,集成功能众多,是目前开发手游的主流引擎.本人有幸使用Unity 3d进行开发已一年多时间,已领略了这歀引擎的强大之处. 编写s ...
随机推荐
- Scoket简介
我们很多人都听说过Socket编程也称网络编程,在我们当今的社会中网络已经深入到我们的生活中了,计算机的网络通信也成为我们生活中必不可少的一部分.而实现我们网络通信就得依靠网络编程,让我们的计算机之间 ...
- AUTOTRACE Statistics常用列解释
AUTOTRACE Statistics常用列解释 序号 列名 解释 1 db block gets 从buffer cache中读取的block的数量 2 consistent gets 从buff ...
- maven 创建的符号连接命令
E:\Joyplus\src\main\webapp\WEB-INF>mklink /d lib ..\..\..\.\..\target\ediHelperSuite-0.5\WEB-INF\ ...
- mac下安装配置nginx环境
本文介绍 nginx 在mac上的安装. 我是通过brewhome 来安装的. brew install nginx 一路顺畅. 下面是安装信息. 复制代码 代码如下: hematoMacBook-P ...
- win7下装ubuntu
需要的东西有: 1,ubuntu系统镜像,下载地址:http://www.ubuntu.com/download/desktop 选64位吧,兼容性好些. 2,空闲的大于20G硬盘空间,这个大小根据个 ...
- jquery之分页插件smartpaginator
今天推荐一个分页工具条插件:Smart Paginator,这个插件用途还是很广的,而且可定制性相当不错,目前内置三种颜色,有需要的话,可以自己改css定制颜色 1.如何使用Smart Paginat ...
- kaptcha小案例(转)
使用kaptcha生成验证码 kaptcha是一个简单好用的验证码生成工具,通过配置,可以自己定义验证码大小.颜色.显示的字符等等.下面就来讲一下如何使用kaptcha生成验证码以及在服务器端取出验证 ...
- 利用toString做类型的判断
//利用toString做类型的判断 : /*var arr = []; alert( Object.prototype.toString.call(arr) == '[object Array]' ...
- ajax只是一个称呼
记得刚入行的时候,看到ajax,即异步的javascript和xml这样一个概念,一点感觉都没有.参加工作前的第一轮面试,被问到有没有自己实现过ajax,我觉得自己实现肯定很复杂吧. 从名字理解 从名 ...
- phpcms安装完成后总是跳转到install/install.php
很多人在本地安装phpcms后总是跳转到install/install.php.由于很多人是第一次使用phpcms,不知道为何会出现这个错误.出现这个大都是phpcms的缓存所致. 如何解决ph ...