Ejemplo n.º 1
0
        public void Deregister()
        {
            DS_HazeCore core = DS_HazeCore.Instance;

            if (core != null)
            {
                core.RemoveLightVolume(this);
            }
        }
Ejemplo n.º 2
0
        public void Deregister()
        {
            DS_HazeCore instance = DS_HazeCore.Instance;

            if (!Object.op_Inequality((Object)instance, (Object)null))
            {
                return;
            }
            instance.RemoveLightVolume(this);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// On Awake we need to check there is only one Haze Controller in the scene and
 /// set up the singleton reference to it.
 /// </summary>
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else if (instance != this)
     {
         Debug.LogError("DeepSky::DS_HazeCore:Awake - There is more than one Haze Controller in this scene! Disabling " + name);
         enabled = false;
     }
 }
Ejemplo n.º 4
0
        public void Register()
        {
            DS_HazeCore instance = DS_HazeCore.Instance;

            if (Object.op_Equality((Object)instance, (Object)null))
            {
                Debug.LogError((object)"DeepSky::DS_HazeLightVolume: Attempting to add a light volume but no HS_HazeCore found in scene! Please make sure there is a DS_HazeCore object.");
            }
            else
            {
                instance.AddLightVolume(this);
            }
        }
Ejemplo n.º 5
0
        public void Register()
        {
            DS_HazeCore core = DS_HazeCore.Instance;

            if (core == null)
            {
                Debug.LogError("DeepSky::DS_HazeLightVolume: Attempting to add a light volume but no HS_HazeCore found in scene! Please make sure there is a DS_HazeCore object.");
            }
            else
            {
                core.AddLightVolume(this);
            }
        }
Ejemplo n.º 6
0
        public static void CreateDeepSkyHazeZone()
        {
            GameObject zone = new GameObject("DS_HazeZone", typeof(DS_HazeZone));

            zone.transform.localScale = new Vector3(100, 50, 100);

            DS_HazeCore core = DS_HazeCore.Instance;

            if (core != null)
            {
                zone.transform.SetParent(core.transform);
            }

            Selection.objects = new Object[] { zone };
        }
Ejemplo n.º 7
0
 private void Awake()
 {
     if (Object.op_Equality((Object)DS_HazeCore.instance, (Object)null))
     {
         DS_HazeCore.instance = this;
     }
     else
     {
         if (!Object.op_Inequality((Object)DS_HazeCore.instance, (Object)this))
         {
             return;
         }
         Debug.LogError((object)("DeepSky::DS_HazeCore:Awake - There is more than one Haze Controller in this scene! Disabling " + ((Object)this).get_name()));
         ((Behaviour)this).set_enabled(false);
     }
 }
Ejemplo n.º 8
0
        public static void CreateDeepSkyHazeController()
        {
            DS_HazeCore core = DS_HazeCore.Instance;
            GameObject  cont;

            if (core == null)
            {
                cont = new GameObject("DS_HazeController", typeof(DS_HazeCore));
                cont.transform.position = new Vector3(0, 0, 0);
            }
            else
            {
                cont = core.gameObject;
                Debug.LogWarning("DeepSky::CreateDeepSkyHazeController - there is already a Haze Controller in this scene!");
            }

            Selection.objects = new Object[] { cont };
        }
Ejemplo n.º 9
0
        private void OnPreRender()
        {
            if (!this.CheckHasSystemSupport())
            {
                ((Behaviour)this).set_enabled(false);
            }
            this.UpdateResources();
            this.SetShaderKeyWords();
            this.m_PerFrameRadianceTarget = RenderTexture.GetTemporary(this.m_X, this.m_Y, 0, !this.m_Camera.get_allowHDR() ? (RenderTextureFormat)0 : (RenderTextureFormat)2, (RenderTextureReadWrite)1, this.AntiAliasingLevel());
            ((Object)this.m_PerFrameRadianceTarget).set_name("_DS_Haze_PerFrameRadiance");
            ((Texture)this.m_PerFrameRadianceTarget).set_filterMode((FilterMode)0);
            this.m_ClearRadianceCmdBuffer.Clear();
            this.m_ClearRadianceCmdBuffer.SetRenderTarget(RenderTargetIdentifier.op_Implicit((Texture)this.m_PerFrameRadianceTarget));
            this.m_ClearRadianceCmdBuffer.ClearRenderTarget(false, true, Color.get_clear());
            DS_HazeCore        instance = DS_HazeCore.Instance;
            DS_HazeContextItem ctx;

            if (this.m_OverrideContextAsset && Object.op_Inequality((Object)this.m_Context, (Object)null))
            {
                ctx = !this.m_OverrideContextVariant ? this.m_Context.Context.GetContextItemBlended(this.m_Time) : this.m_Context.Context.GetItemAtIndex(this.m_ContextItemIndex);
            }
            else
            {
                if (Object.op_Equality((Object)instance, (Object)null))
                {
                    this.SetGlobalParamsToNull();
                    return;
                }
                ctx = instance.GetRenderContextAtPosition(((Component)this).get_transform().get_position());
            }
            if (ctx == null)
            {
                this.SetGlobalParamsToNull();
            }
            else
            {
                this.SetMaterialFromContext(ctx);
                float   farClipPlane = this.m_Camera.get_farClipPlane();
                float   num1         = Mathf.Tan(this.m_Camera.get_fieldOfView() * 0.5f * ((float)Math.PI / 180f));
                float   num2         = num1 * this.m_Camera.get_aspect();
                Vector3 vector3_1    = Vector3.op_Multiply(((Component)this).get_transform().get_forward(), farClipPlane);
                Vector3 vector3_2    = Vector3.op_Multiply(Vector3.op_Multiply(((Component)this).get_transform().get_right(), num2), farClipPlane);
                Vector3 vector3_3    = Vector3.op_Multiply(Vector3.op_Multiply(((Component)this).get_transform().get_up(), num1), farClipPlane);
                this.m_Material.SetVector("_ViewportCorner", Vector4.op_Implicit(Vector3.op_Subtraction(Vector3.op_Subtraction(vector3_1, vector3_2), vector3_3)));
                this.m_Material.SetVector("_ViewportRight", Vector4.op_Implicit(Vector3.op_Multiply(vector3_2, 2f)));
                this.m_Material.SetVector("_ViewportUp", Vector4.op_Implicit(Vector3.op_Multiply(vector3_3, 2f)));
                if (Object.op_Implicit((Object)this.m_DirectLight) && this.m_RenderAtmosphereVolumetrics)
                {
                    this.m_DirectionalLightCmdBuffer.Blit(RenderTargetIdentifier.op_Implicit((BuiltinRenderTextureType)0), RenderTargetIdentifier.op_Implicit((Texture)this.m_PerFrameRadianceTarget), this.m_Material, (int)(this.m_VolumeSamples + (this.m_DownsampleFactor != DS_HazeView.SizeFactor.Half ? 3 : 0)));
                }
            }
            if (!this.m_RenderLocalVolumetrics)
            {
                return;
            }
            Matrix4x4 viewProjMtx = Matrix4x4.op_Multiply(GL.GetGPUProjectionMatrix(this.m_Camera.get_projectionMatrix(), true), this.m_Camera.get_worldToCameraMatrix());

            instance.GetRenderLightVolumes(((Component)this).get_transform().get_position(), this.m_PerFrameLightVolumes, this.m_PerFrameShadowLightVolumes);
            if (this.m_PerFrameLightVolumes.Count > 0)
            {
                this.m_RenderNonShadowVolumes.SetRenderTarget(RenderTargetIdentifier.op_Implicit((Texture)this.m_PerFrameRadianceTarget));
            }
            foreach (DS_HazeLightVolume frameLightVolume in this.m_PerFrameLightVolumes)
            {
                frameLightVolume.SetupMaterialPerFrame(viewProjMtx, this.m_Camera.get_worldToCameraMatrix(), ((Component)this).get_transform(), !this.WillRenderWithTemporalReprojection ? 0.0f : this.m_InterleavedOffsetIndex);
                frameLightVolume.AddLightRenderCommand(((Component)this).get_transform(), this.m_RenderNonShadowVolumes, (int)this.m_DownsampleFactor);
            }
            foreach (DS_HazeLightVolume shadowLightVolume in this.m_PerFrameShadowLightVolumes)
            {
                shadowLightVolume.SetupMaterialPerFrame(viewProjMtx, this.m_Camera.get_worldToCameraMatrix(), ((Component)this).get_transform(), !this.WillRenderWithTemporalReprojection ? 0.0f : this.m_InterleavedOffsetIndex);
                shadowLightVolume.FillLightCommandBuffer(this.m_PerFrameRadianceTarget, ((Component)this).get_transform(), (int)this.m_DownsampleFactor);
                this.m_LightVolumeCmdBuffers.Add(shadowLightVolume.LightSource, shadowLightVolume.RenderCommandBuffer);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Create the Controller, Zone and View needed to see DeepSky effects, fitting
        /// the zone around the passed terrain or object (if supplied) and applying the
        /// selected preset.
        /// </summary>
        /// <param name="boundsObject"> The Zone will be scaled to surround this object/terrain. </param>
        /// <param name="presetPath"> Asset path to preset Context to load settings from. </param>
        private void AddQuickSetupToScene(GameObject boundsObject, string presetPath)
        {
            DS_HazeCore core = DS_HazeCore.Instance;
            GameObject  cont;

            if (core == null)
            {
                cont = new GameObject("DS_HazeController", typeof(DS_HazeCore));
                cont.transform.position = new Vector3(0, 0, 0);
            }
            else
            {
                cont = core.gameObject;
                Debug.Log("DeepSky::AddQuickSetupToScene - There is already a Haze Controller in this scene! Skipping adding a new one.");
            }

            GameObject          zone     = new GameObject("DS_HazeZone", typeof(DS_HazeZone));
            DS_HazeContextAsset ctxAsset = AssetDatabase.LoadAssetAtPath <DS_HazeContextAsset>(presetPath);

            if (ctxAsset == null)
            {
                Debug.LogWarning("DeepSky::AddQuickSetupToScene - Unable to load preset " + presetPath);
            }
            else
            {
                DS_HazeZone zoneComp = zone.GetComponent <DS_HazeZone>();
                DS_HazeZoneEditor.SetZoneFromContextPreset(zoneComp, ctxAsset);
            }

            Vector3 zoneSize     = new Vector3(250, 100, 250);
            Vector3 zoneLocation = Vector3.zero;

            if (boundsObject)
            {
                zoneLocation = boundsObject.transform.position;

                bool    useDefault = false;
                Vector3 objSize    = zoneSize;

                Terrain ter = boundsObject.GetComponent <Terrain>();
                if (ter)
                {
                    // This is a terrain, get the size from the terrain data and scale zone to default inner blend zone.
                    objSize       = ter.terrainData.size;
                    zoneLocation += ter.terrainData.size * 0.5f;
                }
                else
                {
                    // Normal object, fit to mesh renderer bounds (if there is a mesh renderer).
                    MeshRenderer mr = boundsObject.GetComponent <MeshRenderer>();
                    if (mr)
                    {
                        objSize      = mr.bounds.size;
                        zoneLocation = mr.bounds.center;
                    }
                    else
                    {
                        Debug.Log("DeepSky::AddQuickSetupToScene - Supplied object has no Mesh Renderer to get bounds from! Using default size.");
                        useDefault = true;
                    }
                }

                if (!useDefault)
                {
                    // Make sure there is at least some size.
                    if (objSize.x < 10)
                    {
                        objSize.x = 10;
                    }
                    if (objSize.y < 10)
                    {
                        objSize.y = 10;
                    }
                    if (objSize.z < 10)
                    {
                        objSize.z = 10;
                    }

                    zoneSize = objSize;
                    float   dT    = Mathf.Min(zoneSize.x, zoneSize.y, zoneSize.z) * 0.1f;
                    Vector3 scale = new Vector3(zoneSize.x / (zoneSize.x - dT), zoneSize.y / (zoneSize.y - dT), zoneSize.z / (zoneSize.z - dT));
                    zoneSize.Scale(scale);
                    zoneSize.y += objSize.y * 0.1f; // Scale up by 10% in Y to give a little extra room at the top/bottom of the terrain/mesh.
                }
            }
            zone.transform.localScale = zoneSize;
            zone.transform.position   = zoneLocation;
            zone.transform.SetParent(cont.transform);

            DS_HazeView view = m_Camera.GetComponent <DS_HazeView>();

            if (view)
            {
                Debug.Log("DeepSky::AddQuickSetupToScene - The camera already has a Haze View! Skipping adding a new one.");
                return;
            }
            else
            {
                view             = m_Camera.gameObject.AddComponent <DS_HazeView>();
                view.DirectLight = m_DirectionalLight;
            }
        }