/// <summary>
    /// Creates a Clouds Layer for Enviro.
    /// </summary>
    public void CreateCloudLayer()
    {
        //Pick colour of main light
        Color mainLightColor = Color.white;

        mainLightColor = EnviroSkyMgr.instance.Components.DirectLight.GetComponent <Light>().color;

        //Get the main camera
        Camera mainCamera = Camera.main;

        //First make sure its not already in scene - if it isnt then add it
        FogVolume  fVolume;
        GameObject goClouds = GameObject.Find("Fog Volume [Clouds] for Enviro");

        if (goClouds == null)
        {
            goClouds      = new GameObject();
            goClouds.name = "Fog Volume [Clouds] for Enviro";
            Renderer rend = goClouds.AddComponent <MeshRenderer>();
            if (rend != null)
            {
                rend.shadowCastingMode    = UnityEngine.Rendering.ShadowCastingMode.Off;
                rend.receiveShadows       = false;
                rend.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off;
                rend.lightProbeUsage      = UnityEngine.Rendering.LightProbeUsage.Off;
            }
            fVolume = goClouds.AddComponent <FogVolume>();
            //Create the horizon
            GameObject goHorizon = GameObject.CreatePrimitive(PrimitiveType.Plane);
            goHorizon.name                    = "Horizon";
            goHorizon.transform.parent        = goClouds.transform;
            goHorizon.transform.localPosition = new Vector3(0f, -79f, 0f);
            goHorizon.GetComponent <MeshRenderer>().enabled = false;
            goHorizon.GetComponent <MeshCollider>().enabled = false;

            //Create the priority script
            FogVolumePriority fogVolumePrio = goClouds.AddComponent <FogVolumePriority>();
            fogVolumePrio.GameCamera          = mainCamera;
            fogVolumePrio.FogOrderCameraAbove = 4;
            fogVolumePrio.FogOrderCameraBelow = -1;
            fogVolumePrio.thisFog             = fVolume;
            fogVolumePrio.Horizon             = goHorizon;

            CheckCamera();
        }

        //Setup our clouds
        fVolume = goClouds.GetComponent <FogVolume>();

        if (fVolume != null)
        {
            clouds = fVolume;

            //Location and scale
            fVolume.transform.position = cloudsPosition;
            fVolume.fogVolumeScale     = new Vector3(EnviroSkyMgr.instance.Camera.farClipPlane - 50f, 100f, EnviroSkyMgr.instance.Camera.farClipPlane - 50f);

            //Fog type and blend mode
            fVolume._FogType   = FogVolume.FogType.Textured;
            fVolume._BlendMode = FogVolumeRenderer.BlendMode.TraditionalTransparency;

            //Lighting
            fVolume._AmbientColor     = Color.Lerp(mainLightColor, Color.black, 0.1f);
            fVolume.useHeightGradient = true;
            fVolume.Absorption        = 0.8f;
            fVolume.HeightAbsorption  = 0.185f;
            fVolume.bAbsorption       = true;

            fVolume.EnableInscattering             = true;
            fVolume.InscatteringColor              = mainLightColor;
            fVolume.InscatteringShape              = 0.05f;
            fVolume.InscatteringIntensity          = 0.882f;
            fVolume.InscatteringStartDistance      = 0f;
            fVolume.InscatteringTransitionWideness = 1f;

            fVolume._DirectionalLighting         = true;
            fVolume.LightExtinctionColor         = Color.Lerp(mainLightColor, Color.black, 0.8f);
            fVolume._DirectionalLightingDistance = 0.0008f;
            fVolume.DirectLightingShadowDensity  = 6f;
            fVolume.DirectLightingShadowSteps    = 1;

            //Renderer
            fVolume.NoiseIntensity      = 1f;
            fVolume.SceneCollision      = true;
            fVolume.Iterations          = 500;
            fVolume.IterationStep       = 100;
            fVolume._OptimizationFactor = 0.0000005f;

            fVolume.GradMin  = 0.19f;
            fVolume.GradMax  = 0.06f;
            fVolume.GradMin2 = -0.25f;
            fVolume.GradMax2 = 0.21f;

            //Noise
            fVolume.EnableNoise             = true;
            fVolume._3DNoiseScale           = 0.15f;
            fVolume.Speed                   = new Vector4(0.49f, 0f, 0f, 0f);
            fVolume.Vortex                  = 0.47f;
            fVolume.RotationSpeed           = 0f;
            fVolume.rotation                = 324f;
            fVolume._VortexAxis             = FogVolume.VortexAxis.Y;
            fVolume.Coverage                = 2.44f;
            fVolume.NoiseContrast           = 12.9f;
            fVolume.NoiseDensity            = 0.2f;
            fVolume.Octaves                 = 3;
            fVolume.BaseTiling              = 150f;
            fVolume._BaseRelativeSpeed      = 0.85f;
            fVolume.DetailTiling            = 285.3f;
            fVolume._DetailRelativeSpeed    = 16.6f;
            fVolume.DetailDistance          = 5000f;
            fVolume._NoiseDetailRange       = 0.337f;
            fVolume._DetailMaskingThreshold = 8f;
            fVolume._Curl                   = 0.364f;

            //Other
            fVolume.DrawOrder  = 4;
            fVolume._PushAlpha = 1.5f;
            fVolume._ztest     = UnityEngine.Rendering.CompareFunction.LessEqual;

            if (fogMode != CurrentFogMode.Textured)
            {
                fVolume.CreateSurrogate = true;
            }
            else
            {
                fVolume.CreateSurrogate = false;
            }

            CheckCamera();
        }
    }
Exemplo n.º 2
0
        public static void GX_Setup_AddClouds()
        {
            //Pick colour of main light
            Color      mainLightColor = Color.white;
            GameObject goLight        = GameObject.Find("Directional Light");
            Light      mainLight;

            if (goLight != null)
            {
                mainLight = goLight.GetComponent <Light>();
            }
            else
            {
                mainLight = GameObject.FindObjectOfType <Light>();
            }
            if (mainLight != null)
            {
                mainLightColor = mainLight.color;
            }

            //Get the main camera
            Camera mainCamera = Camera.main;

            //First make sure its not already in scene - if it isnt then add it
            FogVolume  fvVolume;
            GameObject goClouds = GameObject.Find("Fog Volume [Clouds]");

            if (goClouds == null)
            {
                goClouds      = new GameObject();
                goClouds.name = "Fog Volume [Clouds]";
                goClouds.AddComponent <MeshRenderer>();
                fvVolume = goClouds.AddComponent <FogVolume>();
                goClouds.GetComponent <Renderer>().shadowCastingMode    = UnityEngine.Rendering.ShadowCastingMode.Off;
                goClouds.GetComponent <Renderer>().receiveShadows       = false;
                goClouds.GetComponent <Renderer>().reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off;
                goClouds.GetComponent <Renderer>().lightProbeUsage      = UnityEngine.Rendering.LightProbeUsage.Off;

                //Create the horizon
                GameObject goHorizon = GameObject.CreatePrimitive(PrimitiveType.Plane);
                goHorizon.name                    = "Horizon";
                goHorizon.transform.parent        = goClouds.transform;
                goHorizon.transform.localPosition = new Vector3(0f, -79f, 0f);
                goHorizon.GetComponent <MeshRenderer>().enabled = false;
                goHorizon.GetComponent <MeshCollider>().enabled = false;


                //Create the priority script
                FogVolumePriority fvPriority = goClouds.AddComponent <FogVolumePriority>();
                fvPriority.GameCamera          = mainCamera;
                fvPriority.FogOrderCameraAbove = 4;
                fvPriority.FogOrderCameraBelow = -1;
                fvPriority.thisFog             = fvVolume;
                fvPriority.Horizon             = goHorizon;
            }

            //Adjust its position and size
            fvVolume = goClouds.GetComponent <FogVolume>();
            if (fvVolume != null)
            {
                GaiaSceneInfo info = GaiaSceneInfo.GetSceneInfo();

                //Location and scale
                fvVolume.transform.position = new Vector3(info.m_sceneBounds.center.x, info.m_seaLevel + 200f, info.m_sceneBounds.center.z);//   info.m_sceneBounds.center;
                fvVolume.fogVolumeScale     = new Vector3(info.m_sceneBounds.size.x * 3, 100f, info.m_sceneBounds.size.z * 3);

                //Camera far clip
                float maxClip = Math.Max(info.m_sceneBounds.size.x, info.m_sceneBounds.size.z) * 3f;
                if (mainCamera != null)
                {
                    if (mainCamera.farClipPlane < maxClip)
                    {
                        mainCamera.farClipPlane = maxClip + 200f;
                    }
                }

                //Fog type and blend mode
                fvVolume._FogType   = FogVolume.FogType.Textured;
                fvVolume._BlendMode = FogVolumeRenderer.BlendMode.PremultipliedTransparency;

                //Lighting
                fvVolume._AmbientColor     = Color.Lerp(mainLightColor, Color.black, 0.1f);
                fvVolume.useHeightGradient = true;
                fvVolume.Absorption        = 0.8f;
                fvVolume.HeightAbsorption  = 0.185f;
                fvVolume.bAbsorption       = true;

                fvVolume.EnableInscattering             = true;
                fvVolume.InscatteringColor              = mainLightColor;
                fvVolume.InscatteringShape              = 0.05f;
                fvVolume.InscatteringIntensity          = 0.882f;
                fvVolume.InscatteringStartDistance      = 0f;
                fvVolume.InscatteringTransitionWideness = 1f;

                fvVolume._DirectionalLighting         = true;
                fvVolume.LightExtinctionColor         = Color.Lerp(mainLightColor, Color.black, 0.8f);
                fvVolume._DirectionalLightingDistance = 0.0008f;
                fvVolume.DirectLightingShadowDensity  = 6f;
                fvVolume.DirectLightingShadowSteps    = 1;

                //Renderer
                fvVolume.NoiseIntensity      = 1f;
                fvVolume.SceneCollision      = false; //Faster i suppose ?
                fvVolume.Iterations          = 500;
                fvVolume.IterationStep       = 100;
                fvVolume._OptimizationFactor = 0.0000005f;

                fvVolume.GradMin  = 0.19f;
                fvVolume.GradMax  = 0.06f;
                fvVolume.GradMin2 = -0.25f;
                fvVolume.GradMax2 = 0.21f;

                //Noise
                fvVolume.EnableNoise             = true;
                fvVolume._3DNoiseScale           = 0.15f;
                fvVolume.Speed                   = new Vector4(0.49f, 0f, 0f, 0f);
                fvVolume.Vortex                  = 0.47f;
                fvVolume.RotationSpeed           = 0f;
                fvVolume.rotation                = 324f;
                fvVolume._VortexAxis             = FogVolume.VortexAxis.Y;
                fvVolume.Coverage                = 2.44f;
                fvVolume.NoiseContrast           = 12.9f;
                fvVolume.NoiseDensity            = 0.2f;
                fvVolume.Octaves                 = 3;
                fvVolume.BaseTiling              = 150f;
                fvVolume._BaseRelativeSpeed      = 0.85f;
                fvVolume.DetailTiling            = 285.3f;
                fvVolume._DetailRelativeSpeed    = 16.6f;
                fvVolume.DetailDistance          = 5000f;
                fvVolume._NoiseDetailRange       = 0.337f;
                fvVolume._DetailMaskingThreshold = 8f;
                fvVolume._Curl                   = 0.364f;

                //Other
                fvVolume.DrawOrder       = 4;
                fvVolume._ztest          = CompareFunction.LessEqual;
                fvVolume.CreateSurrogate = true;
            }
        }