Code Sample: Lightmapping code for prefabs in Unity*

By Alejandr Castedo,

Published:08/17/2018   Last Updated:08/17/2018

File(s): Download
License: Intel Sample Source Code License Agreement
Optimized for...  
OS: Windows® 10
Hardware: N/A
Software:
(Programming Language, tool, IDE, Framework)
C#, Unity*
Prerequisites: Familiarity with the Unity’s C# scripting. Unity 5 or beyond installed and configured.

Introduction

Attach this script as a component to any prefab you might want to lightmap. From the editor window inside Unity you can setup a scene with proper lighting and position your prefabs inside the scene as per your requirements. In the Editor go to Assets-> Bake Prefab Lightmaps which will generate the baked lighting and save it in any prefabs with the script. You can now spawn in different scenes with the baked lighting.

Get Started

Download the code from GitHub* and read Optimization for Unity* Software and Virtual Reality: Run-Time Generated Content for a better understanding of how to prefab you might want to lightmap.

References

https://docs.unity3d.com/ScriptReference/LightmapData.html

https://forum.unity.com/threads/problems-with-instantiating-baked-prefabs.324514/

Updated Log

Created July 17, 2018

Product and Performance Information

1

Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804