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

事先烘培出亮、暗两张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. web.xml 中 resource-ref 的注意事项

    配置说明: web.xml 中配置 <resource-ref> <description>Employees Database for HR Applications< ...

  2. java中插入myslq的datetime类型的

    java.util.Date d = new java.util.Date(); Timestamp tt=new Timestamp(d.getTime()); ps.setTimestamp(4, ...

  3. 关键字final

    final数据 对于一个final变量,如果是基本数据类型的变量,则其数值一旦在初始化之后便不能更改:如果是引用类型的变量,则在对其初始化之后便不能再让其指向另一个对象.再次赋值将引起编译报错. 当f ...

  4. Windows 10+Ubuntu双系统修复Ubuntu启动引导

    U盘启动,联网 $ sudo su sudo add-apt add-apt-repository ppa:yannubuntu/boot-repair apt-get update apt-get ...

  5. Python入门:Python基础笔记

    (C语言:)C语言是相对C++.C#.Java等语言更接近底层,并且一些硬件编程都可以使(只能使用)C语言.另外C语言学起来相对困难,因为涉及到指针,指针也是语言接近底层语言的一个特征.目前编写较大的 ...

  6. 【jenkins】jenkins执行nohup java报错

    nohup:failed to run command 'java':No such file or directory 这是因为jenkins只认绝对路径.在shell里面有涉及到文件的都应该写成绝 ...

  7. 2018 Python开发者大调查:Python和JavaScript最配?

    在2018年秋季,Python软件基金会与JetBrains发起了年度Python开发者调查. 报告的目的是寻找Python领域的新趋势,帮助开发者深入了解2018年Python开发者的现状. 该报告 ...

  8. OpenCV中图像的读取,显示与保存

      图像的读取,显示与保存 相关函数:cv2.imread().cv2.imshow().cv2.imwrite() 1.读入图像: 用cv2.imread()函数来读取图像,cv2.imread(路 ...

  9. python偏函数使用

    偏函数依托于python functools模块.

  10. loj2005 「SDOI2017」相关分析

    鬼畜线段树--Orz Capella #include <iostream> #include <cstdio> using namespace std; int n, m, ...