Unity 过度光照贴图
背景:开关窗帘过程,让环境在亮和暗之间过度
事先烘培出亮、暗两张Lighting map。然后代码实现,窗帘开关由动作实现,而代码中通过动作执行进度来过度两张Lighting map
void OnAnimatorMove()
{
AnimatorTransitionInfo transitionInfo = animator.GetAnimatorTransitionInfo();
if (transitionInfo.normalizedTime != )//状态切换中
{
}
else
{
AnimatorStateInfo currentAnimatorStateInfo = animator.GetCurrentAnimatorStateInfo(); // 开窗
if (currentAnimatorStateInfo.IsName("opening"))
{
LightmapBlender.Instance.OpenWindow(currentAnimatorStateInfo.normalizedTime);
} // 关窗
if (currentAnimatorStateInfo.IsName("closing"))
{
LightmapBlender.Instance.CloseWindow(currentAnimatorStateInfo.normalizedTime);
}
}
动作控制代码
public Texture2D normalTexture2D;
public Texture2D closeWindowTexture2D;
public Texture2D dancingTexture2D; public Texture2D blendTexture2D; private Color[] normalColors;
private Color[] closeWindowColors;
private Color[] dancingColors; private Color[] blendColors; [SerializeField]
private Transform brightTransform, darkTransform; [SerializeField]
private Color brightAmbientLight, darkAmbientLight; void Awake ()
{
normalColors = normalTexture2D.GetPixels();
closeWindowColors = closeWindowTexture2D.GetPixels(); if (dancingTexture2D != null)
dancingColors = dancingTexture2D.GetPixels(); blendColors = blendTexture2D.GetPixels();
} public void OpenWindow(float t)
{
brightTransform.gameObject.SetActive(true);
darkTransform.gameObject.SetActive(false); Blend2Textures(closeWindowColors, normalColors, t);
RenderSettings.ambientLight = Blend2Color(darkAmbientLight, brightAmbientLight, t);
} public void CloseWindow(float t)
{
brightTransform.gameObject.SetActive(false);
darkTransform.gameObject.SetActive(true); Blend2Textures(normalColors, closeWindowColors, t); // 过度环境光(影响没烘培在Lighting map 中的对象的明暗)
RenderSettings.ambientLight = Blend2Color(brightAmbientLight, darkAmbientLight, t);
} private Color Blend2Color(Color from, Color to, float t)
{
Color blend; blend.r = from.r * ( - t) + to.r * t;
blend.g = from.g * ( - t) + to.g * t;
blend.b = from.b * ( - t) + to.b * t;
blend.a = from.a * ( - t) + to.a * t; return blend;
} private void Blend2Textures(Color[] from, Color[] to, float t)
{
for (int i = ; i < blendColors.Length; i++)
blendColors[i] = Blend2Color(from[i], to[i], t); blendTexture2D.SetPixels(blendColors);
blendTexture2D.Apply(); SwitchLightmaps(blendTexture2D);
} private void SwitchLightmaps(Texture2D tex)
{
LightmapData[] lightmaps = LightmapSettings.lightmaps; lightmaps[].lightmapFar = tex; // 切换 Lighting map
LightmapSettings.lightmaps = lightmaps;
}
插值过度Lighting map
Unity 过度光照贴图的更多相关文章
- 【Unity】第13章 光照贴图和光影效果
分类:Unity.C#.VS2015 创建日期:2016-05-19 一.简介 在Unity 5中,Lighting是—种增强场景光照和阴影效果的技术,它可以通过较少的性能消耗使静态场景看上去更真实. ...
- unity中使用自定义shader进行光照贴图烘培无法出现透明度的坑爹问题
最近开发中在对场景进行光照贴图烘焙时发现一个坑爹问题,在使用自定义shader的时候,shader命名中必须包含Transparent路径,否则烘焙的时候不对alpha通道进行计算,烘焙出来都是狗皮膏 ...
- Unity Shader-法线贴图(Normal)及其原理
简介 以前经常听说“模型不好看啊,怎么办啊?”答曰“加法线”,”做了个高模,准备烘一下法线贴图”,“有的美术特别屌,直接画法线贴图”.....法线贴图到底是个什么鬼,当年天真的我真的被这个图形学的奇淫 ...
- unity3d-地图制作之光照贴图Lightmapping
今天无聊随便翻看了暗黑战神的场景资源,发现了一个以前没怎么注意的静态场景优化问题. 什么是静态场景,也就是说这个场景是不会变化.比如MMO游戏中选择人物的场景. 就拿默认的暗黑战神的选择人物场景来看, ...
- OpenGL光照2:材质和光照贴图
本文是个人学习记录,学习建议看教程 https://learnopengl-cn.github.io/ 非常感谢原作者JoeyDeVries和多为中文翻译者提供的优质教程 的内容为插入注释,可以先跳过 ...
- unity知识点思维导图
写了个思维导图,总结了下学习unity的知识点感觉还有其他很多的没写到,等我慢慢在工作中完善它,这是下面的链接,后续会根据他的每一个细节来丰富我的博客. 详细地址: http://naotu.baid ...
- Unity优化之贴图
默认情况下当你把图片导入到unity中时,unity会自动把图片转换成最适合当前平台的压缩格式.如果你有一些特殊的需求,unity也提供了覆盖默认压缩格式的方法,如下图 在图片的Inspector窗口 ...
- OpenGL光照贴图
一:啥叫贴图 上一节中,我们将整个物体的材质定义为一个整体,但现实世界中的物体通常并不只包含有一种材质,而是由多种材质所组成. 拓展之前的系统,引入漫反射和镜面光贴图(Map).这允许我们对物体的漫反 ...
- Unity ShaderLab 光照随笔
unity camera默认3种渲染路径,unity5.50里面有4种 camera Rendering Path 1 vertexLit(逐顶点,一般在vert中处理) 2 forward (前向 ...
随机推荐
- 已知一棵完全二叉树,求其节点的个数 要求:时间复杂度低于O(N),N为这棵树的节点个数
package my_basic.class_4; public class Code_08_CBTNode { // 完全二叉树的节点个数 复杂度低于O(N) public static class ...
- C++ 学习笔记(三)string 类
在C语言中如果想要使用字符串那么有两种方法: 1.定义char型数组:char[10]; 然后将每个字符填充到对应的位置. 优点:这种方式将字符串放在内存所以每个位置都可以修改. 缺点:赋值比较麻烦, ...
- pandas关联mysql并读写数据库
1.代码读写mysql,必须安装关联mysql的工具 操作如下命令: sudo apt-get install mysql-server mysql-clientsudo apt-get instal ...
- Docker自学纪实(一)Docker介绍
先简单了解一下,做个记录,以便不时之需. Docker简介:Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从Apache2.0协议开源. Docker 可以让开发者打包他们的应用以及依 ...
- CentOS7安装配置VSFTP
#是否开启匿名用户,匿名都不安全,不要开 anonymous_enable=NO #允许本机账号登录FTP local_enable=YES #允许账号都有写操作 write_enable=YES # ...
- 多线程辅助类之CyclicBarrier(四)
CyclicBarrier是一个线程辅助类,和<多线程辅助类之CountDownLatch(三)>功能类似,都可以实现一组线程的相互等待.要说不通点,那就是CyclicBarrier在释放 ...
- Java 编辑html模板并生成pdf
1.工具类 import com.hujiang.project.zhgd.Util; import com.itextpdf.text.BaseColor; import com.itextpdf. ...
- python之自定义排序函数sorted()
sorted()也是一个高阶函数,它可以接收一个比较函数来实现自定义排序,比较函数的定义是,传入两个待比较的元素 x, y,如果 x 应该排在 y 的前面,返回 -1,如果 x 应该排在 y 的后面, ...
- LeetCode(290) Word Pattern
题目 Given a pattern and a string str, find if str follows the same pattern. Here follow means a full ...
- POJ:3020-Antenna Placement(二分图的最小路径覆盖)
原题传送:http://poj.org/problem?id=3020 Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Descri ...