Texture GetStaticLightingTexture() { StaticLightingSky staticLightingSky = GetStaticLightingSky(); if (staticLightingSky != null) { return(m_StaticLightingSky.IsValid() ? (Texture)m_StaticLightingSkyRenderingContext.cubemapRT : CoreUtils.blackCubeTexture); } else { return(CoreUtils.blackCubeTexture); } }
public void RenderSky(SkyUpdateContext skyContext, HDCamera hdCamera, Light sunLight, RTHandle colorBuffer, RTHandle depthBuffer, DebugDisplaySettings debugSettings, int frameIndex, CommandBuffer cmd) { if (skyContext.IsValid() && hdCamera.clearColorMode == HDAdditionalCameraData.ClearColorMode.Sky) { using (new ProfilingSample(cmd, "Sky Pass")) { m_BuiltinParameters.commandBuffer = cmd; m_BuiltinParameters.sunLight = sunLight; m_BuiltinParameters.pixelCoordToViewDirMatrix = hdCamera.mainViewConstants.pixelCoordToViewDirWS; m_BuiltinParameters.worldSpaceCameraPos = hdCamera.mainViewConstants.worldSpaceCameraPos; m_BuiltinParameters.viewMatrix = hdCamera.mainViewConstants.viewMatrix; m_BuiltinParameters.screenSize = hdCamera.screenSize; m_BuiltinParameters.colorBuffer = colorBuffer; m_BuiltinParameters.depthBuffer = depthBuffer; m_BuiltinParameters.debugSettings = debugSettings; m_BuiltinParameters.frameIndex = frameIndex; m_BuiltinParameters.updateMode = skyContext.skySettings.updateMode.value; skyContext.renderer.SetRenderTargets(m_BuiltinParameters); // If the luxmeter is enabled, we don't render the sky if (debugSettings.data.lightingDebugSettings.debugLightingMode != DebugLightingMode.LuxMeter) { // When rendering the visual sky for reflection probes, we need to remove the sun disk if skySettings.includeSunInBaking is false. skyContext.renderer.RenderSky(m_BuiltinParameters, false, hdCamera.camera.cameraType != CameraType.Reflection || skyContext.skySettings.includeSunInBaking.value); } } } }
SphericalHarmonicsL2 GetAmbientProbe(SkyUpdateContext skyContext) { if (skyContext.IsValid() && IsCachedContextValid(skyContext)) { ref var context = ref m_CachedSkyContexts[skyContext.cachedSkyRenderingContextId]; return(context.renderingContext.ambientProbe); }
public bool IsVisualSkyValid() { return(m_VisualSky.IsValid()); }
public bool IsLightingSkyValid() { return(m_CurrentSky.IsValid()); }
public bool UpdateEnvironment(SkyUpdateContext skyContext, Light sunLight, Vector3 worldSpaceCameraPos, bool updateRequired, bool updateAmbientProbe, int frameIndex, CommandBuffer cmd) { bool result = false; if (skyContext.IsValid()) { skyContext.currentUpdateTime += Time.deltaTime; m_BuiltinParameters.commandBuffer = cmd; m_BuiltinParameters.sunLight = sunLight; m_BuiltinParameters.worldSpaceCameraPos = worldSpaceCameraPos; m_BuiltinParameters.screenSize = m_CubemapScreenSize; m_BuiltinParameters.debugSettings = null; // We don't want any debug when updating the environment. m_BuiltinParameters.frameIndex = frameIndex; m_BuiltinParameters.updateMode = skyContext.skySettings.updateMode.value; int sunHash = 0; if (sunLight != null) { sunHash = GetSunLightHashCode(sunLight); } int skyHash = sunHash * 23 + skyContext.skySettings.GetHashCode(); bool forceUpdate = (updateRequired || skyContext.updatedFramesRequired > 0 || m_NeedUpdate); if (forceUpdate || (skyContext.skySettings.updateMode.value == EnvironmentUpdateMode.OnChanged && skyHash != skyContext.skyParametersHash) || (skyContext.skySettings.updateMode.value == EnvironmentUpdateMode.Realtime && skyContext.currentUpdateTime > skyContext.skySettings.updatePeriod.value)) { using (new ProfilingSample(cmd, "Sky Environment Pass")) { using (new ProfilingSample(cmd, "Update Env: Generate Lighting Cubemap")) { RenderSkyToCubemap(skyContext); if (updateAmbientProbe) { using (new ProfilingSample(cmd, "Update Ambient Probe")) { cmd.SetComputeBufferParam(m_ComputeAmbientProbeCS, m_ComputeAmbientProbeKernel, m_AmbientProbeOutputBufferParam, m_AmbientProbeResult); cmd.SetComputeTextureParam(m_ComputeAmbientProbeCS, m_ComputeAmbientProbeKernel, m_AmbientProbeInputCubemap, m_SkyboxCubemapRT); cmd.DispatchCompute(m_ComputeAmbientProbeCS, m_ComputeAmbientProbeKernel, 1, 1, 1); cmd.RequestAsyncReadback(m_AmbientProbeResult, OnComputeAmbientProbeDone); } } } if (m_SupportsConvolution) { using (new ProfilingSample(cmd, "Update Env: Convolve Lighting Cubemap")) { RenderCubemapGGXConvolution(skyContext); } } result = true; skyContext.skyParametersHash = skyHash; skyContext.currentUpdateTime = 0.0f; skyContext.updatedFramesRequired--; m_NeedUpdate = false; #if UNITY_EDITOR // In the editor when we change the sky we want to make the GI dirty so when baking again the new sky is taken into account. // Changing the hash of the rendertarget allow to say that GI is dirty m_SkyboxCubemapRT.rt.imageContentsHash = new Hash128((uint)skyContext.skySettings.GetHashCode(), 0, 0, 0); #endif } } } else { if (skyContext.skyParametersHash != 0) { using (new ProfilingSample(cmd, "Clear Sky Environment Pass")) { CoreUtils.ClearCubemap(cmd, m_SkyboxCubemapRT, Color.black, true); if (m_SupportsConvolution) { CoreUtils.ClearCubemap(cmd, m_SkyboxBSDFCubemapIntermediate, Color.black, true); for (int bsdfIdx = 0; bsdfIdx < m_IBLFilterArray.Length; ++bsdfIdx) { for (int face = 0; face < 6; ++face) { cmd.CopyTexture(m_SkyboxBSDFCubemapIntermediate, face, m_SkyboxBSDFCubemapArray, 6 * bsdfIdx + face); } } } } skyContext.skyParametersHash = 0; result = true; } } return(result); }