SphericalHarmonicsL2 GetStaticLightingAmbientProbe() { StaticLightingSky staticLightingSky = GetStaticLightingSky(); if (staticLightingSky != null) { return(m_StaticLightingSky.IsValid() ? m_StaticLightingSkyRenderingContext.ambientProbe : m_BlackAmbientProbe); } else { return(m_BlackAmbientProbe); } }
Texture GetStaticLightingTexture() { StaticLightingSky staticLightingSky = GetStaticLightingSky(); if (staticLightingSky != null) { return(m_StaticLightingSky.IsValid() ? (Texture)m_StaticLightingSkyRenderingContext.cubemapRT : CoreUtils.blackCubeTexture); } else { return(CoreUtils.blackCubeTexture); } }
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."); } if (staticLightingSky.staticLightingSkyUniqueID == (int)SkyType.Procedural && !skyTypesDict.TryGetValue((int)SkyType.Procedural, out var dummy)) { Debug.LogError("You are using the deprecated Procedural Sky for static lighting in your Scene. You can still use it but, to do so, you must install it separately. To do this, open the Package Manager window and import the 'Procedural Sky' sample from the HDRP package page, then close and re-open your project without saving."); return; } m_StaticLightingSkies.Add(staticLightingSky); } }
static public void UnRegisterStaticLightingSky(StaticLightingSky staticLightingSky) { m_StaticLightingSkies.Remove(staticLightingSky); }
public void UpdateEnvironment(HDCamera hdCamera, Light sunLight, int frameIndex, CommandBuffer cmd) { 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_CurrentSkyRenderingContext.UpdateEnvironment(hdCamera, m_CurrentSky, sunLight, hdCamera.mainViewConstants.worldSpaceCameraPos, m_UpdateRequired, ambientMode == SkyAmbientMode.Dynamic, frameIndex, 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(hdCamera, m_StaticLightingSky, sunLight, hdCamera.mainViewConstants.worldSpaceCameraPos, false, true, frameIndex, 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_CurrentSkyRenderingContext.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_CurrentSkyRenderingContext.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); } }