1.一开始认为是光照配置的问题:
terrain取消static,light为realtime,勾选realtime lighting,由于没有静态物体,所以理论上来说没有烘焙的数据。
terrain static,light为realtime,勾选realtime lighting,会烘焙一些间接光照数据,比如环境光反射,AO等,理论上的结果是草会在运行时候被光照点亮+烘焙的间接光数据混合,realtime部分有数据。
terrain static,light为realtime,勾选realtime lighting,勾选上mix lighting,即加上mix light和bake light烘焙数据,由于场景中只有一盏realtime lighting,烘焙的数据理论上与不勾选mix lighting一致,realtime 部分有数据, baked部分没有数据,打包成assetbundle,结果草变亮。
terrain static,light为realtime,,勾选上mix lighting,由于场景中没有mix light或者baked light,所以理论上没有烘焙数据,实际是baked light map,baked directionality, baked albed baked emissive有数据,baked shadowmask没数据,草变亮
terrain static,light为realtime,不勾选realtime lighting和mix lighting,所以理论上没有烘焙数据,草亮
之后验证(terrain取消static,light为realtime,勾选realtime lighting),发现草还是亮了,?,确定不是版本问题(2017.2,2017.3)
2.看下assetbundle有没有打包lightmap?
editor取消simulate模式,打开miniweb assetbundle服务器,在unity editor模式下加载场景,发现草是亮的,但是导出develop client开发版草是暗的。用frame debuger发现,DynamicLightmap_on
认为是shader没有打包
官方文档
Shader Stripping
通过去除与光照和雾确定的shader来减少生成数据,加快加载时间。
Shader设置 | |
---|---|
Automatic (Default value) | unity查看当前的场景和lightmap设置确定哪一些雾和光照模型没有被使用,打包时去除相关的shader |
Manual | 自定义模式。如果要在运行时候改变雾的模式,你需要自己确保要用的模式被包含。 |
Instancing variants | 使用GPU instancing来渲染一个mesh的多个拷贝,常使用于建筑物,树,和草,这些mesh在场景中重复出现。这个选项只在material shader支持GPU Instancing出现。 |
Strip Unused(Default value) | unity只保存至少有一个material的shader打开 “Enable instancing” (在编辑器debug模式下可以看到)的 instancing shader variants。对于没有打开“Enable instancing”的材质的shader会去除instancing shader variants。 When a project is built, Unity only includes instancing shader variants if at least one material referencing the shader has the “Enable instancing” checkbox ticked. Unity strips any shaders that are not referenced by materials with the “Enable instancing” checkbox ticked. |
Strip All | 去除所有instancing shader variants,包括被使用的 |
Keep All | 保存所有instancing shader variants,包括没有被使用的 |
把模式勾选上编译assetbundle,发现草渲染正常。
间接光可以提前计算,生成软阴影,这个预的过程是烘焙。减少运行时计算间接光。
提前计算只针对静态物体。( Unity 5.0 adds support for a new technique called Precomputed Realtime GI. It still requires a precomputation phase similar to the bake mentioned above, and it is still limited to static objects)
对于RealtimeGI,这些提前计算的光照数据并不是最终的结果,unity会根据光照的变化每一帧迭代修改,如果光照变化大,它不会立马变成最终结果( 有收敛过程)。
无论是RealtimeGI还是BakedGI,烘焙的只是静态物体(Both Baked GI and Precomputed Realtime GI have the limitation that only static objects can be included in the bake/precomputation)。
也就是说移动物体是没有bounce light(间接光),(bounce light, 比如有一个全局光照射到一张红色的沙发上反射到白色的墙,墙面会有微红)。一种对于移动物体产生间接光的一个解决方案是使用light probes(light probes可以分布在场景中,可以在烘焙阶段预先计算,每一个probe记录了需要用到的光照信息(indirct light),一个物体中心可以包含在由4个probe组成的四面体中,light probes是低精度的效果)。因为数据是提前算好的(通过静态物体),所以一个移动的红色球靠近一面静止的白色墙壁不会有变化,但是一个移动的白色球当靠近一面静止的红色墙时会红色。
如果把光照设置为Baked,那么直接光(direct light)和间接光(indirect light)会被烘焙到lightmap,并且不会在运行时改变。
如果把光照设置为Realtime,直接光是运行时计算,烘焙会产生间接光数据。
混合光(mixed,之前版本是Stationary),也能生成Realtime的效果。也能受到实时光照的影响。
GI烘焙的时候也会考虑LOD,直接光会计算所有的LOD,对于Lower Lod的间接光采用light probes。
属性 | 功能 |
---|---|
Skybox Material | 天空盒(shader为skybox/procedural ) |
Sun Source | 当天空为procedural skybox,指定一个平行光来表示太阳的方向,如果没有设置那么场景中的最亮的平行光作为该值 |
Source | 环境光漫反射来源,默认skybox |
Intensity Multiplier | 环境光漫反射强度,默认1,范围[0,8] |
Ambient Mode | Realtime,运行时计算环境光 Baked,使用烘焙数据 |
Environment Reflections | |
Source | 环境光反光,可以选择skybox或者cubemap |
compression | 是否压缩纹理 |
Intensity Multiplier | 反光系数 |
Bounces | 反射次数 |
Baked Global Illumination | 如果打开,unity烘焙光照数据,运行时使用预先计算好的数据 |
Lighting Mode | 对于混合光照,有三种模式 Baked Indirect(只烘焙间接光,不计算阴影,模式表现的效果是实时光照+附加的间接光,超出Shadow Distance没有阴影,可以配合雾效,对超过这个距离的物体加雾。 适合用于室内射击游戏或者冒险游戏(通过走廊链接),有雾的室外场景同样合适(超过Shadow Distance的物体会被雾隐藏)) Shadowmask(每texel(纹素)最多受4光源阴影,表现和实时光照一致,Shadowmask模式下烘焙的lightmap和Baked Indirect一样,是间接光) Subtractive(唯一一个把Mixed Lighiting的阴影烘焙进Lightmap的模式,但是对于静态物体没有specular和glossy,动态物体接受实时光照和glossy 反射,但是只接收静态物体的阴影) |
Realtime Shadow Color |
Lightmapper | 可以设置为Enlighten 或者Progressive ,默认Enlighten |
Indirect Resolution | 间接光每单元texel大小 |
Lightmap Resolution | 每位texel大小,lightmap |
Lightmap Padding | 不同物体在同一张lightmap间隔多少个纹素 |
Lightmap Size | lightmap大小 |
Compress Lightmaps | |
Ambient Occlusion 环境光遮蔽 |
只计算间接光 |
Directional Model | Non-directional: one texture, one texture sample, a few extra shader instructions.完全的diffuse Directional: two textures, two texture samples, a few more extra shader instructions.包含一张lightmap和一张光的方向信息和一个比例系数的map |
Indirect Intensity | 控制间接光的亮度强度 |
Albedo Boost | 加强albedo材质的光反弹次数 |
Lightmap Parameters | Lightmap Parameters |
对于静态和动态物体阴影都是通过shadow map生成(实时计算),产生阴影距离相机的最大距离为 Shadow Distance,超过这个距离,不生成阴影。
如果RealtimeGI关闭,实时光只计算动态和静态物体的直接光。如果开启,unity使用enlighten提前计算静态物体的surface-to-surface light paths。
If Realtime GI is not enabled, real-time Lights only calculate direct lighting on dynamic and static GameObjects. If Realtime GI is enabled, Unity uses Enlighten to precompute the surface-to-surface light paths for static GameObjects.
Only indirect lighting is precomputed
混合光照能产生和实时光照的类似效果,但是混合光照的参数修改(颜色和强度)会有一定的限制。在运行过程中一般是实时计算的结果和烘焙的数据相互结合计算。
只烘焙间接光(就是物体之间互相反射的那些光,也包含AO(环境光遮蔽,用来模拟全局光照产生的阴影效果(软阴影 ))),不计算阴影,在Shadow Distance(Project Settings>Quality>Shadows里面设置)之内的阴影都是实时计算的(Shadow Map),所谓Shadow Map就是以灯光视角depth test计算一下渲染到的像素能不能被看到
该模式表现的效果是实时光照+附加的间接光,超出Shadow Distance没有阴影,可以配合雾效,对超过这个距离的物体加雾。 适合用于室内射击游戏或者冒险游戏(通过走廊链接),有雾的室外场景同样合适(超过Shadow Distance的物体会被雾隐藏)
Only indirect lighting is precomputed
对于阴影的处理
Dynamic receiver A dynamic GameObject that is receiving a shadow from another static or dynamic GameObject |
Static receiver A static GameObject that is receiving a shadow from another static or dynamic GameObject |
|||
---|---|---|---|---|
Within Shadow Distance | Beyond Shadow Distance | Within Shadow Distance | Beyond Shadow Distance | |
Dynamic caster A dynamic GameObject that is casting a shadow |
Shadow map | - | Shadow map | |
Static caster A static GameObject that is casting a shadow |
Shadow map | - | Shadow map |
即阴影都是通过实时计算得到的。
优点:
缺点
shadowmask有二种,shadowmask和distanceshadowmask( Quality Settings (menu: Edit > Project Settings > Quality)),其区别主要是
Indirect lighting and direct occlusion are precomputed
shadowmask最多有4张(纹理受GPU4个通道限制),uv,分辨率与lightmap对应一致。适合用于PC。
阴影
Dynamic receiver A dynamic GameObject that is receiving a shadow from another static or dynamic GameObject |
Static receiver A static GameObject that is receiving a shadow from another static or dynamic GameObject |
|||
---|---|---|---|---|
Within Shadow Distance | Beyond Shadow Distance | Within Shadow Distance | Beyond Shadow Distance | |
Dynamic caster A dynamic GameObject that is casting a shadow |
Shadow map | - | Shadow map | - |
Static caster A static GameObject that is casting a shadow |
Shadow map | Light Probes | Shadow map (对于shadowmaskmodel这边是shadowmask) |
Shadow mask |
优点:
缺点:
唯一一个把直接光(direct map)烘焙到lightmap.在运行时候不再计算direct light。
特别地方:
阴影
Dynamic receiver A dynamic GameObject that is receiving a shadow from another static or dynamic GameObject |
Static receiver A static GameObject that is receiving a shadow from another static or dynamic GameObject |
|||
---|---|---|---|---|
Within Shadow Distance | Beyond Shadow Distance | Within Shadow Distance | Beyond Shadow Distance | |
Dynamic caster A dynamic GameObject that is casting a shadow |
Shadow map | - | Main light shadow map | - |
Static caster A static GameObject that is casting a shadow |
Light Probes | Light Probes | Lightmap | Lightmap |
优点
缺点
Bakedlight 用于局部布局光照或者提高一个暗区域的光照,所有的BakedLight不参与实时运算,即所有数据都是烘焙得到。
烘焙会把直接光和间接光烘焙的lightmap和light probes(用于动态物体),烘焙的光不能发射镜面反射光。
All light paths are precomputed
Bakedlight是唯一一个,动态物体不能投射阴影在动态物体上。它不参与运行时光照计算。
优点
缺点
Baked光并不会照亮动态物体,唯一的方式是使用light probes。这也是与subtract模式的唯一却别,subtract通过唯一的main directional light。
https://docs.unity3d.com/2017.4/Documentation/Manual/GIIntro.html
http://ma-yidong.com/2017/09/02/mixed-lighting-lightmap-shader-in-unity/