Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by Ben 35 · Apr 28, 2011 at 03:35 AM · lightlightmaplightmappingbeast

Beast lightmap ignores light culling mask and/or layers

Similar to this question, which was never really answered, Beast seems to ignore the culling mask associated with lights.

As a test, I created the following project: a static cube with 2 different colored lights shining on it. One light has it's culling mask set to "Nothing". Without lightmapping, this works fine: only one light shows on the cube. However, when lightmapped, both lights show as if the culling mask has been ignored. This seems to happen regardless of whether the lights are point, directional, or spot. This also still happens when using user layers.

Am I doing something wrong here?

EDIT: Anyone? I can't be the only one with this problem... Is there an alternative way prevent certain lights from lighting a specific object in a lightmap?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Enzign · Aug 04, 2011 at 02:17 PM 0
Share

I have the exact same issue. Seems very strange. $$anonymous$$ust be a bug in unity?

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by David · May 06, 2011 at 01:04 PM

I think you have two options to do that. If you want just to bake some objects, select them and use Bake Selected.

If you want just to bake selected lights for an object you can disable the lights you don't want for that object and then bake the objects you want using Bake Selected.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ben 35 · May 07, 2011 at 03:19 AM 0
Share

Thanks for the suggestion. Yeah, that would work for the simple cube example. But in a more complex scene there is a problem because Unity/Beast requires you to bake everything that you want to be lightmapped at once. Lets say I have two cubes side-by-side and two lights: one red light, and one green light. How do I lightmap just the green light on cube1 and just the red light on cube2 ? I thought the answer would be culling mask, but Beast ignores that?

avatar image David · May 07, 2011 at 12:29 PM 1
Share

Yeah, i understand what you mean. The only way to do it is photoshop. You should do a lightmap for each light working over all the objects and merge all on photoshop. I upload a video to youtube to explain it. That would be the only option right now. Video: http://www.youtube.com/watch?v=DrxQ-ZVFVHc

avatar image
5
Wiki

Answer by ricardo_arango · Jul 19, 2013 at 05:47 PM

Use this script to bake your lightmapping taking into account culling masks:

 using UnityEngine;
 using UnityEditor;
 using System.Collections;
 using System.Collections.Generic;
 using System.Linq;
 
 public class BakeLightmaps {
     [MenuItem ("Lightmapping/Bake")]
     static void Bake () {    
         // Get all lights which are active in the scene
         Light[] lights = (from light in (Object.FindObjectsOfType (typeof(Light)) as Light[])
                 where (light.enabled == true && light.gameObject.activeInHierarchy == true) select light).ToArray();
             
         // Get all the game objects which are active in the scene
         GameObject[] gameObjects = (from go in (Object.FindObjectsOfType (typeof(GameObject)) as GameObject[])
                 where (    go.activeInHierarchy == true &&
                         (GameObjectUtility.GetStaticEditorFlags (go) & StaticEditorFlags.LightmapStatic) > 0 &&
                         (go.GetComponent<Renderer>() != null || go.GetComponent<Terrain>() != null ))
                 select go).ToArray();
         
         ILookup<int, GameObject> gameObjectGroups = gameObjects.ToLookup(go => (1 << go.layer));
         
         // Disable all the lights
         SetActive (lights, false);
             
         // For each group of gameObjects with a specific layer, 
         // bake them with the lights that have them in their culling mask
         foreach (IGrouping<int, GameObject> gameObjectGroup in gameObjectGroups)
         {
             int layerForGroup = gameObjectGroup.Key;
             
             GameObject[] gameObjectsForLayer = gameObjectGroup.ToArray();
             Light[] lightsForLayer =
                 (from light in lights where ((light.cullingMask & layerForGroup) > 0) select light).ToArray();
             
             if (lightsForLayer.Count() > 0) {
                 // Enable the lights for baking
                 SetActive (lightsForLayer, true);        
                 
                 // Select the GameObjects and do a "Bake Selected"
                 Selection.objects = gameObjectsForLayer;
                 UnityEditor.Lightmapping.BakeSelected ();
                 
                 // Disable the objects
                 SetActive (lightsForLayer, false);
             }
         }
                     
         // Enable all the lights
         SetActive (lights, true);
         
         // Set all lights to lightmapped to avoid double lighting
         foreach (Light light in lights){
             SerializedObject serializedLight = new SerializedObject (light);
             SerializedProperty actuallyLM = serializedLight.FindProperty ("m_ActuallyLightmapped");
             actuallyLM.boolValue = true;
             serializedLight.ApplyModifiedProperties ();
         }
     }
     
     static void SetActive (Light[] lights, bool active){
         foreach (Light light in lights)
             light.gameObject.SetActive (active);
     }
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Salepate · May 15, 2014 at 10:28 AM 0
Share

Would there be a way to adapt your algorithm to light probe baking? Inside a scene, I have many groups of lightprobes, and I would like each group to receive light from a different directional.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Lightmapping - Shadow power 1 Answer

Lightmapping - Lightmap Resolution 1 Answer

Why Does Lightmapping make everything Super Bright? 0 Answers

extended Tutorial how to setup scene for beast lightmapping 2 Answers

How do I prevent the Ambient Light from influencing lightmap bakes? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges