Search Unity

Question Is there any solution that LightmapParameters via script ?? version 2019.2

Discussion in 'Global Illumination' started by power6574, Apr 7, 2021.

  1. power6574

    power6574

    Joined:
    Apr 29, 2020
    Posts:
    6
    Code (CSharp):
    1. // Parameter
    2.     LightmapParameters m_defaultLightmapParameters = new LightmapParameters();
    3.     private static SerializedObject GetLightmapSettings()
    4.     {
    5.         var getLightmapSettingsMethod = typeof(LightmapEditorSettings).GetMethod("GetLightmapSettings", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
    6.         var lightmapSettings = getLightmapSettingsMethod.Invoke(null, null) as UnityEngine.Object;
    7.         return new SerializedObject(lightmapSettings);
    8.     }
    9.  
    10.     private void GetValue()
    11.     {
    12.         SerializedObject baseSettings = GetLightmapSettings();
    13.         SerializedProperty lightmapParameters = baseSettings.FindProperty("m_LightmapEditorSettings.m_LightmapParameters");
    14.  
    15.         m_defaultLightmapParameters = lightmapParameters.objectReferenceValue as LightmapParameters;
    16.     }
    17.  
    18.     private void SetValue()
    19.     {
    20.         SerializedObject baseSettings = GetLightmapSettings();
    21.         SerializedProperty lightmapParameters = baseSettings.FindProperty("m_LightmapEditorSettings.m_LightmapParameters");
    22.  
    23.         lightmapParameters.objectReferenceValue = m_defaultLightmapParameters;
    24.  
    25.         baseSettings.ApplyModifiedProperties();
    26.     }
    27.  
    28. // laurenth-personal/lightmap-switching-tool
    29.  
    30. private IEnumerator BuildLightingAsync(Scene lightingScene)
    31.     {
    32.         Lightmapping.ClearDiskCache();
    33.         var newLightmapMode = new LightmapsMode();
    34.         newLightmapMode = LightmapSettings.lightmapsMode;
    35.         // setting part
    36.         LightmapEditorSettings.prioritizeView = true;
    37.         LightmapEditorSettings.directSampleCount = 32;
    38.         LightmapEditorSettings.indirectSampleCount = 512;
    39.         LightmapEditorSettings.environmentSampleCount = 256;
    40.         LightmapEditorSettings.bounces = 2;
    41.         LightmapEditorSettings.maxAtlasSize = 1024;
    42.         LightmapEditorSettings.lightmapper = LightmapEditorSettings.Lightmapper.ProgressiveGPU;
    43.         LightmapEditorSettings.mixedBakeMode = MixedLightingMode.IndirectOnly;
    44.         LightmapEditorSettings.bakeResolution = 2;
    45.         LightmapEditorSettings.enableAmbientOcclusion = false;
    46.         LightmapEditorSettings.padding = 2;
    47.         // parameter part
    48.         GetValue();
    49.         m_defaultLightmapParameters.name = "Test";
    50.         m_defaultLightmapParameters.antiAliasingSamples = 256;
    51.         m_defaultLightmapParameters.limitLightmapCount = true;
    52.         m_defaultLightmapParameters.maxLightmapCount = 3;
    53.         SetValue();
    54.  
    55.         //LightmapSettings.
    56.         Lightmapping.BakeAsync();
    57.         while (Lightmapping.isRunning) { yield return null; }
    58.         EditorSceneManager.SaveScene(lightingScene);
    59.         EditorSceneManager.CloseScene(lightingScene, true);
    60. }
    Oh.. It doesn't Work..

    I have no idea that how to access to lightmapParameters via code

    ! help me !
     
    Last edited: Apr 7, 2021
  2. kristijonas_unity

    kristijonas_unity

    Unity Technologies

    Joined:
    Feb 8, 2018
    Posts:
    1,080
    Have you looked through the Unity manual regarding this?
     
  3. power6574

    power6574

    Joined:
    Apr 29, 2020
    Posts:
    6
    Yes. I read it.

    So, I tried baking another way.

    First, I wrote a script that changes the lighting parameter on the 'Lighting Editor Settings' window.

    Second, I changed the parameter's properties via the script.

    Finally, I tried baking Light via another script for light baking.
    (not the Inspector of lighting settings but the custom tool of lighting settings like on the thread script.)

    And then I found In the inspector the lighting parameter name is only changed.

    In the Dropdown of the parameter, except for the changed name, the custom parameter item does not exist.

    But, there is not any error in the baking process.

    So, it is really applied to the baking process?
     
    Last edited: Apr 8, 2021
  4. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    If you want to see your created lightmap parameters via script into the list, you must save your lightmap parameters as asset into your project files
    https://docs.unity3d.com/ScriptReference/AssetDatabase.CreateAsset.html



    Code (CSharp):
    1. LightmapParameters a = new LightmapParameters();
    2.  
    3.             a.name = "Lighting Box Very-Low";
    4.             a.resolution = 0.125f;
    5.             a.clusterResolution = 0.4f;
    6.             a.irradianceBudget = 96;
    7.             a.irradianceQuality = 8192;
    8.             a.modellingTolerance = 0.001f;
    9.             a.stitchEdges = true;
    10.             a.isTransparent = false;
    11.             a.systemTag = -1;
    12.             a.blurRadius = 2;
    13.             a.antiAliasingSamples = 8;
    14.             a.directLightQuality = 64;
    15.             a.bakedLightmapTag = -1;
    16.             a.AOQuality = 256;
    17.             a.AOAntiAliasingSamples = 16;
    18.             a.backFaceTolerance = backfaceTolerance;
    19.  
    20.             //LB_LightingSettingsHepler.SetLightmapParameters (a);
    21.             LightmapParameters.SetLightmapParametersForLightingSettings(a, Lightmapping.lightingSettings);
    22.             AssetDatabase.CreateAsset(a, "Assets/Lighting Box Very-Low.giparams");
    23.  
     
    kristijonas_unity likes this.
  5. power6574

    power6574

    Joined:
    Apr 29, 2020
    Posts:
    6
    Thank You! . I will try it.
     
  6. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    tested and works well
     
    Deleted User likes this.