Exemple #1
0
        private static void GenerateProbesOnTerrain(Terrain terrain, ReflectionProbeData reflectionProbeData, bool seaLevelActive, float seaLevel, GaiaConstants.EnvironmentRenderer renderPipelineSettings)
        {
            GameObject reflectionParentObject = ReflectionProbeParenting(terrain);
            Vector3    terrainSize            = terrain.terrainData.size;

#if GAIA_PRO_PRESENT
            ReflectionProbeManager rpManager = ReflectionProbeManager.Instance;

            for (int row = 0; row < reflectionProbeData.reflectionProbesPerRow; ++row)
            {
                for (int columns = 0; columns < reflectionProbeData.reflectionProbesPerRow; ++columns)
                {
                    Vector3 newPosition = new Vector3
                    {
                        x = ((columns + 1) * terrainSize.x / reflectionProbeData.reflectionProbesPerRow) - terrainSize.x / reflectionProbeData.reflectionProbesPerRow / 2f + terrain.transform.position.x,
                        z = ((row + 1) * terrainSize.z / reflectionProbeData.reflectionProbesPerRow) - terrainSize.z / reflectionProbeData.reflectionProbesPerRow / 2f + terrain.transform.position.z
                    };
                    Vector3 size = new Vector3(terrain.terrainData.size.x / reflectionProbeData.reflectionProbesPerRow, terrain.terrainData.size.y, terrain.terrainData.size.z / reflectionProbeData.reflectionProbesPerRow);
                    if (rpManager != null)
                    {
                        ReflectionProbe newProbe = ReflectionProbeUtils.CreateReflectionProbe(newPosition, size, terrain, reflectionProbeData, seaLevelActive, seaLevel, reflectionParentObject.transform, renderPipelineSettings == GaiaConstants.EnvironmentRenderer.HighDefinition, rpManager.UseReflectionProbeCuller);
                        m_storedProbes.Add(newProbe);
                    }
                    else
                    {
                        ReflectionProbe newProbe = ReflectionProbeUtils.CreateReflectionProbe(newPosition, size, terrain, reflectionProbeData, seaLevelActive, seaLevel, reflectionParentObject.transform, renderPipelineSettings == GaiaConstants.EnvironmentRenderer.HighDefinition);
                        m_storedProbes.Add(newProbe);
                    }
                    m_currentProbeCount++;
                }
            }
#else
            for (int row = 0; row < reflectionProbeData.reflectionProbesPerRow; ++row)
            {
                for (int columns = 0; columns < reflectionProbeData.reflectionProbesPerRow; ++columns)
                {
                    Vector3 newPosition = new Vector3
                    {
                        x = ((columns + 1) * terrainSize.x / reflectionProbeData.reflectionProbesPerRow) - terrainSize.x / reflectionProbeData.reflectionProbesPerRow / 2f + terrain.transform.position.x,
                        z = ((row + 1) * terrainSize.z / reflectionProbeData.reflectionProbesPerRow) - terrainSize.z / reflectionProbeData.reflectionProbesPerRow / 2f + terrain.transform.position.z
                    };
                    Vector3         size     = new Vector3(terrain.terrainData.size.x / reflectionProbeData.reflectionProbesPerRow, terrain.terrainData.size.y, terrain.terrainData.size.z / reflectionProbeData.reflectionProbesPerRow);
                    ReflectionProbe newProbe = ReflectionProbeUtils.CreateReflectionProbe(newPosition, size, terrain, reflectionProbeData, seaLevelActive, seaLevel, reflectionParentObject.transform, renderPipelineSettings == GaiaConstants.EnvironmentRenderer.HighDefinition);
                    m_storedProbes.Add(newProbe);
                    m_currentProbeCount++;
                }
            }
#endif

            EditorGUIUtility.PingObject(reflectionParentObject);
        }
Exemple #2
0
        private static void GenerateProbesOnTerrain(Terrain terrain, ReflectionProbeData profile, float seaLevel)
        {
            GameObject lightProbeObject = GameObject.Find(terrain.name + " Light Probes Group Data");

            if (lightProbeObject == null)
            {
                lightProbeObject = new GameObject(terrain.name + " Light Probes Group Data");
            }

            LightProbeGroup lightProbeData = lightProbeObject.GetComponent <LightProbeGroup>();

            if (lightProbeData == null)
            {
                lightProbeData = lightProbeObject.AddComponent <LightProbeGroup>();
                lightProbeData.probePositions = new Vector3[0];
            }
            GameObject lightParentObject = LightProbeParenting(terrain);
            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)
                {
                    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);

                    if (sampledHeight > seaLevel)
                    {
                        probePositions.Add(newPosition);
                        newPosition += new Vector3(0f, 2.5f, 0f);
                        probePositions.Add(newPosition);
                        newPosition += new Vector3(0f, 10f, 0f);
                        probePositions.Add(newPosition);
                        lightProbeData.probePositions = probePositions.ToArray();
                        m_currentProbeCount++;
                    }
                }
            }

            lightProbeObject.transform.SetParent(lightParentObject.transform);
            EditorGUIUtility.PingObject(lightParentObject);
        }
Exemple #3
0
        /// <summary>
        /// Setup for the automatically probe spawning
        /// </summary>
        /// <param name="profile"></param>
        public static void CreateAutomaticProbes(ReflectionProbeData profile)
        {
            int numberTerrains = Terrain.activeTerrains.Length;

            if (numberTerrains == 0)
            {
                Debug.LogError("Unable to initiate probe spawning systen. No terrain found");
            }
            else
            {
                if (profile.lightProbesPerRow < 2)
                {
                    Debug.LogError("Please set Light Probes Per Row to a value of 2 or higher");
                }
                else
                {
                    LoadProbesFromScene();

                    m_probeLocations = null;
                    ClearCreatedLightProbes();

                    float seaLevel = 0f;

                    PWS_WaterSystem gaiawater = GameObject.FindObjectOfType <PWS_WaterSystem>();
                    if (gaiawater != null)
                    {
                        seaLevel = gaiawater.SeaLevel;
                    }

                    if (GaiaUtils.HasDynamicLoadedTerrains())
                    {
                        Action <Terrain> terrAction = (t) => GenerateProbesOnTerrain(t, profile, seaLevel);
                        GaiaUtils.CallFunctionOnDynamicLoadedTerrains(terrAction, true, null, "Generating Light Probes");
                    }
                    else
                    {
                        foreach (var activeTerrain in Terrain.activeTerrains)
                        {
                            GenerateProbesOnTerrain(activeTerrain, profile, seaLevel);
                        }
                    }
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Setup for the automatically probe spawning
        /// </summary>
        /// <param name="reflectionProbeData"></param>
        public static void CreateAutomaticProbes(ReflectionProbeData reflectionProbeData, GaiaConstants.EnvironmentRenderer renderPipelineSettings)
        {
            if (reflectionProbeData == null)
            {
                return;
            }

            if (reflectionProbeData.reflectionProbeRefresh == GaiaConstants.ReflectionProbeRefreshModePW.ProbeManager && reflectionProbeData.reflectionProbeMode == ReflectionProbeMode.Realtime)
            {
#if GAIA_PRO_PRESENT
                ReflectionProbeManager manager = ReflectionProbeManager.GetOrCreateProbeManager();
                if (manager != null)
                {
                    manager.ProbeLayerMask = reflectionProbeData.reflectionprobeCullingMask;
                }
#endif
            }
            else
            {
#if GAIA_PRO_PRESENT
                ReflectionProbeManager.RemoveReflectionProbeManager();
#endif
            }

            ClearCreatedReflectionProbes();

            GameObject oldReflectionProbe = GameObject.Find("Global Reflection Probe");
            if (oldReflectionProbe != null)
            {
                UnityEngine.Object.DestroyImmediate(oldReflectionProbe);
                Debug.Log("Old Reflection Probe Destroyed");
            }

            if (reflectionProbeData.reflectionProbesPerRow < 2)
            {
                Debug.LogError("Please set Probes Per Row to a value of 2 or higher");
            }
            else
            {
                m_currentProbeCount = 0;

                float seaLevel       = 0f;
                bool  seaLevelActive = false;

                PWS_WaterSystem gaiawater = GameObject.FindObjectOfType <PWS_WaterSystem>();
                if (gaiawater != null)
                {
                    seaLevel       = gaiawater.SeaLevel;
                    seaLevelActive = true;
                }

                if (GaiaUtils.HasDynamicLoadedTerrains())
                {
                    Action <Terrain> terrAction = (t) => GenerateProbesOnTerrain(t, reflectionProbeData, seaLevelActive, seaLevel, renderPipelineSettings);
                    GaiaUtils.CallFunctionOnDynamicLoadedTerrains(terrAction, true, null, "Generating Reflection Probes");
                }
                else
                {
                    if (Terrain.activeTerrains.Length < 1)
                    {
                        Debug.LogError("No terrains we're found, unable to generate reflection probes.");
                    }
                    else
                    {
                        foreach (var activeTerrain in Terrain.activeTerrains)
                        {
                            GenerateProbesOnTerrain(activeTerrain, reflectionProbeData, seaLevelActive, seaLevel, renderPipelineSettings);
                        }
                    }
                }
                m_probeRenderActive = true;
            }
        }
Exemple #5
0
        /// <summary>
        /// Creates a single Reflection Probe in the given position
        /// </summary>
        /// <param name="position"></param>
        /// <param name="terrain"></param>
        /// <param name="reflectionProbeData"></param>
        /// <param name="seaLevelActive"></param>
        /// <param name="seaLevel"></param>
        /// <param name="parentTransform"></param>
        /// <param name="isHDRP"></param>
        /// <returns></returns>
        public static ReflectionProbe CreateReflectionProbe(Vector3 position, Vector3 size, Terrain terrain, ReflectionProbeData reflectionProbeData, bool seaLevelActive, float seaLevel, Transform parentTransform, bool isHDRP, bool probeCulling = false)
        {
            GameObject probeObject = new GameObject("Global Generated Reflection Probe");

            float sampledHeight = terrain.SampleHeight(position);

            ReflectionProbe reflectionProbe = probeObject.AddComponent <ReflectionProbe>();

            reflectionProbe.enabled       = false;
            reflectionProbe.blendDistance = 0f;
            reflectionProbe.cullingMask   = reflectionProbeData.reflectionprobeCullingMask;
            reflectionProbe.farClipPlane  = reflectionProbeData.reflectionProbeClipPlaneDistance;
            reflectionProbe.mode          = reflectionProbeData.reflectionProbeMode;
            switch (reflectionProbeData.reflectionProbeRefresh)
            {
            case GaiaConstants.ReflectionProbeRefreshModePW.OnAwake:
                reflectionProbe.refreshMode = ReflectionProbeRefreshMode.OnAwake;
                break;

            case GaiaConstants.ReflectionProbeRefreshModePW.EveryFrame:
                reflectionProbe.refreshMode = ReflectionProbeRefreshMode.EveryFrame;
                break;

            case GaiaConstants.ReflectionProbeRefreshModePW.ViaScripting:
                reflectionProbe.refreshMode = ReflectionProbeRefreshMode.ViaScripting;
                break;

            case GaiaConstants.ReflectionProbeRefreshModePW.ProbeManager:
                reflectionProbe.refreshMode = ReflectionProbeRefreshMode.ViaScripting;
                break;
            }

            if (!seaLevelActive)
            {
                position.y = 500f + seaLevel + 0.2f;
            }
            else
            {
                position.y             = sampledHeight + reflectionProbeData.reflectionProbeOffset;
                reflectionProbe.center = new Vector3(0f, 0f - reflectionProbeData.reflectionProbeOffset - sampledHeight, 0f);
            }

            if (position.y < seaLevel)
            {
                position.y = seaLevel + reflectionProbeData.reflectionProbeOffset;
            }
            probeObject.transform.position = position;
            probeObject.transform.SetParent(parentTransform);

            switch (reflectionProbeData.reflectionProbeResolution)
            {
            case GaiaConstants.ReflectionProbeResolution.Resolution16:
                reflectionProbe.resolution = 16;
                break;

            case GaiaConstants.ReflectionProbeResolution.Resolution32:
                reflectionProbe.resolution = 32;
                break;

            case GaiaConstants.ReflectionProbeResolution.Resolution64:
                reflectionProbe.resolution = 64;
                break;

            case GaiaConstants.ReflectionProbeResolution.Resolution128:
                reflectionProbe.resolution = 128;
                break;

            case GaiaConstants.ReflectionProbeResolution.Resolution256:
                reflectionProbe.resolution = 256;
                break;

            case GaiaConstants.ReflectionProbeResolution.Resolution512:
                reflectionProbe.resolution = 512;
                break;

            case GaiaConstants.ReflectionProbeResolution.Resolution1024:
                reflectionProbe.resolution = 1024;
                break;

            case GaiaConstants.ReflectionProbeResolution.Resolution2048:
                reflectionProbe.resolution = 2048;
                break;
            }

            reflectionProbe.shadowDistance  = 80f;
            reflectionProbe.size            = size;
            reflectionProbe.timeSlicingMode = reflectionProbeData.reflectionProbeTimeSlicingMode;
            reflectionProbe.hdr             = true;
            reflectionProbe.shadowDistance  = reflectionProbeData.reflectionProbeShadowDistance;

            //If HDRP
            if (isHDRP)
            {
#if HDPipeline
                HDAdditionalReflectionData reflectionData = probeObject.GetComponent <HDAdditionalReflectionData>();
                if (reflectionData == null)
                {
                    reflectionData = probeObject.AddComponent <HDAdditionalReflectionData>();
                }

                reflectionData.multiplier   = 1f;
                reflectionData.realtimeMode = ProbeSettings.RealtimeMode.OnEnable;
#endif
            }

#if GAIA_PRO_PRESENT
            ReflectionProbeCuller culler = reflectionProbe.GetComponent <ReflectionProbeCuller>();
            if (probeCulling)
            {
                if (culler == null)
                {
                    culler         = reflectionProbe.gameObject.AddComponent <ReflectionProbeCuller>();
                    culler.m_probe = reflectionProbe;
                    culler.Initialize();
                }
            }
            else
            {
                if (culler != null)
                {
                    GameObject.DestroyImmediate(culler);
                }
            }
#endif

            return(reflectionProbe);
        }