블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2731)
Unity3D (814)
Script (91)
Extensions (14)
Effect (3)
NGUI (77)
UGUI (8)
Physics (2)
Shader (36)
Math (1)
Design Pattern (2)
Xml (1)
Tips (200)
Link (22)
World (1)
AssetBundle (25)
Mecanim (2)
Plugins (68)
Trouble Shooting (68)
Encrypt (7)
LightMap (4)
Shadow (4)
Editor (8)
Crash Report (3)
Utility (9)
UnityVS (2)
Facebook SDK (2)
iTween (3)
Font (10)
Ad (14)
Photon (2)
IAP (1)
Google (8)
Android (45)
iOS (41)
Programming (474)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (57)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (51)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday
03-30 00:00

Answer by misterPantoni 

After a lot of tests and googeling around i found a working solution, although i am not totally happy with it:

If you store the lightmaps and the LightmapSettings for each renderer in a custom script, you can load the lightmaps on runtime. Look at this forum post and the sample project provided there, this is how i got it to work:

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

The "bad" thing is, that now i need to have a duplicate of the lightmaps stored in my custom script - whenever i try to assign the lightmaps which are "in the scene" (and also after loading the assetbundle, at least in the editor i can see them), they somehow are not beeing loaded correcty by the renderers and i get wrong lightmap positions. So i have to store the lightmaps as extra texture and add them to the lightmap array to use them.

EDIT: The problems with the wrong index were just some indices i messed up - now i got it working the way i want it to, without duplicate Lightmaps. Here is the working script, just place it on the parent object of whatever is lightmapped in your scene you want to use as an assetbundle:

  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. public class SceneAssetBundleLightmaps : MonoBehaviour{
  5. [System.Serializable]
  6. struct RendererInfo{
  7. public Renderer renderer;
  8. public int lightmapIndex;
  9. public Vector4 lightmapOffsetScale;
  10. }
  11. [SerializeField]
  12. RendererInfo[] m_RendererInfo;
  13. void Awake (){
  14. if (m_RendererInfo == null || m_RendererInfo.Length == 0)
  15. return;
  16. ApplyRendererInfo(m_RendererInfo);
  17. }
  18. static void ApplyRendererInfo (RendererInfo[] infos){
  19. for (int i=0;i<infos.Length;i++){
  20. var info = infos[i];
  21. info.renderer.lightmapIndex = info.lightmapIndex;
  22. info.renderer.lightmapScaleOffset = info.lightmapOffsetScale;
  23. }
  24. }
  25. #if UNITY_EDITOR
  26. [UnityEditor.MenuItem("Assets/Assign Scene Assetbundle Lightmaps")]
  27. static void GenerateLightmapInfo (){
  28. if (UnityEditor.Lightmapping.giWorkflowMode != UnityEditor.Lightmapping.GIWorkflowMode.OnDemand){
  29. Debug.LogError("ExtractLightmapData requires that you have baked you lightmaps and Auto mode is disabled.");
  30. return;
  31. }
  32. //UnityEditor.Lightmapping.Bake();
  33. SceneAssetBundleLightmaps[] prefabs = FindObjectsOfType<SceneAssetBundleLightmaps>();
  34. foreach (var instance in prefabs){
  35. var gameObject = instance.gameObject;
  36. var rendererInfos = new List<RendererInfo>();
  37. var lightmaps = new List<Texture2D>();
  38. GenerateLightmapInfo(gameObject, rendererInfos, lightmaps);
  39. instance.m_RendererInfo = rendererInfos.ToArray();
  40. }
  41. }
  42. static void GenerateLightmapInfo (GameObject root, List<RendererInfo> rendererInfos, List<Texture2D> lightmaps){
  43. var renderers = root.GetComponentsInChildren<MeshRenderer>();
  44. foreach (MeshRenderer renderer in renderers){
  45. if (renderer.lightmapIndex != -1)
  46. {
  47. RendererInfo info = new RendererInfo();
  48. info.renderer = renderer;
  49. info.lightmapOffsetScale = renderer.lightmapScaleOffset;
  50. info.lightmapIndex = renderer.lightmapIndex;
  51. rendererInfos.Add(info);
  52. }
  53. }
  54. }
  55. #endif
  56. }



[출처] http://answers.unity3d.com/questions/1278569/unity-5-lightmapped-scene-assetbundle-problem.html

반응형

'Unity3D > LightMap' 카테고리의 다른 글

유니티5 라이트 맵 팁  (0) 2015.06.19
LightMapSize 조절  (0) 2014.03.18
Unity Lightmapping Tips, Tricks and Thoughts  (0) 2014.03.18
Posted by blueasa
, |


링크 : http://blog.naver.com/blue9954/220393256568


참조 : http://blog.naver.com/blue9954/220391202268



반응형

'Unity3D > LightMap' 카테고리의 다른 글

[펌] Unity 5 lightmapped scene assetbundle problem  (0) 2017.04.19
LightMapSize 조절  (0) 2014.03.18
Unity Lightmapping Tips, Tricks and Thoughts  (0) 2014.03.18
Posted by blueasa
, |

LightMapSize 조절

Unity3D/LightMap / 2014. 3. 18. 09:44
using UnityEditor; 

public class LightMapSize_512 : EditorWindow 
{ 
    [MenuItem("LightMapSize/Size_512")] 
    static void Init() 
    { 
        LightmapEditorSettings.maxAtlasHeight = 512; 
        LightmapEditorSettings.maxAtlasWidth = 512; 
    } 
} 

public class LightMapSize_1024 : EditorWindow 
{ 
    [MenuItem("LightMapSize/Size_1024")] 
    static void Init() 
    { 
        LightmapEditorSettings.maxAtlasHeight = 1024; 
        LightmapEditorSettings.maxAtlasWidth = 1024; 
    } 
} 

public class LightMapSize_2048 : EditorWindow 
{ 
    [MenuItem("LightMapSize/Size_2048")] 
    static void Init() 
    { 
        LightmapEditorSettings.maxAtlasHeight = 2048; 
        LightmapEditorSettings.maxAtlasWidth = 2048; 
    } 
} 

public class LightMapSize_4096 : EditorWindow 
{ 
    [MenuItem("LightMapSize/Size_4096")] 
    static void Init() 
    { 
        LightmapEditorSettings.maxAtlasHeight = 4096; 
        LightmapEditorSettings.maxAtlasWidth = 4096; 
    } 
} 
출처 : http://devkorea.co.kr/bbs/board.php?bo_table=m03_qna&wr_id=43889&page=0&sca=&sfl=&stx=&spt=0&page=0&currentId=44#c_43910


반응형
Posted by blueasa
, |


Install "Lightmapping Extended":

Step 1 is to pick up "Lightmapping Extended" on the Unity Asset Store! and commit it into the project!https://www.assetstore.unity3d.com/#/content/6071

While most of the settings are a bit beyond pick up and play, the ability to save and load xml configurations is a life saver and if you are working with a team it can really speed up the workflow. There are great tool tips for the rest of the settings. Without a formal lighting background I make do with what I have and search for what I don't know.

Document Changes:

Despite knowing and saving your production settings with Lightmapping Extended, when dialing in a light setup I take screenshots of the editor and the light map settings panel. This lets me get good before and after images documented when I make subtle changes to the overall settings. It also lets me show others how the system works and how the scene has evolved.

UV scale / ratio fine tuning:

After I get my main light sources in and where I want them I run a high quality bake so I can see where major shadows fall. Armed with this I can manually select all prefabs that are 100% within shadow and set their "Scale in Lightmap" setting down to .1 - .05. Once you have done this to all relevant objects you can do the reverse for 'hero' objects. Unfortunately you often want to increase the light map resolution on large objects such as the ground, and depending on how the geometry is split up the UV block might be too big and bulky to do too much with. (Currently Unity 4.1 does a terrible job auto laying out UV's - according to this thread that should be resolved in 4.2)

Maximize your resolution within your output targets:

Once I have all the manual light map scaling in place I then nuke my settings back down to a 10-20 second render time and start inching the resolution up or down to get everything at my desired output target. We often want to get everything onto 1 1024 map (which we can still cut down later). I want the scene to look as good as it can be - even if it means spending an hour bumping up the resolution by .01!

Editing the light map .exr file:

While my options are limited I from time to time do bring in the final .exr image into Photoshop for some slight level adjustments Note that doing this will probably hose you if you need to do dual light map realtime lighting. Photoshop is pretty limited in what you can do to a 32 channel image however I do have a work around for solidifying unity's output if I feel the image will benefit form it. since you can't use the magic wand with a tolerance of 1 to select out and delete the black I save off a version with 16 channels, save a selection of what I want to delete and load it back into the 32 bit file, delete out the black and run Solidify A on it to blend in the image. I am 100% sure there is an easier way to do this - I just have no experience editing HDR files, let alone 16bit in photoshop.

Wishes:

I would LOVE to be able to set what I want my output to be and have Unity fill in the rest. I usually have to spend an hour or two over the course of a scene setup fine tuning the atlas resolution trying to get it all onto 1 1024 map for instance. This changes and needs to be re-optimized every time you manually set a scale override on something in your scene (which I have the tendency to do quite often!)

Additionally I would LOVE to have some sort of automated workflow occur where I could set up a stationary camera that takes the same screenshot after every bake and splices in the settings data as well!

That's all for now, hope this saves somebody some time!




출처 http://mkingery.com/blog/unity-lightmapping-tips-tricks-and-thoughts

반응형

'Unity3D > LightMap' 카테고리의 다른 글

[펌] Unity 5 lightmapped scene assetbundle problem  (0) 2017.04.19
유니티5 라이트 맵 팁  (0) 2015.06.19
LightMapSize 조절  (0) 2014.03.18
Posted by blueasa
, |