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

事先烘培出亮、暗两张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. NFS缓存IO机制

    NFS的缓存IO机制<一> async 参数模式下分析 NFS 默认的mount参数为async,async 参数表示内核不会透传程序的IO请求给sever,对于写IO会延迟执行,积累一定 ...

  2. ES6中const的用法

    const声明一个只读的常量.一旦声明,常量的值就不能改变.且const一旦声明变量,就必须立即初始化,不能留到以后赋值. const的作用域与let命令相同:只在声明所在的块级作用域内有效. con ...

  3. 关于java字符串常量池

    今天发现一个好玩的东西 public static void main(String[] args)    {        String str1 = new StringBuilder(" ...

  4. 7.Props向子组件传递数据

    组件实例的作用域是孤立的.这意味着不能并且不应该在子组件的模板内直接引用父组件的数据. 可以使用 props 把数据传给子组件. for-child-msg="aaa"  , fo ...

  5. python入门:if、elif、else 条件语句的基本用法

    #!/usr/bin/env python # -*- coding:utf-8 -*- #elif(否则如果,译音:埃尔夫)eise(否则,译音:埃尔斯) #if.elif.else 条件语句的基本 ...

  6. biological clock--class

    '''this application aimed to cauculate people's biological block about emotional(28), energy(23),int ...

  7. sqlmanagementstudio2008下载地址

    http://big.wy119.com/sqlmanagementstudio2008_x86_chs.zip

  8. 10个MCU常用的基础知识

    转自:http://bbs.21ic.com/icview-2659278-1-1.html 1.MCU有串口外设的话,在加上电平转换芯片,如MAX232.SP3485就是RS232和RS485接口了 ...

  9. 思维题:UVa1334-Ancient Cipher

    Ancient Cipher Ancient Roman empire had a strong government system with various departments, includi ...

  10. German Collegiate Programming Contest 2015

    // Legacy Code #include <iostream> #include <cstdio> #include <cstring> #include & ...