背景:开关窗帘过程,让环境在亮和暗之间过度

事先烘培出亮、暗两张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 过度光照贴图的更多相关文章

  1. 【Unity】第13章 光照贴图和光影效果

    分类:Unity.C#.VS2015 创建日期:2016-05-19 一.简介 在Unity 5中,Lighting是—种增强场景光照和阴影效果的技术,它可以通过较少的性能消耗使静态场景看上去更真实. ...

  2. unity中使用自定义shader进行光照贴图烘培无法出现透明度的坑爹问题

    最近开发中在对场景进行光照贴图烘焙时发现一个坑爹问题,在使用自定义shader的时候,shader命名中必须包含Transparent路径,否则烘焙的时候不对alpha通道进行计算,烘焙出来都是狗皮膏 ...

  3. Unity Shader-法线贴图(Normal)及其原理

    简介 以前经常听说“模型不好看啊,怎么办啊?”答曰“加法线”,”做了个高模,准备烘一下法线贴图”,“有的美术特别屌,直接画法线贴图”.....法线贴图到底是个什么鬼,当年天真的我真的被这个图形学的奇淫 ...

  4. unity3d-地图制作之光照贴图Lightmapping

    今天无聊随便翻看了暗黑战神的场景资源,发现了一个以前没怎么注意的静态场景优化问题. 什么是静态场景,也就是说这个场景是不会变化.比如MMO游戏中选择人物的场景. 就拿默认的暗黑战神的选择人物场景来看, ...

  5. OpenGL光照2:材质和光照贴图

    本文是个人学习记录,学习建议看教程 https://learnopengl-cn.github.io/ 非常感谢原作者JoeyDeVries和多为中文翻译者提供的优质教程 的内容为插入注释,可以先跳过 ...

  6. unity知识点思维导图

    写了个思维导图,总结了下学习unity的知识点感觉还有其他很多的没写到,等我慢慢在工作中完善它,这是下面的链接,后续会根据他的每一个细节来丰富我的博客. 详细地址: http://naotu.baid ...

  7. Unity优化之贴图

    默认情况下当你把图片导入到unity中时,unity会自动把图片转换成最适合当前平台的压缩格式.如果你有一些特殊的需求,unity也提供了覆盖默认压缩格式的方法,如下图 在图片的Inspector窗口 ...

  8. OpenGL光照贴图

    一:啥叫贴图 上一节中,我们将整个物体的材质定义为一个整体,但现实世界中的物体通常并不只包含有一种材质,而是由多种材质所组成. 拓展之前的系统,引入漫反射和镜面光贴图(Map).这允许我们对物体的漫反 ...

  9. Unity ShaderLab 光照随笔

    unity camera默认3种渲染路径,unity5.50里面有4种 camera Rendering Path 1 vertexLit(逐顶点,一般在vert中处理)  2 forward (前向 ...

随机推荐

  1. GitHub和码云的简单使用

    年轻,又经历了初高大学的英语的纠缠,导致连最简单的语句都看不懂,我在慢慢寻找语言的快乐 GitHub 的简单使用 : https://www.cnblogs.com/zhcncn/p/3731707. ...

  2. 服务器上搭建flowvisor平台

    之前全是在virtualbox上的Ubuntu虚拟机上测试的ovs以及pox, 现在我们开始在服务器上开始了 两台服务器上的ovs均是1.4.6版本 遇到一个问题:之前装的ovs down了 然后什么 ...

  3. VS连接SQL Server 2008,并实现登录和注册功能

    --------------------- 作者:Cambridge 来源:CSDN 原文:https://blog.csdn.net/cambridgeacm/article/details/797 ...

  4. DNA Pairing-freecodecamp算法题目

    DNA Pairing 1.要求 DNA 链缺少配对的碱基.依据每一个碱基,为其找到配对的碱基,然后将结果作为第二个数组返回. Base pairs(碱基对)是一对 AT 和 CG,为给定的字母匹配缺 ...

  5. OI杂记

    从今天开始记录一下为数不多天的OI历程 8.25 上 今天举行了难得的五校联考,模拟noip,题目的解压密码竟然是$aKnoIp2o18$,对你没有看错!!! 7:50老师?啊啊啊啊,收不到题目啊,还 ...

  6. Docker 镜像&仓库 获取及推送镜像

    docker查看.删除镜像 docker镜像存储位置: /var/lib/docker 查看docker信息也可以查看保存位置 docker info 1.列出镜像 docker images -aa ...

  7. mac Parallels Desttop 13 win7/win8 无法连接网络

    把 “源” 从共享网络改为"Wi-Fi" 在mac 这边点击菜单栏windows图标,选配置(如果没有配置,点控制中心,在点控制中心的齿轮,)选 硬件 找到网络 解锁,上边第一行就 ...

  8. 面试:如何把xxx.sh使用/etc/init.d/xxx.sh start启动,并且可以用chkconfig配置开机自启动

    chkconfig原理: 1.脚本放到/etc/init.d下面,并且可执行(/etc/init.d/sshd) 需要被chkconfig管理,需要添加进去chkconfig  --add  sshd ...

  9. PHP函数详解:call_user_func()使用方法

    call_user_func函数类似于一种特别的调用函数的方法,使用方法如下: <?php function nowamagic($a,$b) { echo $a; echo $b; } cal ...

  10. redis+PHP消息队列实现及应用

    学习视频: http://www.imooc.com/learn/852 学习笔记: https://blog.csdn.net/qq_33862644/article/details/7938564 ...