RTRQualityRenderingParameters PrepareRTRQualityRenderingParameters(HDCamera hdCamera, ScreenSpaceReflection settings, bool transparent)
        {
            RTRQualityRenderingParameters rtrQualityRenderingParameters = new RTRQualityRenderingParameters();

            // Camera parameters
            rtrQualityRenderingParameters.texWidth  = hdCamera.actualWidth;
            rtrQualityRenderingParameters.texHeight = hdCamera.actualHeight;
            rtrQualityRenderingParameters.viewCount = hdCamera.viewCount;

            // Reflection evaluation parameters
            rtrQualityRenderingParameters.clampValue  = settings.clampValue;
            rtrQualityRenderingParameters.reflectSky  = settings.reflectSky.value ? 1 : 0;
            rtrQualityRenderingParameters.rayLength   = settings.rayLength;
            rtrQualityRenderingParameters.sampleCount = settings.sampleCount.value;
            rtrQualityRenderingParameters.bounceCount = settings.bounceCount.value;
            rtrQualityRenderingParameters.transparent = transparent;

            // Other parameters
            rtrQualityRenderingParameters.accelerationStructure = RequestAccelerationStructure();
            rtrQualityRenderingParameters.lightCluster          = RequestLightCluster();
            BlueNoise blueNoise = GetBlueNoiseManager();

            rtrQualityRenderingParameters.ditheredTextureSet          = blueNoise.DitheredTextureSet8SPP();
            rtrQualityRenderingParameters.shaderVariablesRayTracingCB = m_ShaderVariablesRayTracingCB;
            rtrQualityRenderingParameters.skyTexture       = m_SkyManager.GetSkyReflection(hdCamera);
            rtrQualityRenderingParameters.reflectionShader = m_Asset.renderPipelineRayTracingResources.reflectionRaytracingRT;

            return(rtrQualityRenderingParameters);
        }
Esempio n. 2
0
        void RenderReflectionsQuality(HDCamera hdCamera, CommandBuffer cmd, RTHandle outputTexture, ScriptableRenderContext renderContext, int frameCount, bool transparent)
        {
            // Request the buffers we shall be using
            RTHandle intermediateBuffer0 = GetRayTracingBuffer(InternalRayTracingBuffers.RGBA0);
            RTHandle intermediateBuffer1 = GetRayTracingBuffer(InternalRayTracingBuffers.RGBA1);

            var          settings             = hdCamera.volumeStack.GetComponent <ScreenSpaceReflection>();
            LightCluster lightClusterSettings = hdCamera.volumeStack.GetComponent <LightCluster>();

            // Do the integration
            RTRQualityRenderingParameters rtrQRenderingParameters = PrepareRTRQualityRenderingParameters(hdCamera, settings, transparent);
            RTRQualityRenderingResources  rtrQRenderingResources  = PrepareRTRQualityRenderingResources(hdCamera, outputTexture);

            using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.RaytracingReflectionEvaluation)))
            {
                RenderQualityRayTracedReflections(cmd, rtrQRenderingParameters, rtrQRenderingResources);
            }

            using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.RaytracingFilterReflection)))
            {
                if (settings.denoise && !transparent)
                {
                    // 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, rtrQRenderingParameters.bounceCount == 1);
                    ReflectionDenoiserResources  reflectionDenoiserResources = reflectionDenoiser.PrepareReflectionDenoiserResources(hdCamera, outputTexture, reflectionHistory,
                                                                                                                                     intermediateBuffer0, intermediateBuffer1);
                    HDReflectionDenoiser.DenoiseBuffer(cmd, reflDenoiserParameters, reflectionDenoiserResources);
                }
            }
        }
        static void RenderQualityRayTracedReflections(CommandBuffer cmd, RTRQualityRenderingParameters rtrQRenderingParameters, RTRQualityRenderingResources rtrQRenderingResources)
        {
            // Define the shader pass to use for the reflection pass
            cmd.SetRayTracingShaderPass(rtrQRenderingParameters.reflectionShader, "IndirectDXR");

            // Set the acceleration structure for the pass
            cmd.SetRayTracingAccelerationStructure(rtrQRenderingParameters.reflectionShader, HDShaderIDs._RaytracingAccelerationStructureName, rtrQRenderingParameters.accelerationStructure);

            // Global reflection parameters
            rtrQRenderingParameters.shaderVariablesRayTracingCB._RaytracingIntensityClamp = rtrQRenderingParameters.clampValue;
            rtrQRenderingParameters.shaderVariablesRayTracingCB._RaytracingIncludeSky     = rtrQRenderingParameters.reflectSky;
            // Inject the ray generation data
            rtrQRenderingParameters.shaderVariablesRayTracingCB._RaytracingRayMaxLength = rtrQRenderingParameters.rayLength;
            rtrQRenderingParameters.shaderVariablesRayTracingCB._RaytracingNumSamples   = rtrQRenderingParameters.sampleCount;
            // Set the number of bounces for reflections
            rtrQRenderingParameters.shaderVariablesRayTracingCB._RaytracingMaxRecursion = rtrQRenderingParameters.bounceCount;
            ConstantBuffer.PushGlobal(cmd, rtrQRenderingParameters.shaderVariablesRayTracingCB, HDShaderIDs._ShaderVariablesRaytracing);

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

            // Set the data for the ray generation
            cmd.SetRayTracingTextureParam(rtrQRenderingParameters.reflectionShader, HDShaderIDs._SsrLightingTextureRW, rtrQRenderingResources.outputTexture);
            cmd.SetRayTracingTextureParam(rtrQRenderingParameters.reflectionShader, HDShaderIDs._DepthTexture, rtrQRenderingResources.depthStencilBuffer);
            cmd.SetRayTracingTextureParam(rtrQRenderingParameters.reflectionShader, HDShaderIDs._NormalBufferTexture, rtrQRenderingResources.normalBuffer);
            cmd.SetGlobalTexture(HDShaderIDs._StencilTexture, rtrQRenderingResources.depthStencilBuffer, RenderTextureSubElement.Stencil);
            cmd.SetRayTracingIntParams(rtrQRenderingParameters.reflectionShader, HDShaderIDs._SsrStencilBit, (int)StencilUsage.TraceReflectionRay);

            // Set ray count texture
            cmd.SetRayTracingTextureParam(rtrQRenderingParameters.reflectionShader, HDShaderIDs._RayCountTexture, rtrQRenderingResources.rayCountTexture);

            // Bind the lightLoop data
            rtrQRenderingParameters.lightCluster.BindLightClusterData(cmd);

            // Note: Just in case, we rebind the directional light data (in case they were not)
            cmd.SetGlobalBuffer(HDShaderIDs._DirectionalLightDatas, rtrQRenderingResources.directionalLightData);

            // Evaluate the clear coat mask texture based on the lit shader mode
            cmd.SetRayTracingTextureParam(rtrQRenderingParameters.reflectionShader, HDShaderIDs._SsrClearCoatMaskTexture, rtrQRenderingResources.clearCoatMaskTexture);

            // Set the data for the ray miss
            cmd.SetRayTracingTextureParam(rtrQRenderingParameters.reflectionShader, HDShaderIDs._SkyTexture, rtrQRenderingParameters.skyTexture);

            // Only use the shader variant that has multi bounce if the bounce count > 1
            CoreUtils.SetKeyword(cmd, "MULTI_BOUNCE_INDIRECT", rtrQRenderingParameters.bounceCount > 1);

            // We are not in the diffuse only case
            rtrQRenderingParameters.shaderVariablesRayTracingCB._RayTracingDiffuseLightingOnly = 0;
            ConstantBuffer.PushGlobal(cmd, rtrQRenderingParameters.shaderVariablesRayTracingCB, HDShaderIDs._ShaderVariablesRaytracing);

            // Run the computation
            cmd.DispatchRays(rtrQRenderingParameters.reflectionShader, rtrQRenderingParameters.transparent ? m_RayGenIntegrationTransparentName : m_RayGenIntegrationName, (uint)rtrQRenderingParameters.texWidth, (uint)rtrQRenderingParameters.texHeight, (uint)rtrQRenderingParameters.viewCount);

            // Disable multi-bounce
            CoreUtils.SetKeyword(cmd, "MULTI_BOUNCE_INDIRECT", false);
        }