/// <summary> /// Sets the baked lightmapping settings /// </summary> /// <param name="profile"></param> public static void SetBakedGISettings(AmbientLightingProfile profile) { LightmapEditorSettings.bakeResolution = profile.lightmapResolution; LightmapEditorSettings.padding = profile.lightmapPadding; #if UNITY_2018_3_OR_NEWER LightmapEditorSettings.filteringMode = profile.filterMode; #endif #if !UNITY_2018_3_OR_NEWER if (profile.lightmappingMode == AmbientSkiesConsts.LightmapperMode.Enlighten) { LightmapEditorSettings.lightmapper = LightmapEditorSettings.Lightmapper.Enlighten; } else if (profile.lightmappingMode == AmbientSkiesConsts.LightmapperMode.ProgressiveCPU) { LightmapEditorSettings.lightmapper = LightmapEditorSettings.Lightmapper.ProgressiveCPU; } #else if (profile.lightmappingMode == AmbientSkiesConsts.LightmapperMode.Enlighten) { LightmapEditorSettings.lightmapper = LightmapEditorSettings.Lightmapper.Enlighten; } else if (profile.lightmappingMode == AmbientSkiesConsts.LightmapperMode.ProgressiveCPU) { LightmapEditorSettings.lightmapper = LightmapEditorSettings.Lightmapper.ProgressiveCPU; } else { LightmapEditorSettings.lightmapper = LightmapEditorSettings.Lightmapper.ProgressiveGPU; } #endif if (profile.useHighResolutionLightmapSize) { #if !UNITY_2018_1_OR_NEWER LightmapEditorSettings.maxAtlasHeight = 4096; #endif LightmapEditorSettings.maxAtlasSize = 4096; } else if (!profile.useHighResolutionLightmapSize) { #if !UNITY_2018_1_OR_NEWER LightmapEditorSettings.maxAtlasHeight = 1024; #endif LightmapEditorSettings.maxAtlasSize = 1024; } LightmapEditorSettings.textureCompression = profile.compressLightmaps; LightmapEditorSettings.enableAmbientOcclusion = profile.ambientOcclusion; LightmapEditorSettings.aoMaxDistance = profile.maxDistance; LightmapEditorSettings.aoExponentIndirect = profile.indirectContribution; LightmapEditorSettings.aoExponentDirect = profile.directContribution; }
/// <summary> /// Load the selected profile and apply it /// </summary> /// <param name="profile">The profiles object</param> /// <param name="profileName">The name of the profile to load</param> /// <param name="useDefaults">Whether to load default settings or current user settings.</param> public static void SetFromProfileName(AmbientSkyProfiles skyProfiles, AmbientSkyProfiles profile, string profileName, bool useDefaults, bool updateRealtime, bool updateBaked) { AmbientLightingProfile p = profile.m_lightingProfiles.Find(x => x.name == profileName); if (p == null) { Debug.LogWarning("Invalid profile name supplied, can not apply post processing profile!"); return; } SetLightmapSettings(skyProfiles, p, useDefaults, updateRealtime, updateBaked); }
/// <summary> /// Sets the realtime lightmapping settings /// </summary> /// <param name="profile"></param> public static void SetRealtimeGISettings(AmbientLightingProfile profile) { LightmapEditorSettings.realtimeResolution = profile.indirectRelolution; if (profile.useDirectionalMode) { LightmapSettings.lightmapsMode = LightmapsMode.CombinedDirectional; } else if (!profile.useDirectionalMode) { LightmapSettings.lightmapsMode = LightmapsMode.NonDirectional; } }
/// <summary> /// Sets up the lighting /// </summary> /// <param name="profile"></param> /// <param name="useDefaults"></param> public static void SetLightmapSettings(AmbientSkyProfiles skyProfiles, AmbientLightingProfile profile, bool useDefaults, bool updateRealtime, bool updateBaked) { //Clear console if required if (skyProfiles.m_smartConsoleClean) { SkyboxUtils.ClearLog(); Debug.Log("Console cleared successfully"); } if (profile.autoLightmapGeneration) { Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.Iterative; } else { Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.OnDemand; } Lightmapping.bounceBoost = profile.lightBoostIntensity; Lightmapping.indirectOutputScale = profile.lightIndirectIntensity; Lightmapping.realtimeGI = profile.realtimeGlobalIllumination; Lightmapping.bakedGI = profile.bakedGlobalIllumination; if (profile.realtimeGlobalIllumination) { if (updateRealtime) { if (skyProfiles.m_showFunctionDebugsOnly) { Debug.Log("Updating: SetRealtimeGISettings()"); } SetRealtimeGISettings(profile); } } if (profile.bakedGlobalIllumination) { if (updateBaked) { if (skyProfiles.m_showFunctionDebugsOnly) { Debug.Log("Updating: SetBakedGISettings()"); } SetBakedGISettings(profile); } } }
/// <summary> /// Load the selected profile and apply to the lightmap settings /// </summary> /// <param name="profiles">The profiles object</param> /// <param name="profileIndex">The zero based index to load</param> /// <param name="useDefaults">Whether to load default settings or current user settings.</param> public static void SetFromProfileIndex(AmbientSkyProfiles skyProfiles, AmbientLightingProfile profiles, int profileName, bool useDefaults, bool updateRealtime, bool updateBaked) { if (skyProfiles == null) { Debug.LogError("Missing the sky profiles (m_profiles from Ambient Skies) try reopening ambient skies and try again. Exiting"); return; } if (profiles == null) { Debug.LogError("Missing the sky profiles (m_selectedLightingProfile from Ambient Skies) try reopening ambient skies and try again. Exiting"); return; } AmbientLightingProfile p = profiles; if (p == null) { Debug.LogWarning("Invalid profile index selected, can not apply lightmapping settings!"); return; } SetLightmapSettings(skyProfiles, p, false, updateRealtime, updateBaked); }
/// <summary> /// Creates a reflection probe at current scene view camera location /// </summary> /// <param name="profile"></param> /// <param name="renderPipelineSettings"></param> public static void CreateProbeAtLocation(AmbientLightingProfile profile, AmbientSkiesConsts.RenderPipelineSettings renderPipelineSettings) { GameObject oldReflectionProbe = GameObject.Find("Global Reflection Probe"); if (oldReflectionProbe != null) { Object.DestroyImmediate(oldReflectionProbe); Debug.Log("Old Reflection Probe Destroyed"); } //Creates the probe GameObject createdProbeObject = new GameObject(profile.reflectionProbeName); //Assign scene view camera Vector3 position = SceneView.lastActiveSceneView.camera.transform.position; if (SceneView.lastActiveSceneView.pivot != position) { //Set position based on scene view camera position createdProbeObject.transform.localPosition = position; } else { Debug.LogWarning("Scene View camera not found, probe spawned at position 0, 0, 0"); } //Parent the probe object GameObject reflectionProbeParent = ReflectionProbeParenting(true); createdProbeObject.transform.SetParent(reflectionProbeParent.transform); //Add probe data ReflectionProbe probeData = createdProbeObject.AddComponent <ReflectionProbe>(); //Configure Probe settings probeData.blendDistance = profile.reflectionProbeBlendDistance; probeData.cullingMask = profile.reflectionprobeCullingMask; probeData.farClipPlane = profile.reflectionProbeClipPlaneDistance; probeData.mode = profile.reflectionProbeMode; probeData.refreshMode = profile.reflectionProbeRefresh; probeData.blendDistance = 5f; switch (profile.reflectionProbeResolution) { case AmbientSkiesConsts.ReflectionProbeResolution.Resolution16: probeData.resolution = 16; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution32: probeData.resolution = 32; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution64: probeData.resolution = 64; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution128: probeData.resolution = 128; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution256: probeData.resolution = 256; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution512: probeData.resolution = 512; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution1024: probeData.resolution = 1024; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution2048: probeData.resolution = 2048; break; } probeData.shadowDistance = profile.reflectionProbeShadowDistance; probeData.size = profile.reflectionProbeScale; probeData.timeSlicingMode = profile.reflectionProbeTimeSlicingMode; probeData.hdr = true; probeData.shadowDistance = profile.reflectionProbeShadowDistance; //If HDRP if (renderPipelineSettings == AmbientSkiesConsts.RenderPipelineSettings.HighDefinition) { #if HDPipeline && UNITY_2018_3_OR_NEWER HDAdditionalReflectionData reflectionData = createdProbeObject.GetComponent <HDAdditionalReflectionData>(); if (reflectionData == null) { reflectionData = createdProbeObject.AddComponent <HDAdditionalReflectionData>(); reflectionData.multiplier = 1f; } else { reflectionData.multiplier = 1f; } #endif } m_currentProbeCount++; SceneView.lastActiveSceneView.Repaint(); EditorGUIUtility.PingObject(createdProbeObject); }
/// <summary> /// Setup for the automatically probe spawning /// </summary> /// <param name="profile"></param> public static void CreateAutomaticProbes(AmbientLightingProfile profile, AmbientSkiesConsts.RenderPipelineSettings renderPipelineSettings) { GameObject oldReflectionProbe = GameObject.Find("Global Reflection Probe"); if (oldReflectionProbe != null) { Object.DestroyImmediate(oldReflectionProbe); Debug.Log("Old Reflection Probe Destroyed"); } GameObject relfectionParentObject = ReflectionProbeParenting(true); int numberTerrains = Terrain.activeTerrains.Length; if (numberTerrains == 0) { Debug.LogError("Unable to initiate probe spawning systen. No terrain found"); return; } else { if (profile.reflectionProbesPerRow < 2) { Debug.LogError("Please set Probes Per Row to a value of 2 or higher"); return; } else { m_currentProbeCount = 0; float seaLevel = 0f; bool seaLevelActive = false; #if GAIA_PRESENT Gaia.GaiaSessionManager gaiaSession = Object.FindObjectOfType <Gaia.GaiaSessionManager>(); if (gaiaSession != null) { seaLevel = profile.seaLevel; seaLevelActive = true; } #else seaLevel = profile.seaLevel; #endif for (int terrainIdx = 0; terrainIdx < numberTerrains; terrainIdx++) { Terrain terrain = Terrain.activeTerrains[terrainIdx]; Vector3 terrainSize = terrain.terrainData.size; for (int row = 0; row < profile.reflectionProbesPerRow; ++row) { for (int columns = 0; columns < profile.reflectionProbesPerRow; ++columns) { GameObject probeObject = new GameObject("Global Generated Reflection Probe"); Vector3 newPosition = probeObject.transform.position; newPosition.x = ((columns + 1) * terrainSize.x / profile.reflectionProbesPerRow) - terrainSize.x / profile.reflectionProbesPerRow / 2f + terrain.transform.position.x; newPosition.z = ((row + 1) * terrainSize.z / profile.reflectionProbesPerRow) - terrainSize.z / profile.reflectionProbesPerRow / 2f + terrain.transform.position.z; float sampledHeight = terrain.SampleHeight(newPosition); ReflectionProbe probeData = probeObject.AddComponent <ReflectionProbe>(); probeData.enabled = false; probeData.blendDistance = 0f; probeData.cullingMask = profile.reflectionprobeCullingMask; probeData.farClipPlane = profile.reflectionProbeClipPlaneDistance; probeData.mode = profile.reflectionProbeMode; probeData.refreshMode = profile.reflectionProbeRefresh; if (seaLevelActive) { newPosition.y = 500f + seaLevel + 0.2f; } else { newPosition.y = sampledHeight + profile.reflectionProbeOffset; probeData.center = new Vector3(0f, 0f - profile.reflectionProbeOffset - sampledHeight, 0f); } probeObject.transform.position = newPosition; probeObject.transform.SetParent(relfectionParentObject.transform); switch (profile.reflectionProbeResolution) { case AmbientSkiesConsts.ReflectionProbeResolution.Resolution16: probeData.resolution = 16; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution32: probeData.resolution = 32; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution64: probeData.resolution = 64; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution128: probeData.resolution = 128; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution256: probeData.resolution = 256; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution512: probeData.resolution = 512; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution1024: probeData.resolution = 1024; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution2048: probeData.resolution = 2048; break; } probeData.shadowDistance = 80f; probeData.size = new Vector3(terrainSize.x / profile.reflectionProbesPerRow, terrainSize.y, terrainSize.z / profile.reflectionProbesPerRow); probeData.timeSlicingMode = profile.reflectionProbeTimeSlicingMode; probeData.hdr = true; probeData.shadowDistance = profile.reflectionProbeShadowDistance; //If HDRP if (renderPipelineSettings == AmbientSkiesConsts.RenderPipelineSettings.HighDefinition) { #if HDPipeline && UNITY_2018_3_OR_NEWER HDAdditionalReflectionData reflectionData = probeObject.GetComponent <HDAdditionalReflectionData>(); if (reflectionData == null) { reflectionData = probeObject.AddComponent <HDAdditionalReflectionData>(); reflectionData.multiplier = 1f; } else { reflectionData.multiplier = 1f; } #endif } m_storedProbes.Add(probeData); m_currentProbeCount++; } } } #if HDPipeline && GAIA_PRESENT if (seaLevelActive) { GameObject planarObject = GameObject.Find("Gaia Water Planar Reflections Object"); if (planarObject == null) { planarObject = new GameObject("Gaia Water Planar Reflections Object"); PlanarReflectionProbe planar = planarObject.AddComponent <PlanarReflectionProbe>(); planar.mode = ProbeSettings.Mode.Realtime; planar.realtimeMode = ProbeSettings.RealtimeMode.OnEnable; planar.influenceVolume.shape = InfluenceShape.Box; planar.influenceVolume.boxSize = new Vector3(10000f, 5f, 10000f); planarObject.transform.position = new Vector3(0f, profile.seaLevel + 0.2f, 0f); planarObject.transform.SetParent(relfectionParentObject.transform); } } #endif m_probeRenderActive = true; } } }
/// <summary> /// Setup for the automatically probe spawning /// </summary> /// <param name="profile"></param> public static void CreateAutomaticProbes(AmbientLightingProfile profile) { GameObject lightParentObject = LightProbeParenting(true); int numberTerrains = Terrain.activeTerrains.Length; if (numberTerrains == 0) { Debug.LogError("Unable to initiate probe spawning systen. No terrain found"); return; } else { if (profile.lightProbesPerRow < 2) { Debug.LogError("Please set Light Probes Per Row to a value of 2 or higher"); return; } else { LoadProbesFromScene(); GameObject lightProbeObject = GameObject.Find("Light Probes Group Data"); if (lightProbeObject == null) { lightProbeObject = new GameObject("Light Probes Group Data"); } LightProbeGroup lightProbeData = lightProbeObject.GetComponent <LightProbeGroup>(); if (lightProbeData == null) { lightProbeData = lightProbeObject.AddComponent <LightProbeGroup>(); lightProbeData.probePositions = new Vector3[0]; } m_probeLocations = null; float seaLevel = 0f; #if GAIA_PRESENT Gaia.GaiaSessionManager gaiaSession = Object.FindObjectOfType <Gaia.GaiaSessionManager>(); if (gaiaSession != null) { seaLevel = profile.seaLevel; } else { seaLevel = profile.seaLevel; } #else seaLevel = profile.seaLevel; #endif for (int terrainIdx = 0; terrainIdx < numberTerrains; terrainIdx++) { Terrain terrain = Terrain.activeTerrains[terrainIdx]; Vector3 terrainSize = terrain.terrainData.size; m_storedProbes = profile.lightProbesPerRow * profile.lightProbesPerRow; for (int row = 0; row < profile.lightProbesPerRow; ++row) { for (int columns = 0; columns < profile.lightProbesPerRow; ++columns) { EditorUtility.DisplayProgressBar("Adding Probes", "Adding probes to terrain :" + terrain.name, (float)m_currentProbeCount / (float)m_storedProbes); if (profile.lightProbeSpawnType == AmbientSkiesConsts.LightProbeSpawnType.AutomaticallyGenerated) { Vector3 newPosition = lightProbeObject.transform.position - lightProbeData.transform.position; newPosition.x = ((columns + 1) * terrainSize.x / profile.lightProbesPerRow) - terrainSize.x / profile.lightProbesPerRow / 2f + terrain.transform.position.x; newPosition.z = ((row + 1) * terrainSize.z / profile.lightProbesPerRow) - terrainSize.z / profile.lightProbesPerRow / 2f + terrain.transform.position.z; float sampledHeight = terrain.SampleHeight(newPosition); newPosition.y = sampledHeight + 2.5f; List <Vector3> probePositions = new List <Vector3>(lightProbeData.probePositions); Vector3 position = lightProbeObject.transform.position - lightProbeData.transform.position; //Translate to local space relative to lpg probePositions.Add(newPosition); position += new Vector3(0f, 2.5f, 0f); probePositions.Add(newPosition); position += new Vector3(0f, 10f, 0f); probePositions.Add(newPosition); lightProbeData.probePositions = probePositions.ToArray(); AddProbe(lightProbeObject.transform.position, lightProbeData); m_currentProbeCount++; } else { Vector3 newPosition = lightProbeObject.transform.position - lightProbeData.transform.position; newPosition.x = ((columns + 1) * terrainSize.x / profile.lightProbesPerRow) - terrainSize.x / profile.lightProbesPerRow / 2f + terrain.transform.position.x; newPosition.z = ((row + 1) * terrainSize.z / profile.lightProbesPerRow) - terrainSize.z / profile.lightProbesPerRow / 2f + terrain.transform.position.z; float sampledHeight = terrain.SampleHeight(newPosition); newPosition.y = sampledHeight + 2.5f; List <Vector3> probePositions = new List <Vector3>(lightProbeData.probePositions); Vector3 position = lightProbeObject.transform.position - lightProbeData.transform.position; //Translate to local space relative to lpg if (sampledHeight > seaLevel) { probePositions.Add(newPosition); position += new Vector3(0f, 2.5f, 0f); probePositions.Add(newPosition); position += new Vector3(0f, 10f, 0f); probePositions.Add(newPosition); lightProbeData.probePositions = probePositions.ToArray(); AddProbe(lightProbeObject.transform.position, lightProbeData); m_currentProbeCount++; } } } } EditorUtility.ClearProgressBar(); } lightProbeObject.transform.SetParent(lightParentObject.transform); } } }
/// <summary> /// Creates a reflection probe at current scene view camera location /// </summary> /// <param name="profile"></param> /// <param name="renderPipelineSettings"></param> public static void CreateLightProbeAtLocation(AmbientLightingProfile profile) { GameObject lightProbeObject = GameObject.Find("Light Probes Group Data"); if (lightProbeObject == null) { lightProbeObject = new GameObject("Light Probes Group Data"); } LightProbeGroup lightProbeData = lightProbeObject.GetComponent <LightProbeGroup>(); if (lightProbeData == null) { lightProbeData = lightProbeObject.AddComponent <LightProbeGroup>(); lightProbeData.probePositions = new Vector3[0]; } //Assign scene view camera Vector3 scenePosition = SceneView.lastActiveSceneView.camera.transform.position; if (SceneView.lastActiveSceneView.pivot != scenePosition) { LoadProbesFromScene(); m_probeLocations = null; Terrain terrain = Terrain.activeTerrain; for (int row = 0; row < profile.lightProbesPerRow; ++row) { for (int columns = 0; columns < profile.lightProbesPerRow; ++columns) { //scenePosition = lightProbeObject.transform.position - lightProbeData.transform.position; scenePosition.x = ((columns + 1) * profile.lightProbeSpawnRadius / profile.lightProbesPerRow) - profile.lightProbeSpawnRadius / profile.lightProbesPerRow / 2f; scenePosition.z = ((row + 1) * profile.lightProbeSpawnRadius / profile.lightProbesPerRow) - profile.lightProbeSpawnRadius / profile.lightProbesPerRow / 2f; float sampledHeight = terrain.SampleHeight(scenePosition); scenePosition.y = sampledHeight + 0.5f; List <Vector3> probePositions = new List <Vector3>(lightProbeData.probePositions); Vector3 position = lightProbeObject.transform.position - lightProbeData.transform.position; //Translate to local space relative to lpg probePositions.Add(scenePosition); position += new Vector3(0f, 2.5f, 0f); probePositions.Add(scenePosition); position += new Vector3(0f, 10f, 0f); probePositions.Add(scenePosition); lightProbeData.probePositions = probePositions.ToArray(); AddProbe(lightProbeObject.transform.position, lightProbeData); m_currentProbeCount++; } } } else { Debug.LogWarning("Scene View camera not found, probe spawned at position 0, 0, 0"); } //Parent the probe object GameObject lightProbeParent = LightProbeParenting(true); lightProbeObject.transform.SetParent(lightProbeParent.transform); m_currentProbeCount++; SceneView.lastActiveSceneView.Repaint(); }