代码之夏:外部光照映射的进展

This blog post is written by Michał Mandrysz who is working on support for External Lightmapping in Unity. The project is one of four selected projects that were selected for the Unity Summer of Code.

这篇博客由 MichałMandrysz 撰写, 他正在致力于支持Unity中的外部照明贴图。 该项目是为Unity夏季代码选择的四个选定项目 之一

What’s lightmapping?

什么是光映射?

If you’re not familiar with the terms “baking” and “lightmapping” then let me introduce them to you a little. Baking is an operation of prerendering expensive details (in calculational sense) like illuminated lightning, highlights and shadows into a texture so that it doesn’t have to be renderered at realtime. It requires some additional effort from the game designers, but it benefits hugely in performance. This solution is pretty old, but according to words of John Carmack it’s still up-to-date and will be – even in high end games.

如果您不熟悉“烘焙”和“光照贴图”这两个术语,那么让我向您介绍一下。 烘焙是一种将昂贵的细节(在计算意义上)(例如照明的闪电,高光和阴影)预先渲染到纹理中的操作,因此不必实时渲染。 它需要游戏设计师付出额外的努力,但在性能上却大有裨益。 这个解决方案已经很老了,但是根据约翰·卡马克(John Carmack)的话,它仍然是最新的,并且即使在高端游戏中也将是最新的。

What is the Lightmapping Tool? It’s a tool for lightmapping scenes in external applications (yeah, I know most of you would  wish to see an integrated system, but it’s not that easy to write this kind of system; however there are several huge benefits from using an external one, especially as powerful one as VRay). As you may have heard before, my job is to wire lightmapping process tightly with 3dsmax and VRay. The system automates the process of both external baking, and setting up the lightmaps in Unity. Lightmapping tool manages up to 99 lightmap atlases (could be even more but the interface would have to be modded for such extreme jobs) which hold object information with resolution proportional to their size on the stage. It can start external applications (currently only 3dsmax), assign appropriate renderer or load a preset max scene which holds information about lightning and so on. I’m planning to make a short screencast video when the work is done, so you can be sure you understand everything clearly ;-)

什么是Lightmapping工具? 它是用于在外部应用程序中映射场景的工具(是的,我知道你们中的大多数人都希望看到一个集成的系统,但是编写这种系统并不容易;但是,使用外部系统有很多巨大的好处,特别是像VRay一样强大)。 就像您之前听到的那样,我的工作是使用3dsmax和VRay紧密绑定灯光映射过程。 系统会自动进行外部烘焙和在Unity中设置光照贴图的过程。 光照贴图工具最多可管理99个光照图地图集(可能会更多,但必须修改界面以用于此类极端任务),这些地图集可容纳分辨率与舞台上大小成比例的对象信息。 它可以启动外部应用程序(当前仅3dsmax),分配适当的渲染器或加载预设的最大场景,该场景包含有关闪电的信息等。 我计划在完成工作后制作一个简短的截屏视频,因此可以确保您清楚地了解所有内容;-)

代码之夏:外部光照映射的进展

This picture presents about 1/6 of a whole scene lightmapped with only one 2kx2k lightmap rendered with VRay on medium settings

这张图片显示了整个场景的大约1/6,其中只有一个2kx2k的光照贴图通过VRay在中等设置下渲染

What makes this solution different? Many people have asked me how my tool will change the way the lightmapping is done. The answer is  quite simple – it gives you the power to decide whatever in scene will be static (and lightmapped) or not – at anytime without much pain.

是什么使该解决方案与众不同? 许多人问我,我的工具将如何改变光照贴图的完成方式。 答案很简单–它使您可以随时确定场景中的任何内容是静态的(或有灯光映射的)或没有静态的-无需太多痛苦。

Let me introduce how the workflow is looking:

让我介绍一下工作流程的外观:

代码之夏:外部光照映射的进展
  1. Open a the lightmapping tool (all the previously lightmapped objects from the scene will be  already present at Lightmapping tools lists),

    打开一个光照贴图工具(场景中所有以前的光照贴图对象将已经出现在光照贴图工具列表中),
  2. Setup export options,

    设置导出选项,
  3. Export to 3dsmax and make anything that’s needed to make the scene look good,

    导出到3dsmax,并进行使场景看起来更好的一切操作,
  4. Max will be opened (if not opened before),

    Max将被打开(如果之前未打开),
  5. Setup lightning in 3dsmax and store presets with light and renderer settings using the the  additional tool Lightmapping. You’ll be able to switch between them later to render the scene,

    使用附加工具“ Lightmapping”在3dsmax中设置闪电,并使用灯光和渲染器设置存储预设。 您稍后可以在它们之间切换以渲染场景,
  6. Bake them with a single click.

    只需单击一下即可烘烤它们。
  7. Come back to Unity to see the effects of your work. No texture drag and dropping – everything is automated ;)

    返回Unity来查看您的工作效果。 没有纹理拖放-一切都是自动化的;)

How is the work going? Most of the options you’ve seen are implemented and working, today the system hits it’s first beta day and will be given to first beta testers (by the way: if you’re interested in beta testing, please write a message to masteranza at gmail dot com).

工作进展如何? 您所看到的大多数选项都已实现并正常运行,今天该系统将是第一个beta测试日,并将提供给第一个beta测试人员(顺便说一句:如果您对beta测试感兴趣,请在以下网址给masteranza写一条消息: gmail点com)。

It’s over four weeks of developing right now, and I must say that the original idea really evolved. I’ve read some feedback coming from the community  and I decided to generalize my system. Of course I stick to the guide lines (Main Goals) send to Unity team, but I try to generalize whenever is possible. Let’s look at the “Advanced” window – it was not designed to fit 3dsmax or VRay options only, but with a little effort every external tool.

现在的发展已经超过四个星期,我必须说,最初的想法确实在演变。 我已经阅读了一些来自社区的反馈,因此决定对我的系统进行概括。 当然,我会坚持发送给Unity团队的指导原则(主要目标),但是我会尽可能地概括一下。 让我们看一下“高级”窗口-它不是专门为仅适合3dsmax或VRay选项而设计的,而是需要花一点功夫才能使用所有外部工具。

代码之夏:外部光照映射的进展

What’s more, after exporting, the FBX file system waits for lightmaps to appear so, automatic setting up them is also tool independent. I will do my best to help everyone willing to extend the system in future for such tools like Blender, Maya and so on.

更重要的是,导出后,FBX文件系统等待光照贴图出现,因此自动设置它们也与工具无关。 我将尽力为将来愿意使用Blender,Maya等工具扩展系统的每个人提供帮助。

What’s left to do for this week:

这周剩下要做的事情:

  • correct the material setting subsystem

    纠正材料设置子系统
  • correct some issues with lightmap edges

    纠正光照贴图边缘的一些问题
  • eliminate bugs

    消除错误
  • optimize the code

    优化代码
  • try making GUI more intuitive

    尝试使GUI更直观
  • gather feedback from beta testers and make improvements

    收集Beta测试人员的反馈意见并进行改进
  • make icons and additional graphics for both (Unity and Max) interfaces

    为(Unity和Max)界面制作图标和其他图形

Personal experience Developing the system gave and still gives me a lot of satisfaction. I’ve learned a lot of things and had a chance to use things I’ve learned in school in practice. Starting from Immediate-GUI, going through the ‘normals space’, up to some deeper MaxScript insights. Although it took me almost half of my vacations [and a small eye strain ;-D] I’ve already planned a game development in Unity as soon as I get my Unity Pro license.

开发该系统的个人经验给了我,但仍然给我很多满意。 我学到了很多东西,并且有机会在实践中使用我在学校学到的东西。 从Instant-GUI开始,一直到“法线空间”,再到更深入的MaxScript见解。 尽管花了我几乎一半的假期[和一点点眼睛疲劳;-D],但我已经获得Unity Pro许可证就已经计划在Unity中进行游戏开发。

What I noticed during development is that Unity makes some things really easy to do and it’s not only about the Unity Engine internals, but the way things are organized here – I’m thinking about the huge community, enormous library of already written scripts and almost instant help on any problem.

我在开发过程中注意到的是,Unity确实使某些事情真正易于实现,这不仅关乎Unity Engine内部,而且关乎这里的组织方式–我正在考虑的是庞大的社区,庞大的已编写脚本库以及几乎所有内容。即时解决任何问题。

翻译自: https://blogs.unity3d.com/2009/08/24/progress-on-external-lightmapping-support/