Example #1
0
 static public void RegisterStaticLightingSky(StaticLightingSky staticLightingSky)
 {
     if (!m_StaticLightingSkies.Contains(staticLightingSky))
     {
         if (m_StaticLightingSkies.Count != 0)
         {
             Debug.LogWarning("One Static Lighting Sky component was already set for baking, only the latest one will be used.");
         }
         m_StaticLightingSkies.Add(staticLightingSky);
     }
 }
Example #2
0
        SphericalHarmonicsL2 GetStaticLightingAmbientProbe()
        {
            StaticLightingSky staticLightingSky = GetStaticLightingSky();

            if (staticLightingSky != null)
            {
                return(m_StaticLightingSky.IsValid() ? m_StaticLightingSkyRenderingContext.ambientProbe : m_BlackAmbientProbe);
            }
            else
            {
                return(m_BlackAmbientProbe);
            }
        }
Example #3
0
        Texture GetStaticLightingTexture()
        {
            StaticLightingSky staticLightingSky = GetStaticLightingSky();

            if (staticLightingSky != null)
            {
                return(m_StaticLightingSky.IsValid() ? (Texture)m_StaticLightingSkyRenderingContext.cubemapRT : CoreUtils.blackCubeTexture);
            }
            else
            {
                return(CoreUtils.blackCubeTexture);
            }
        }
Example #4
0
        protected void OnEnable()
        {
            InitializeProperties();

            if (m_VolumeProfile.objectReferenceValue == null)
            {
                StaticLightingSky staticLightingSky = (StaticLightingSky)target;
                Volume            volume            = staticLightingSky.GetComponent <Volume>();
                if (volume != null)
                {
                    staticLightingSky.profile = volume.sharedProfile;
                }
            }
        }
Example #5
0
 static public void UnRegisterStaticLightingSky(StaticLightingSky staticLightingSky)
 {
     m_StaticLightingSkies.Remove(staticLightingSky);
 }
Example #6
0
        public void UpdateEnvironment(HDCamera hdCamera, Light sunLight, CommandBuffer cmd)
        {
            // WORKAROUND for building the player.
            // When building the player, for some reason we end up in a state where frameCount is not updated but all currently setup shader texture are reset to null
            // resulting in a rendering error (compute shader property not bound) that makes the player building fails...
            // So we just check if the texture is bound here so that we can setup a pink one to avoid the error without breaking half the world.
            if (Shader.GetGlobalTexture(HDShaderIDs._SkyTexture) == null)
            {
                cmd.SetGlobalTexture(HDShaderIDs._SkyTexture, CoreUtils.magentaCubeTexture);
            }

            bool isRegularPreview = HDUtils.IsRegularPreviewCamera(hdCamera.camera);

            SkyAmbientMode ambientMode = VolumeManager.instance.stack.GetComponent <VisualEnvironment>().skyAmbientMode.value;

            // Preview should never use dynamic ambient or they will conflict with main view (async readback of sky texture will update ambient probe for main view one frame later)
            if (isRegularPreview)
            {
                ambientMode = SkyAmbientMode.Static;
            }

            m_SkyRenderingContext.UpdateEnvironment(m_CurrentSky, hdCamera, sunLight, m_UpdateRequired, ambientMode == SkyAmbientMode.Dynamic, cmd);
            StaticLightingSky staticLightingSky = GetStaticLightingSky();

            // We don't want to update the static sky during preview because it contains custom lights that may change the result.
            // The consequence is that previews will use main scene static lighting but we consider this to be acceptable.
            if (staticLightingSky != null && !isRegularPreview)
            {
                m_StaticLightingSky.skySettings = staticLightingSky.skySettings;
                m_StaticLightingSkyRenderingContext.UpdateEnvironment(m_StaticLightingSky, hdCamera, sunLight, false, true, cmd);
            }

            bool useRealtimeGI = true;

#if UNITY_EDITOR
            useRealtimeGI = UnityEditor.Lightmapping.realtimeGI;
#endif
            // Working around GI current system
            // When using baked lighting, setting up the ambient probe should be sufficient => We only need to update RenderSettings.ambientProbe with either the static or visual sky ambient probe (computed from GPU)
            // When using real time GI. Enlighten will pull sky information from Skybox material. So in order for dynamic GI to work, we update the skybox material texture and then set the ambient mode to SkyBox
            // Problem: We can't check at runtime if realtime GI is enabled so we need to take extra care (see useRealtimeGI usage below)
            RenderSettings.ambientMode = AmbientMode.Custom; // Needed to specify ourselves the ambient probe (this will update internal ambient probe data passed to shaders)
            if (ambientMode == SkyAmbientMode.Static)
            {
                RenderSettings.ambientProbe = GetStaticLightingAmbientProbe();
                m_StandardSkyboxMaterial.SetTexture("_Tex", GetStaticLightingTexture());
            }
            else
            {
                RenderSettings.ambientProbe = m_SkyRenderingContext.ambientProbe;
                // Workaround in the editor:
                // When in the editor, if we use baked lighting, we need to setup the skybox material with the static lighting texture otherwise when baking, the dynamic texture will be used
                if (useRealtimeGI)
                {
                    m_StandardSkyboxMaterial.SetTexture("_Tex", m_CurrentSky.IsValid() ? (Texture)m_SkyRenderingContext.cubemapRT : CoreUtils.blackCubeTexture);
                }
                else
                {
                    m_StandardSkyboxMaterial.SetTexture("_Tex", GetStaticLightingTexture());
                }
            }

            // This is only needed if we use realtime GI otherwise enlighten won't get the right sky information
            RenderSettings.skybox              = m_StandardSkyboxMaterial; // Setup this material as the default to be use in RenderSettings
            RenderSettings.ambientIntensity    = 1.0f;
            RenderSettings.ambientMode         = AmbientMode.Skybox;       // Force skybox for our HDRI
            RenderSettings.reflectionIntensity = 1.0f;
            RenderSettings.customReflection    = null;

            m_UpdateRequired = false;

            SetGlobalSkyTexture(cmd);
            if (IsLightingSkyValid())
            {
                cmd.SetGlobalInt(HDShaderIDs._EnvLightSkyEnabled, 1);
            }
            else
            {
                cmd.SetGlobalInt(HDShaderIDs._EnvLightSkyEnabled, 0);
            }
        }