Пример #1
0
        RTReflectionDirGenParameters PrepareRTReflectionDirGenParameters(HDCamera hdCamera, bool transparent, ScreenSpaceReflection settings)
        {
            RTReflectionDirGenParameters rtrDirGenParams = new RTReflectionDirGenParameters();

            // Set the camera parameters
            rtrDirGenParams.texWidth  = hdCamera.actualWidth;
            rtrDirGenParams.texHeight = hdCamera.actualHeight;
            rtrDirGenParams.viewCount = hdCamera.viewCount;

            // Set the generation parameters
            rtrDirGenParams.fullResolution = settings.fullResolution;
            rtrDirGenParams.minSmoothness  = settings.minSmoothness;

            // Grab the right kernel
            rtrDirGenParams.directionGenCS = m_Asset.renderPipelineRayTracingResources.reflectionRaytracingCS;
            if (settings.fullResolution)
            {
                rtrDirGenParams.dirGenKernel = transparent ? m_RaytracingReflectionsTransparentFullResKernel : m_RaytracingReflectionsFullResKernel;
            }
            else
            {
                rtrDirGenParams.dirGenKernel = transparent ? m_RaytracingReflectionsTransparentHalfResKernel : m_RaytracingReflectionsHalfResKernel;
            }

            // Grab the additional parameters
            BlueNoise blueNoise = GetBlueNoiseManager();

            rtrDirGenParams.ditheredTextureSet          = blueNoise.DitheredTextureSet8SPP();
            rtrDirGenParams.shaderVariablesRayTracingCB = m_ShaderVariablesRayTracingCB;

            return(rtrDirGenParams);
        }
Пример #2
0
        static void RTReflectionDirectionGeneration(CommandBuffer cmd, RTReflectionDirGenParameters rtrDirGenParams, RTReflectionDirGenResources rtrDirGenResources)
        {
            // TODO: check if this is required, i do not think so
            CoreUtils.SetRenderTarget(cmd, rtrDirGenResources.outputBuffer, ClearFlag.Color, clearColor: Color.black);

            // Inject the ray-tracing sampling data
            BlueNoise.BindDitheredTextureSet(cmd, rtrDirGenParams.ditheredTextureSet);

            // Bind all the required scalars to the CB
            rtrDirGenParams.shaderVariablesRayTracingCB._RaytracingReflectionMinSmoothness = rtrDirGenParams.minSmoothness;
            ConstantBuffer.PushGlobal(cmd, rtrDirGenParams.shaderVariablesRayTracingCB, HDShaderIDs._ShaderVariablesRaytracing);

            // Bind all the required textures
            cmd.SetComputeTextureParam(rtrDirGenParams.directionGenCS, rtrDirGenParams.dirGenKernel, HDShaderIDs._DepthTexture, rtrDirGenResources.depthBuffer);
            cmd.SetComputeTextureParam(rtrDirGenParams.directionGenCS, rtrDirGenParams.dirGenKernel, HDShaderIDs._NormalBufferTexture, rtrDirGenResources.normalBuffer);
            cmd.SetComputeTextureParam(rtrDirGenParams.directionGenCS, rtrDirGenParams.dirGenKernel, HDShaderIDs._SsrClearCoatMaskTexture, rtrDirGenResources.clearCoatMaskTexture);
            cmd.SetComputeIntParam(rtrDirGenParams.directionGenCS, HDShaderIDs._SsrStencilBit, (int)StencilUsage.TraceReflectionRay);
            cmd.SetComputeTextureParam(rtrDirGenParams.directionGenCS, rtrDirGenParams.dirGenKernel, HDShaderIDs._StencilTexture, rtrDirGenResources.stencilBuffer, 0, RenderTextureSubElement.Stencil);

            // Bind the output buffers
            cmd.SetComputeTextureParam(rtrDirGenParams.directionGenCS, rtrDirGenParams.dirGenKernel, HDShaderIDs._RaytracingDirectionBuffer, rtrDirGenResources.outputBuffer);

            // Evaluate the dispatch parameters
            int numTilesX = (rtrDirGenParams.texWidth + (rtReflectionsComputeTileSize - 1)) / rtReflectionsComputeTileSize;
            int numTilesY = (rtrDirGenParams.texHeight + (rtReflectionsComputeTileSize - 1)) / rtReflectionsComputeTileSize;

            // Compute the directions
            cmd.DispatchCompute(rtrDirGenParams.directionGenCS, rtrDirGenParams.dirGenKernel, numTilesX, numTilesY, rtrDirGenParams.viewCount);
        }
Пример #3
0
        void RenderReflectionsPerformance(HDCamera hdCamera, CommandBuffer cmd, RTHandle outputTexture, ScriptableRenderContext renderContext, int frameCount, bool transparent)
        {
            // Fetch the required resources
            RTHandle intermediateBuffer0 = GetRayTracingBuffer(InternalRayTracingBuffers.RGBA0);
            RTHandle intermediateBuffer1 = GetRayTracingBuffer(InternalRayTracingBuffers.RGBA1);

            // Fetch all the settings
            ScreenSpaceReflection settings = hdCamera.volumeStack.GetComponent <ScreenSpaceReflection>();

            // Generate the signal
            using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.RaytracingReflectionDirectionGeneration)))
            {
                // Prepare the components for the direction generation
                RTReflectionDirGenParameters rtrDirGenParameters   = PrepareRTReflectionDirGenParameters(hdCamera, transparent, settings);
                RTReflectionDirGenResources  rtrDirGenResousources = PrepareRTReflectionDirGenResources(hdCamera, intermediateBuffer1);
                RTReflectionDirectionGeneration(cmd, rtrDirGenParameters, rtrDirGenResousources);
            }

            using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.RaytracingReflectionEvaluation)))
            {
                // Prepare the components for the deferred lighting
                DeferredLightingRTParameters deferredParamters = PrepareReflectionDeferredLightingRTParameters(hdCamera);
                DeferredLightingRTResources  deferredResources = PrepareDeferredLightingRTResources(hdCamera, intermediateBuffer1, intermediateBuffer0);
                RenderRaytracingDeferredLighting(cmd, deferredParamters, deferredResources);
            }

            using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.RaytracingReflectionUpscaleGeneration)))
            {
                // Prepare the parameters for the upscale pass
                RTReflectionUpscaleParameters rtrUpscaleParameters = PrepareRTReflectionUpscaleParameters(hdCamera, settings);
                RTReflectionUpscaleResources  rtrUpscaleResources  = PrepareRTReflectionUpscaleResources(hdCamera, intermediateBuffer0, intermediateBuffer1, outputTexture);
                UpscaleRTReflections(cmd, rtrUpscaleParameters, rtrUpscaleResources);
            }

            // Denoise if required
            if (settings.denoise && !transparent)
            {
                using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.RaytracingFilterReflection)))
                {
                    // Grab the history buffer
                    RTHandle reflectionHistory = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.RaytracedReflection)
                                                 ?? hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.RaytracedReflection, ReflectionHistoryBufferAllocatorFunction, 1);

                    // Prepare the parameters and the resources
                    HDReflectionDenoiser         reflectionDenoiser          = GetReflectionDenoiser();
                    ReflectionDenoiserParameters reflDenoiserParameters      = reflectionDenoiser.PrepareReflectionDenoiserParameters(hdCamera, EvaluateHistoryValidity(hdCamera), settings.denoiserRadius);
                    ReflectionDenoiserResources  reflectionDenoiserResources = reflectionDenoiser.PrepareReflectionDenoiserResources(hdCamera, outputTexture, reflectionHistory,
                                                                                                                                     intermediateBuffer0, intermediateBuffer1);

                    // Denoise
                    HDReflectionDenoiser.DenoiseBuffer(cmd, reflDenoiserParameters, reflectionDenoiserResources);
                }
            }
        }