Beispiel #1
0
 // Scaling viewport is done for auto-scaling render targets.
 // In the context of HDRP, every auto-scaled RT is scaled against the maximum RTHandles reference size (that can only grow).
 // When we render using a camera whose viewport is smaller than the RTHandles reference size (and thus smaller than the RT actual size), we need to set it explicitly (otherwise, native code will set the viewport at the size of the RT)
 // For auto-scaled RTs (like for example a half-resolution RT), we need to scale this viewport accordingly.
 // For non scaled RTs we just do nothing, the native code will set the viewport at the size of the RT anyway.
 public static void SetViewport(CommandBuffer cmd, RTHandle target)
 {
     if (target.useScaling)
     {
         Vector2Int scaledViewportSize = target.GetScaledSize(target.rtHandleProperties.currentViewportSize);
         cmd.SetViewport(new Rect(0.0f, 0.0f, scaledViewportSize.x, scaledViewportSize.y));
     }
 }
Beispiel #2
0
        void DemandResize(RTHandle rth)
        {
            Assert.IsTrue(m_ResizeOnDemandRTs.Contains(rth), "The RTHandle is not an resize on demand handle in this RTHandleSystem. Please call SwitchToResizeOnDemand(rth, true) before resizing on demand.");

            // Grab the render texture
            var rt = rth.m_RT;

            rth.referenceSize = new Vector2Int(m_MaxWidths, m_MaxHeights);
            var scaledSize = rth.GetScaledSize(rth.referenceSize);

            scaledSize = Vector2Int.Max(Vector2Int.one, scaledSize);

            // Did the size change?
            var sizeChanged = rt.width != scaledSize.x || rt.height != scaledSize.y;
            // If this is an MSAA texture, did the sample count change?
            var msaaSampleChanged = rth.m_EnableMSAA && rt.antiAliasing != (int)m_ScaledRTCurrentMSAASamples;

            if (sizeChanged || msaaSampleChanged)
            {
                // Free this render texture
                rt.Release();

                // Update the antialiasing count
                if (rth.m_EnableMSAA)
                {
                    rt.antiAliasing = (int)m_ScaledRTCurrentMSAASamples;
                }

                // Update the size
                rt.width  = scaledSize.x;
                rt.height = scaledSize.y;

                // Generate a new name
                rt.name = CoreUtils.GetRenderTargetAutoName(
                    rt.width,
                    rt.height,
                    rt.volumeDepth,
                    rt.graphicsFormat,
                    rt.dimension,
                    rth.m_Name,
                    mips: rt.useMipMap,
                    enableMSAA: rth.m_EnableMSAA,
                    msaaSamples: m_ScaledRTCurrentMSAASamples,
                    dynamicRes: rt.useDynamicScale
                    );

                // Create the new texture
                rt.Create();
            }
        }