void RenderSkyToCubemap(SkyUpdateContext skyContext) { for (int i = 0; i < 6; ++i) { m_BuiltinParameters.pixelCoordToViewDirMatrix = m_facePixelCoordToViewDirMatrices[i]; m_BuiltinParameters.colorBuffer = m_SkyboxCubemapRT; m_BuiltinParameters.depthBuffer = null; m_BuiltinParameters.hdCamera = null; CoreUtils.SetRenderTarget(m_BuiltinParameters.commandBuffer, m_SkyboxCubemapRT, ClearFlag.None, 0, (CubemapFace)i); skyContext.renderer.RenderSky(m_BuiltinParameters, true, skyContext.skySettings.includeSunInBaking.value); } // Generate mipmap for our cubemap Debug.Assert(m_SkyboxCubemapRT.rt.autoGenerateMips == false); HDRenderPipeline.RT_GenerateMips(m_BuiltinParameters.commandBuffer, m_SkyboxCubemapRT); }
Texture[] ConvolveProbeTexture(CommandBuffer cmd, Texture texture) { // Probes can be either Cubemaps (for baked probes) or RenderTextures (for realtime probes) Cubemap cubeTexture = texture as Cubemap; RenderTexture renderTexture = texture as RenderTexture; RenderTexture convolutionSourceTexture = null; if (cubeTexture != null) { // if the size if different from the cache probe size or if the input texture format is compressed, we need to convert it // 1) to a format for which we can generate mip maps // 2) to the proper reflection probe cache size bool sizeMismatch = cubeTexture.width != m_ProbeSize || cubeTexture.height != m_ProbeSize; bool formatMismatch = cubeTexture.format != TextureFormat.RGBAHalf; // Temporary RT for convolution is always FP16 if (formatMismatch || sizeMismatch) { // We comment the following warning as they have no impact on the result but spam the console, it is just that we waste offline time and a bit of quality for nothing. if (sizeMismatch) { // Debug.LogWarningFormat("Baked Reflection Probe {0} does not match HDRP Reflection Probe Cache size of {1}. Consider baking it at the same size for better loading performance.", texture.name, m_ProbeSize); } else if (cubeTexture.format == TextureFormat.BC6H) { // Debug.LogWarningFormat("Baked Reflection Probe {0} is compressed but the HDRP Reflection Probe Cache is not. Consider removing compression from the input texture for better quality.", texture.name); } ConvertTexture(cmd, cubeTexture, m_TempRenderTexture); } else { for (int f = 0; f < 6; f++) { cmd.CopyTexture(cubeTexture, f, 0, m_TempRenderTexture, f, 0); } } // Ideally if input is not compressed and has mipmaps, don't do anything here. Problem is, we can't know if mips have been already convolved offline... //cmd.GenerateMips(m_TempRenderTexture); HDRenderPipeline.RT_GenerateMips(cmd, m_TempRenderTexture); convolutionSourceTexture = m_TempRenderTexture; } else { Debug.Assert(renderTexture != null); if (renderTexture.dimension != TextureDimension.Cube) { Debug.LogError("Realtime reflection probe should always be a Cube RenderTexture."); return(null); } // TODO: Do a different case for downsizing, in this case, instead of doing ConvertTexture just use the relevant mipmaps. bool sizeMismatch = renderTexture.width != m_ProbeSize || renderTexture.height != m_ProbeSize; if (sizeMismatch) { ConvertTexture(cmd, renderTexture, m_TempRenderTexture); convolutionSourceTexture = m_TempRenderTexture; } else { convolutionSourceTexture = renderTexture; } // Generate unfiltered mipmaps as a base for convolution // TODO: Make sure that we don't first convolve everything on the GPU with the legacy code path executed after rendering the probe. HDRenderPipeline.RT_GenerateMips(cmd, convolutionSourceTexture); //cmd.GenerateMips(convolutionSourceTexture); } for (int bsdfIdx = 0; bsdfIdx < m_IBLFilterBSDF.Length; ++bsdfIdx) { m_IBLFilterBSDF[bsdfIdx].FilterCubemap(cmd, convolutionSourceTexture, m_ConvolutionTargetTextureArray[bsdfIdx]); } return(m_ConvolutionTargetTextureArray); }
Texture ConvolveProbeTexture(CommandBuffer cmd, Texture texture) { // Probes can be either Cubemaps (for baked probes) or RenderTextures (for realtime probes) Texture2D texture2D = texture as Texture2D; RenderTexture renderTexture = texture as RenderTexture; RenderTexture convolutionSourceTexture = null; if (texture2D != null) { // if the size if different from the cache probe size or if the input texture format is compressed, we need to convert it // 1) to a format for which we can generate mip maps // 2) to the proper reflection probe cache size var sizeMismatch = texture2D.width != m_ProbeSize || texture2D.height != m_ProbeSize; var formatMismatch = texture2D.format != TextureFormat.RGBAHalf; // Temporary RT for convolution is always FP16 if (formatMismatch || sizeMismatch) { if (sizeMismatch) { Debug.LogWarningFormat("Baked Planar Reflection Probe {0} does not match HDRP Planar Reflection Probe Cache size of {1}. Consider baking it at the same size for better loading performance.", texture.name, m_ProbeSize); } else if (texture2D.format == TextureFormat.BC6H) { Debug.LogWarningFormat("Baked Planar Reflection Probe {0} is compressed but the HDRP Planar Reflection Probe Cache is not. Consider removing compression from the input texture for better quality.", texture.name); } ConvertTexture(cmd, texture2D, m_TempRenderTexture); } else { cmd.CopyTexture(texture2D, 0, 0, m_TempRenderTexture, 0, 0); } // Ideally if input is not compressed and has mipmaps, don't do anything here. Problem is, we can't know if mips have been already convolved offline... //cmd.GenerateMips(m_TempRenderTexture); HDRenderPipeline.RT_GenerateMips(cmd, m_TempRenderTexture); convolutionSourceTexture = m_TempRenderTexture; } else { Debug.Assert(renderTexture != null); if (renderTexture.dimension != TextureDimension.Tex2D) { Debug.LogError("Planar Realtime reflection probe should always be a 2D RenderTexture."); return(null); } // TODO: Do a different case for downsizing, in this case, instead of doing ConvertTexture just use the relevant mipmaps. var sizeMismatch = renderTexture.width != m_ProbeSize || renderTexture.height != m_ProbeSize; if (sizeMismatch) { ConvertTexture(cmd, renderTexture, m_TempRenderTexture); convolutionSourceTexture = m_TempRenderTexture; } else { convolutionSourceTexture = renderTexture; } // Generate unfiltered mipmaps as a base for convolution // TODO: Make sure that we don't first convolve everything on the GPU with the legacy code path executed after rendering the probe. //cmd.GenerateMips(convolutionSourceTexture); HDRenderPipeline.RT_GenerateMips(cmd, convolutionSourceTexture); } m_IBLFilterGGX.FilterPlanarTexture(cmd, convolutionSourceTexture, m_ConvolutionTargetTexture); return(m_ConvolutionTargetTexture); }