Exemplo n.º 1
0
        public Vector4 FetchSlice(CommandBuffer cmd, Texture texture, ref IBLFilterBSDF.PlanarTextureFilteringParameters planarTextureFilteringParameters, out int fetchIndex)
        {
            Vector4 scaleOffset = Vector4.zero;

            fetchIndex = m_FrameProbeIndex++;

            if (m_TextureAtlas.IsCached(out scaleOffset, texture))
            {
                // If the texture is already in the atlas, we update it only if needed
                if (NeedsUpdate(texture) || m_ProbeBakingState[scaleOffset] != ProbeFilteringState.Ready)
                {
                    if (!UpdatePlanarTexture(cmd, texture, ref planarTextureFilteringParameters, ref scaleOffset))
                    {
                        Debug.LogError("Can't convolve or update the planar reflection render target");
                    }
                }
            }
            else // Either we add it to the atlas
            if (!UpdatePlanarTexture(cmd, texture, ref planarTextureFilteringParameters, ref scaleOffset))
            {
                Debug.LogError("No more space in the planar reflection probe atlas. To solve this issue, increase the size of the Planar Reflection Probe Atlas in the HDRP settings.");
            }

            return(scaleOffset);
        }
Exemplo n.º 2
0
        Texture ConvolveProbeTexture(CommandBuffer cmd, Texture texture, ref IBLFilterBSDF.PlanarTextureFilteringParameters planarTextureFilteringParameters, out Vector4 sourceScaleOffset)
        {
            // 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;

            // Disabled code path because planar reflection probe baking is currently disabled
            if (texture2D != null && false)
            {
                // 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);
                }

                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.");
                    sourceScaleOffset = Vector4.zero;
                    return(null);
                }

                convolutionSourceTexture = renderTexture;
            }

            float scaleX = (float)texture.width / m_ConvolutionTargetTexture.width;
            float scaleY = (float)texture.height / m_ConvolutionTargetTexture.height;

            sourceScaleOffset = new Vector4(scaleX, scaleY, 0, 0);
            m_IBLFilterGGX.FilterPlanarTexture(cmd, convolutionSourceTexture, ref planarTextureFilteringParameters, m_ConvolutionTargetTexture);

            return(m_ConvolutionTargetTexture);
        }
Exemplo n.º 3
0
        bool UpdatePlanarTexture(CommandBuffer cmd, Texture texture, ref IBLFilterBSDF.PlanarTextureFilteringParameters planarTextureFilteringParameters, ref Vector4 scaleOffset)
        {
            bool success = false;

            using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.ConvolvePlanarReflectionProbe)))
            {
                // For now baking is done directly but will be time sliced in the future. Just preparing the code here.
                m_ProbeBakingState[scaleOffset] = ProbeFilteringState.Convolving;

                Vector4 sourceScaleOffset;
                Texture convolvedTexture = ConvolveProbeTexture(cmd, texture, ref planarTextureFilteringParameters, out sourceScaleOffset);
                if (convolvedTexture == null)
                {
                    return(false);
                }

                if (m_PerformBC6HCompression)
                {
                    throw new NotImplementedException("BC6H Support not implemented for PlanarReflectionProbeCache");
                }
                else
                {
                    if (m_TextureAtlas.IsCached(out scaleOffset, texture))
                    {
                        success = m_TextureAtlas.UpdateTexture(cmd, texture, convolvedTexture, ref scaleOffset, sourceScaleOffset);
                    }
                    else
                    {
                        // Reserve space for the rendertarget and then blit the result of the convolution at this
                        // location, we don't use the UpdateTexture because it will keep the reference to the
                        // temporary target used to convolve the result of the probe rendering.
                        if (!m_TextureAtlas.AllocateTextureWithoutBlit(texture, texture.width, texture.height, ref scaleOffset))
                        {
                            return(false);
                        }
                        m_TextureAtlas.BlitTexture(cmd, scaleOffset, convolvedTexture, sourceScaleOffset);
                        success = true;
                    }
                }

                m_ProbeBakingState[scaleOffset] = ProbeFilteringState.Ready;
            }

            return(success);
        }
Exemplo n.º 4
0
        Texture ConvolveProbeTexture(CommandBuffer cmd, Texture texture, ref IBLFilterBSDF.PlanarTextureFilteringParameters planarTextureFilteringParameters, out Vector4 sourceScaleOffset)
        {
            Texture2D     texture2D     = texture as Texture2D;
            RenderTexture renderTexture = texture as RenderTexture;

            if (renderTexture.dimension != TextureDimension.Tex2D)
            {
                Debug.LogError("Planar Realtime reflection probe should always be a 2D RenderTexture.");
                sourceScaleOffset = Vector4.zero;
                return(null);
            }

            float scaleX = (float)texture.width / m_ConvolutionTargetTexture.width;
            float scaleY = (float)texture.height / m_ConvolutionTargetTexture.height;

            sourceScaleOffset = new Vector4(scaleX, scaleY, 0, 0);
            m_IBLFilterGGX.FilterPlanarTexture(cmd, renderTexture, ref planarTextureFilteringParameters, m_ConvolutionTargetTexture);

            return(m_ConvolutionTargetTexture);
        }
Exemplo n.º 5
0
        bool UpdatePlanarTexture(CommandBuffer cmd, Texture texture, ref IBLFilterBSDF.PlanarTextureFilteringParameters planarTextureFilteringParameters, ref Vector4 scaleOffset)
        {
            bool success = false;

            using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.ConvolvePlanarReflectionProbe)))
            {
                m_ProbeBakingState[scaleOffset] = ProbeFilteringState.Convolving;

                Vector4 sourceScaleOffset;
                Texture convolvedTexture = ConvolveProbeTexture(cmd, texture, ref planarTextureFilteringParameters, out sourceScaleOffset);
                if (convolvedTexture == null)
                {
                    return(false);
                }

                if (m_TextureAtlas.IsCached(out scaleOffset, texture))
                {
                    success = m_TextureAtlas.UpdateTexture(cmd, texture, convolvedTexture, ref scaleOffset, sourceScaleOffset);
                }
                else
                {
                    // Reserve space for the rendertarget and then blit the result of the convolution at this
                    // location, we don't use the UpdateTexture because it will keep the reference to the
                    // temporary target used to convolve the result of the probe rendering.
                    if (!m_TextureAtlas.AllocateTextureWithoutBlit(texture, texture.width, texture.height, ref scaleOffset))
                    {
                        return(false);
                    }
                    m_TextureAtlas.BlitTexture(cmd, scaleOffset, convolvedTexture, sourceScaleOffset);
                    success = true;
                }

                m_ProbeBakingState[scaleOffset] = ProbeFilteringState.Ready;
            }

            return(success);
        }