TextureHandle GetPostprocessOutputHandle(RenderGraph renderGraph, string name) { return(renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true) { name = name, colorFormat = m_ColorFormat, useMipMap = false, enableRandomWrite = true })); }
TextureHandle DenoiseRTSSS(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle rayTracedSSS, TextureHandle depthPyramid, TextureHandle normalBuffer, TextureHandle motionVectorBuffer, TextureHandle historyValidationTexture) { // Evaluate the history's validity float historyValidity = HDRenderPipeline.EvaluateHistoryValidity(hdCamera); // Run the temporal denoiser TextureHandle historyBuffer = renderGraph.ImportTexture(RequestRayTracedSSSHistoryTexture(hdCamera)); return(GetTemporalFilter().Denoise(renderGraph, hdCamera, singleChannel: false, historyValidity, rayTracedSSS, renderGraph.defaultResources.blackTextureXR, historyBuffer, depthPyramid, normalBuffer, motionVectorBuffer, historyValidationTexture)); }
BuildGPULightListOutput BuildGPULightList(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle depthStencilBuffer, TextureHandle stencilBufferCopy, GBufferOutput gBuffer) { using (var builder = renderGraph.AddRenderPass <BuildGPULightListPassData>("Build Light List", out var passData, ProfilingSampler.Get(HDProfileId.BuildLightList))) { builder.EnableAsyncCompute(hdCamera.frameSettings.BuildLightListRunsAsync()); passData.lightLoopGlobalParameters = PrepareLightLoopGlobalParameters(hdCamera, m_TileAndClusterData); passData.buildGPULightListParameters = PrepareBuildGPULightListParameters(hdCamera, m_TileAndClusterData, ref m_ShaderVariablesLightListCB, m_TotalLightCount); passData.depthBuffer = builder.ReadTexture(depthStencilBuffer); passData.stencilTexture = builder.ReadTexture(stencilBufferCopy); if (passData.buildGPULightListParameters.computeMaterialVariants && passData.buildGPULightListParameters.enableFeatureVariants) { for (int i = 0; i < gBuffer.gBufferCount; ++i) { passData.gBuffer[i] = builder.ReadTexture(gBuffer.mrt[i]); } passData.gBufferCount = gBuffer.gBufferCount; } passData.lightVolumeDataBuffer = m_TileAndClusterData.lightVolumeDataBuffer; passData.convexBoundsBuffer = m_TileAndClusterData.convexBoundsBuffer; passData.AABBBoundsBuffer = m_TileAndClusterData.AABBBoundsBuffer; passData.globalLightListAtomic = m_TileAndClusterData.globalLightListAtomic; passData.output.tileFeatureFlags = builder.WriteComputeBuffer(renderGraph.ImportComputeBuffer(m_TileAndClusterData.tileFeatureFlags)); passData.output.dispatchIndirectBuffer = builder.WriteComputeBuffer(renderGraph.ImportComputeBuffer(m_TileAndClusterData.dispatchIndirectBuffer)); passData.output.perVoxelOffset = builder.WriteComputeBuffer(renderGraph.ImportComputeBuffer(m_TileAndClusterData.perVoxelOffset)); passData.output.perTileLogBaseTweak = builder.WriteComputeBuffer(renderGraph.ImportComputeBuffer(m_TileAndClusterData.perTileLogBaseTweak)); passData.output.tileList = builder.WriteComputeBuffer(renderGraph.ImportComputeBuffer(m_TileAndClusterData.tileList)); passData.output.bigTileLightList = builder.WriteComputeBuffer(renderGraph.ImportComputeBuffer(m_TileAndClusterData.bigTileLightList)); passData.output.perVoxelLightLists = builder.WriteComputeBuffer(renderGraph.ImportComputeBuffer(m_TileAndClusterData.perVoxelLightLists)); passData.output.lightList = builder.WriteComputeBuffer(renderGraph.ImportComputeBuffer(m_TileAndClusterData.lightList)); builder.SetRenderFunc( (BuildGPULightListPassData data, RenderGraphContext context) => { bool tileFlagsWritten = false; var buildLightListResources = PrepareBuildGPULightListResources(context, data); ClearLightLists(data.buildGPULightListParameters, buildLightListResources, context.cmd); GenerateLightsScreenSpaceAABBs(data.buildGPULightListParameters, buildLightListResources, context.cmd); BigTilePrepass(data.buildGPULightListParameters, buildLightListResources, context.cmd); BuildPerTileLightList(data.buildGPULightListParameters, buildLightListResources, ref tileFlagsWritten, context.cmd); VoxelLightListGeneration(data.buildGPULightListParameters, buildLightListResources, context.cmd); BuildDispatchIndirectArguments(data.buildGPULightListParameters, buildLightListResources, tileFlagsWritten, context.cmd); // TODO RENDERGRAPH WARNING: Note that the three sets of variables are bound here, but it should be handled differently. PushLightLoopGlobalParams(data.lightLoopGlobalParameters, context.cmd); }); return(passData.output); } }
TextureHandle RenderVolumetricClouds_FullResolution(RenderGraph renderGraph, HDCamera hdCamera, TVolumetricCloudsCameraType cameraType, TextureHandle colorBuffer, TextureHandle depthPyramid, TextureHandle motionVectors, TextureHandle volumetricLighting, TextureHandle maxZMask) { using (var builder = renderGraph.AddRenderPass <VolumetricCloudsFullResolutionData>("Generating the rays for RTR", out var passData, ProfilingSampler.Get(HDProfileId.VolumetricClouds))) { builder.EnableAsyncCompute(false); VolumetricClouds settings = hdCamera.volumeStack.GetComponent <VolumetricClouds>(); passData.parameters = PrepareVolumetricCloudsParameters_FullResolution(hdCamera, hdCamera.actualWidth, hdCamera.actualHeight, hdCamera.viewCount, hdCamera.exposureControlFS, settings, cameraType); passData.colorBuffer = builder.ReadTexture(builder.WriteTexture(colorBuffer)); passData.depthPyramid = builder.ReadTexture(depthPyramid); passData.maxZMask = settings.localClouds.value ? renderGraph.defaultResources.blackTextureXR : builder.ReadTexture(maxZMask); passData.ambientProbeBuffer = builder.ReadComputeBuffer(renderGraph.ImportComputeBuffer(m_CloudsProbeBuffer)); passData.volumetricLighting = builder.ReadTexture(volumetricLighting); passData.scatteringFallbackTexture = renderGraph.defaultResources.blackTexture3DXR; passData.intermediateLightingBuffer = builder.CreateTransientTexture(new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite = true, name = "Temporary Clouds Lighting Buffer 0" }); passData.intermediateBufferDepth = builder.CreateTransientTexture(new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R32_SFloat, enableRandomWrite = true, name = "Temporary Clouds Depth Buffer 0" }); passData.intermediateColorBufferCopy = passData.parameters.needExtraColorBufferCopy ? builder.CreateTransientTexture(new TextureDesc(Vector2.one, true, true) { colorFormat = GetColorBufferFormat(), enableRandomWrite = true, name = "Temporary Color Buffer" }) : renderGraph.defaultResources.blackTextureXR; if (passData.parameters.needsTemporaryBuffer) { passData.intermediateBufferUpscale = builder.CreateTransientTexture(new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite = true, name = "Temporary Clouds Upscaling Buffer" }); } else { passData.intermediateBufferUpscale = renderGraph.defaultResources.blackTexture; } builder.SetRenderFunc( (VolumetricCloudsFullResolutionData data, RenderGraphContext ctx) => { TraceVolumetricClouds_FullResolution(ctx.cmd, data.parameters, data.ambientProbeBuffer, data.colorBuffer, data.depthPyramid, data.volumetricLighting, data.scatteringFallbackTexture, data.maxZMask, data.intermediateLightingBuffer, data.intermediateBufferDepth, data.intermediateColorBufferCopy, data.intermediateBufferUpscale); }); // In the case of reflection probes, we don't expect any pass that will need the transmittance mask of the clouds so we return white. return(renderGraph.defaultResources.whiteTextureXR); } }
PrepassOutput RenderPrepass(RenderGraph renderGraph, RenderGraphMutableResource sssBuffer, CullingResults cullingResults, HDCamera hdCamera) { m_IsDepthBufferCopyValid = false; var result = new PrepassOutput(); result.gbuffer = m_GBufferOutput; result.dbuffer = m_DBufferOutput; bool msaa = hdCamera.frameSettings.IsEnabled(FrameSettingsField.MSAA); bool clearMotionVectors = hdCamera.camera.cameraType == CameraType.SceneView && !CoreUtils.AreAnimatedMaterialsEnabled(hdCamera.camera); // TODO: See how to clean this. Some buffers are created outside, some inside functions... result.motionVectorsBuffer = CreateMotionVectorBuffer(renderGraph, msaa, clearMotionVectors); result.depthBuffer = CreateDepthBuffer(renderGraph, msaa); RenderOcclusionMeshes(renderGraph, hdCamera, result.depthBuffer); StartSinglePass(renderGraph, hdCamera); bool renderMotionVectorAfterGBuffer = RenderDepthPrepass(renderGraph, cullingResults, hdCamera, ref result); if (!renderMotionVectorAfterGBuffer) { // If objects motion vectors are enabled, this will render the objects with motion vector into the target buffers (in addition to the depth) // Note: An object with motion vector must not be render in the prepass otherwise we can have motion vector write that should have been rejected RenderObjectsMotionVectors(renderGraph, cullingResults, hdCamera, result); } ResolveStencilBufferIfNeeded(renderGraph, hdCamera, ref result); // At this point in forward all objects have been rendered to the prepass (depth/normal/motion vectors) so we can resolve them ResolvePrepassBuffers(renderGraph, hdCamera, ref result); RenderDecals(renderGraph, hdCamera, ref result, cullingResults); RenderGBuffer(renderGraph, sssBuffer, ref result, cullingResults, hdCamera); // In both forward and deferred, everything opaque should have been rendered at this point so we can safely copy the depth buffer for later processing. GenerateDepthPyramid(renderGraph, hdCamera, ref result); if (renderMotionVectorAfterGBuffer) { // See the call RenderObjectsMotionVectors() above and comment RenderObjectsMotionVectors(renderGraph, cullingResults, hdCamera, result); } RenderCameraMotionVectors(renderGraph, hdCamera, result.depthPyramidTexture, result.resolvedMotionVectorsBuffer); result.stencilBuffer = msaa ? result.resolvedStencilBuffer : result.depthBuffer; StopSinglePass(renderGraph, hdCamera); return(result); }
void BuildGPULightList(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle depthStencilBuffer, TextureHandle stencilBufferCopy, GBufferOutput gBuffer) { using (var builder = renderGraph.AddRenderPass <BuildGPULightListPassData>("Build Light List", out var passData, ProfilingSampler.Get(HDProfileId.BuildLightList))) { builder.EnableAsyncCompute(hdCamera.frameSettings.BuildLightListRunsAsync()); passData.lightDataGlobalParameters = PrepareLightDataGlobalParameters(hdCamera); passData.shadowGlobalParameters = PrepareShadowGlobalParameters(hdCamera); passData.lightLoopGlobalParameters = PrepareLightLoopGlobalParameters(hdCamera); passData.buildGPULightListParameters = PrepareBuildGPULightListParameters(hdCamera); // TODO: Move this inside the render function onces compute buffers are RenderGraph ready passData.buildGPULightListResources = PrepareBuildGPULightListResources(m_TileAndClusterData, null, null, isGBufferNeeded: true); passData.depthBuffer = builder.ReadTexture(depthStencilBuffer); passData.stencilTexture = builder.ReadTexture(stencilBufferCopy); if (passData.buildGPULightListParameters.computeMaterialVariants && passData.buildGPULightListParameters.enableFeatureVariants) { for (int i = 0; i < gBuffer.gBufferCount; ++i) { passData.gBuffer[i] = builder.ReadTexture(gBuffer.mrt[i]); } passData.gBufferCount = gBuffer.gBufferCount; } builder.SetRenderFunc( (BuildGPULightListPassData data, RenderGraphContext context) => { bool tileFlagsWritten = false; data.buildGPULightListResources.depthBuffer = context.resources.GetTexture(data.depthBuffer); data.buildGPULightListResources.stencilTexture = context.resources.GetTexture(data.stencilTexture); if (data.buildGPULightListParameters.computeMaterialVariants && data.buildGPULightListParameters.enableFeatureVariants) { data.buildGPULightListResources.gBuffer = context.renderGraphPool.GetTempArray <RTHandle>(data.gBufferCount); for (int i = 0; i < data.gBufferCount; ++i) { data.buildGPULightListResources.gBuffer[i] = context.resources.GetTexture(data.gBuffer[i]); } } ClearLightLists(data.buildGPULightListParameters, data.buildGPULightListResources, context.cmd); GenerateLightsScreenSpaceAABBs(data.buildGPULightListParameters, data.buildGPULightListResources, context.cmd); BigTilePrepass(data.buildGPULightListParameters, data.buildGPULightListResources, context.cmd); BuildPerTileLightList(data.buildGPULightListParameters, data.buildGPULightListResources, ref tileFlagsWritten, context.cmd); VoxelLightListGeneration(data.buildGPULightListParameters, data.buildGPULightListResources, context.cmd); BuildDispatchIndirectArguments(data.buildGPULightListParameters, data.buildGPULightListResources, tileFlagsWritten, context.cmd); // TODO RENDERGRAPH WARNING: Note that the three sets of variables are bound here, but it should be handled differently. PushLightDataGlobalParams(data.lightDataGlobalParameters, context.cmd); PushShadowGlobalParams(data.shadowGlobalParameters, context.cmd); PushLightLoopGlobalParams(data.lightLoopGlobalParameters, context.cmd); }); } }
static public TextureHandle CreateRayCountTexture(RenderGraph renderGraph) { return(renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R16_UInt, slices = TextureXR.slices * (int)RayCountValues.Count, dimension = TextureDimension.Tex2DArray, enableRandomWrite = true, name = "RayCountTextureDebug" })); }
public void CleanupNonRenderGraphResources(RenderGraph renderGraph) { m_Atlas.Release(renderGraph); m_CascadeAtlas.Release(renderGraph); cachedShadowManager.punctualShadowAtlas.Release(renderGraph); if (ShaderConfig.s_AreaLights == 1) { m_AreaLightShadowAtlas.Release(renderGraph); cachedShadowManager.areaShadowAtlas.Release(renderGraph); } }
void PrepareVolumetricCloudsSkyHighPassData(RenderGraph renderGraph, RenderGraphBuilder builder, HDCamera hdCamera, int width, int height, Matrix4x4[] pixelCoordToViewDir, CubemapFace cubemapFace, VolumetricClouds settings, TextureHandle output, VolumetricCloudsSkyHighPassData data) { // Compute the cloud model data CloudModelData cloudModelData = GetCloudModelData(settings); // Fill the common data FillVolumetricCloudsCommonData(false, settings, TVolumetricCloudsCameraType.Sky, in cloudModelData, ref data.commonData); // If this is a baked reflection, we run everything at full res data.finalWidth = width; data.finalHeight = height; // Sky data.cubemapFace = cubemapFace; data.cloudCombinePass = m_CloudCombinePass; // Compute shader and kernels data.renderKernel = m_CloudRenderKernel; data.combineKernel = m_CombineCloudsSkyKernel; data.pixelCoordToViewDir = pixelCoordToViewDir; // Update the constant buffer VolumetricCloudsCameraData cameraData; cameraData.cameraType = data.commonData.cameraType; cameraData.traceWidth = data.finalWidth; cameraData.traceHeight = data.finalHeight; cameraData.intermediateWidth = data.finalWidth; cameraData.intermediateHeight = data.finalHeight; cameraData.finalWidth = data.finalWidth; cameraData.finalHeight = data.finalHeight; cameraData.viewCount = 1; cameraData.enableExposureControl = data.commonData.enableExposureControl; cameraData.lowResolution = false; cameraData.enableIntegration = false; UpdateShaderVariableslClouds(ref data.commonData.cloudsCB, hdCamera, settings, cameraData, cloudModelData, false); int skyResolution = (int)m_Asset.currentPlatformRenderPipelineSettings.lightLoopSettings.skyReflectionSize; data.intermediateLightingBuffer0 = builder.CreateTransientTexture(GetVolumetricCloudsIntermediateLightingBufferDesc()); data.intermediateDepthBuffer = builder.CreateTransientTexture(GetVolumetricCloudsIntermediateDepthBufferDesc()); if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Metal) { data.intermediateLightingBuffer1 = builder.CreateTransientTexture(GetVolumetricCloudsIntermediateLightingBufferDesc()); data.output = builder.ReadWriteTexture(output); } else { data.output = builder.WriteTexture(output); } data.maxZMask = builder.ReadTexture(renderGraph.defaultResources.blackTextureXR); data.ambientProbeBuffer = builder.ReadComputeBuffer(renderGraph.ImportComputeBuffer(m_CloudsProbeBuffer)); }
internal TextureHandle CreateFlagMaskTexture(RenderGraph renderGraph) { return(renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R8_SNorm, dimension = TextureXR.dimension, enableRandomWrite = true, useMipMap = true, name = "FlagMaskTexture" })); }
public override unsafe void Render() { var graph = new RenderGraph(_device, 3); graph.CreateComponent(_settings); //graph.AddPass(_renderer); graph.AddPass(_outputPass); graph.ExecuteGraph(); _output.Present(); }
public TextureHandle Denoise(RenderGraph renderGraph, HDCamera hdCamera, TemporalFilterParameters tfParameters, TextureHandle noisyBuffer, TextureHandle historyBuffer, TextureHandle depthPyramid, TextureHandle normalBuffer, TextureHandle motionVectorBuffer) { using (var builder = renderGraph.AddRenderPass <TemporalFilterPassData>("TemporalDenoiser", out var passData, ProfilingSampler.Get(HDProfileId.TemporalFilter))) { // Cannot run in async builder.EnableAsyncCompute(false); // Fetch all the resources passData.parameters = tfParameters; // Input Buffers passData.depthStencilBuffer = builder.ReadTexture(depthPyramid); passData.normalBuffer = builder.ReadTexture(normalBuffer); passData.motionVectorBuffer = builder.ReadTexture(motionVectorBuffer); passData.velocityBuffer = renderGraph.defaultResources.blackTextureXR; passData.noisyBuffer = builder.ReadTexture(noisyBuffer); // Temporary buffers passData.validationBuffer = builder.CreateTransientTexture(new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R8_UNorm, enableRandomWrite = true, name = "ValidationTexture" }); // History buffers passData.historyDepthTexture = builder.ReadTexture(renderGraph.ImportTexture(hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.Depth))); passData.historyNormalTexture = builder.ReadTexture(renderGraph.ImportTexture(hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.Normal))); passData.historyBuffer = builder.ReadTexture(builder.WriteTexture(historyBuffer)); // Output buffers passData.outputBuffer = builder.ReadTexture(builder.WriteTexture(renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite = true, name = "Temporal Filter Output" }))); builder.SetRenderFunc( (TemporalFilterPassData data, RenderGraphContext ctx) => { TemporalFilterResources tfResources = new TemporalFilterResources(); tfResources.depthStencilBuffer = data.depthStencilBuffer; tfResources.normalBuffer = data.normalBuffer; tfResources.velocityBuffer = data.velocityBuffer; tfResources.motionVectorBuffer = data.motionVectorBuffer; tfResources.historyDepthTexture = data.historyDepthTexture; tfResources.historyNormalTexture = data.historyNormalTexture; tfResources.noisyBuffer = data.noisyBuffer; tfResources.validationBuffer = data.validationBuffer; tfResources.historyBuffer = data.historyBuffer; tfResources.outputBuffer = data.outputBuffer; DenoiseBuffer(ctx.cmd, data.parameters, tfResources); }); return(passData.outputBuffer); } }
TextureHandle DenoiseRTSSS(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle rayTracedSSS, TextureHandle depthPyramid, TextureHandle normalBuffer, TextureHandle motionVectorBuffer) { // Evaluate the history's validity float historyValidity = HDRenderPipeline.EvaluateHistoryValidity(hdCamera); // Run the temporal denoiser HDTemporalFilter temporalFilter = GetTemporalFilter(); TemporalFilterParameters tfParameters = temporalFilter.PrepareTemporalFilterParameters(hdCamera, false, historyValidity); TextureHandle historyBuffer = renderGraph.ImportTexture(RequestRayTracedSSSHistoryTexture(hdCamera)); return(temporalFilter.Denoise(renderGraph, hdCamera, tfParameters, rayTracedSSS, historyBuffer, depthPyramid, normalBuffer, motionVectorBuffer)); }
TextureHandle CombineRTSSS(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle rayTracedSSS, TextureHandle depthStencilBuffer, TextureHandle sssColor, TextureHandle ssgiBuffer, TextureHandle diffuseLightingBuffer, TextureHandle colorBuffer) { using (var builder = renderGraph.AddRenderPass <ComposeRTSSSPassData>("Composing the result of RTSSS", out var passData, ProfilingSampler.Get(HDProfileId.RaytracingSSSCompose))) { builder.EnableAsyncCompute(false); // Camera parameters passData.texWidth = hdCamera.actualWidth; passData.texHeight = hdCamera.actualHeight; passData.viewCount = hdCamera.viewCount; // Generation parameters passData.validSSGI = GetIndirectDiffuseMode(hdCamera) != IndirectDiffuseMode.Off; // Required kernels passData.combineSSSKernel = passData.validSSGI ? m_CombineSubSurfaceWithGIKernel : m_CombineSubSurfaceKernel; // Other parameters passData.rayTracingSubSurfaceCS = m_Asset.renderPipelineRayTracingResources.subSurfaceRayTracingCS; passData.combineLightingMat = m_CombineLightingPass; passData.depthStencilBuffer = builder.UseDepthBuffer(depthStencilBuffer, DepthAccess.Read); passData.sssColor = builder.ReadTexture(sssColor); passData.ssgiBuffer = passData.validSSGI ? builder.ReadTexture(ssgiBuffer) : renderGraph.defaultResources.blackTextureXR; passData.diffuseLightingBuffer = builder.ReadTexture(diffuseLightingBuffer); passData.subsurfaceBuffer = builder.ReadTexture(rayTracedSSS); passData.colorBuffer = builder.ReadWriteTexture(colorBuffer); builder.SetRenderFunc( (ComposeRTSSSPassData data, RenderGraphContext ctx) => { // Evaluate the dispatch parameters int numTilesXHR = (data.texWidth + (s_sssTileSize - 1)) / s_sssTileSize; int numTilesYHR = (data.texHeight + (s_sssTileSize - 1)) / s_sssTileSize; ctx.cmd.SetComputeTextureParam(data.rayTracingSubSurfaceCS, data.combineSSSKernel, HDShaderIDs._SubSurfaceLightingBuffer, data.subsurfaceBuffer); ctx.cmd.SetComputeTextureParam(data.rayTracingSubSurfaceCS, data.combineSSSKernel, HDShaderIDs._DiffuseLightingTextureRW, data.diffuseLightingBuffer); ctx.cmd.SetComputeTextureParam(data.rayTracingSubSurfaceCS, data.combineSSSKernel, HDShaderIDs._SSSBufferTexture, data.sssColor); if (data.validSSGI) { ctx.cmd.SetComputeTextureParam(data.rayTracingSubSurfaceCS, data.combineSSSKernel, HDShaderIDs._IndirectDiffuseLightingBuffer, data.ssgiBuffer); } ctx.cmd.DispatchCompute(data.rayTracingSubSurfaceCS, data.combineSSSKernel, numTilesXHR, numTilesYHR, data.viewCount); // Combine it with the rest of the lighting data.combineLightingMat.SetTexture(HDShaderIDs._IrradianceSource, data.diffuseLightingBuffer); HDUtils.DrawFullScreen(ctx.cmd, data.combineLightingMat, data.colorBuffer, data.depthStencilBuffer, shaderPassId: 1); }); return(passData.colorBuffer); } }
// Albedo + SSS Profile and mask / Specular occlusion (when no SSS) // This will be used during GBuffer and/or forward passes. TextureHandle CreateSSSBuffer(RenderGraph renderGraph, bool msaa) { return(renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R8G8B8A8_SRGB, enableRandomWrite = !msaa, bindTextureMS = msaa, enableMSAA = msaa, clearBuffer = NeedClearGBuffer(), clearColor = Color.clear, name = msaa ? "SSSBufferMSAA" : "SSSBuffer" })); }
public async Task DrawGraph(RenderGraph graph) { EnsureInitialized(); foreach (var node in graph.Nodes) { await DrawNode(node); } foreach (var edge in graph.Edges) { await DrawEdge(edge); } }
TextureHandle DenoiseReflection(RenderGraph renderGraph, HDCamera hdCamera, bool fullResolution, int denoiserRadius, bool singleReflectionBounce, bool affectSmoothSurfaces, TextureHandle input, TextureHandle depthPyramid, TextureHandle normalBuffer, TextureHandle motionVectors, TextureHandle clearCoatTexture) { // Prepare the parameters and the resources HDReflectionDenoiser reflectionDenoiser = GetReflectionDenoiser(); float historyValidity = EvaluateRayTracedReflectionHistoryValidity(hdCamera, fullResolution, true); RTHandle historySignal = RequestRayTracedReflectionsHistoryTexture(hdCamera); var rtrResult = reflectionDenoiser.DenoiseRTR(renderGraph, hdCamera, historyValidity, denoiserRadius, fullResolution, singleReflectionBounce, affectSmoothSurfaces, depthPyramid, normalBuffer, motionVectors, clearCoatTexture, input, historySignal); PropagateRayTracedReflectionsHistoryValidity(hdCamera, fullResolution, true); return(rtrResult); }
private async Task AnalyzeGraph() { _showingTypesSelector.BitMask = _analyzeTypesSelector.BitMask; var tasks = await TaskManager.GetAll(); var config = new GraphConfig { ReferenceTypes = _analyzeTypesSelector.BitMask }; _graph = await Analyzer.Analyze(tasks, config); await RenderGraph(); }
public void Resolve(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle input) { if (hdCamera.frameSettings.IsEnabled(FrameSettingsField.VirtualTexturing)) { using (var builder = renderGraph.AddRenderPass <ResolveVTData>("Resolve VT", out var passData, ProfilingSampler.Get(HDProfileId.VTFeedbackDownsample))) { // The output is never read outside the pass but is still useful for the VT system so we can't cull this pass. builder.AllowPassCulling(false); bool msaa = hdCamera.msaaEnabled; passData.width = hdCamera.actualWidth; passData.height = hdCamera.actualHeight; passData.lowresWidth = passData.width; passData.lowresHeight = passData.height; GetResolveDimensions(ref passData.lowresWidth, ref passData.lowresHeight); passData.resolver = msaa ? m_ResolverMsaa : m_Resolver; passData.downsampleCS = m_DownSampleCS; passData.downsampleKernel = msaa ? m_DownsampleKernelMSAA : m_DownsampleKernel; passData.input = builder.ReadTexture(input); passData.lowres = builder.WriteTexture(renderGraph.ImportTexture(m_LowresResolver)); builder.SetRenderFunc( (ResolveVTData data, RenderGraphContext ctx) => { RTHandle lowresBuffer = data.lowres; RTHandle buffer = data.input; Debug.Assert(data.lowresWidth <= data.resolver.CurrentWidth && data.lowresHeight <= data.resolver.CurrentHeight); Debug.Assert(data.lowresWidth <= lowresBuffer.referenceSize.x && data.lowresHeight <= lowresBuffer.referenceSize.y); string mainFunction = (buffer.isMSAAEnabled) ? "KMainMSAA" : "KMain"; int inputID = (buffer.isMSAAEnabled) ? HDShaderIDs._InputTextureMSAA : HDShaderIDs._InputTexture; ctx.cmd.SetComputeTextureParam(data.downsampleCS, data.downsampleKernel, inputID, buffer); ctx.cmd.SetComputeTextureParam(data.downsampleCS, data.downsampleKernel, HDShaderIDs._OutputTexture, lowresBuffer); var resolveCounter = 0; var startOffsetX = (resolveCounter % kResolveScaleFactor); var startOffsetY = (resolveCounter / kResolveScaleFactor) % kResolveScaleFactor; ctx.cmd.SetComputeVectorParam(data.downsampleCS, HDShaderIDs._Params, new Vector4(kResolveScaleFactor, startOffsetX, startOffsetY, /*unused*/ -1)); ctx.cmd.SetComputeVectorParam(data.downsampleCS, HDShaderIDs._Params1, new Vector4(data.width, data.height, data.lowresWidth, data.lowresHeight)); var TGSize = 8; //Match shader ctx.cmd.DispatchCompute(data.downsampleCS, data.downsampleKernel, ((int)data.lowresWidth + (TGSize - 1)) / TGSize, ((int)data.lowresHeight + (TGSize - 1)) / TGSize, 1); data.resolver.Process(ctx.cmd, lowresBuffer, 0, data.lowresWidth, 0, data.lowresHeight, 0, 0); VirtualTexturing.System.Update(); }); } } }
TextureHandle UpscaleSSGI(RenderGraph renderGraph, HDCamera hdCamera, GlobalIllumination giSettings, HDUtils.PackedMipChainInfo info, TextureHandle depthPyramid, TextureHandle inputBuffer) { using (var builder = renderGraph.AddRenderPass <UpscaleSSGIPassData>("Upscale SSGI", out var passData, ProfilingSampler.Get(HDProfileId.SSGIUpscale))) { builder.EnableAsyncCompute(false); // Set the camera parameters passData.texWidth = hdCamera.actualWidth; passData.texHeight = hdCamera.actualHeight; passData.viewCount = hdCamera.viewCount; passData.halfScreenSize.Set(passData.texWidth / 2, passData.texHeight / 2, 1.0f / (passData.texWidth * 0.5f), 1.0f / (passData.texHeight * 0.5f)); // Set the generation parameters passData.firstMipOffset.Set(HDShadowUtils.Asfloat((uint)info.mipLevelOffsets[1].x), HDShadowUtils.Asfloat((uint)info.mipLevelOffsets[1].y)); // Grab the right kernel passData.bilateralUpsampleCS = m_Asset.renderPipelineResources.shaders.bilateralUpsampleCS; passData.upscaleKernel = m_BilateralUpSampleColorKernel; passData.depthTexture = builder.ReadTexture(depthPyramid); passData.inputBuffer = builder.ReadTexture(inputBuffer); passData.outputBuffer = builder.WriteTexture(renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite = true, name = "SSGI Final" })); builder.SetRenderFunc( (UpscaleSSGIPassData data, RenderGraphContext ctx) => { // Re-evaluate the dispatch parameters (we are evaluating the upsample in full resolution) int ssgiTileSize = 8; int numTilesXHR = (data.texWidth + (ssgiTileSize - 1)) / ssgiTileSize; int numTilesYHR = (data.texHeight + (ssgiTileSize - 1)) / ssgiTileSize; // Inject the input scalars ctx.cmd.SetComputeVectorParam(data.bilateralUpsampleCS, HDShaderIDs._HalfScreenSize, data.halfScreenSize); ctx.cmd.SetComputeVectorParam(data.bilateralUpsampleCS, HDShaderIDs._DepthPyramidFirstMipLevelOffset, data.firstMipOffset); // Inject all the input buffers ctx.cmd.SetComputeTextureParam(data.bilateralUpsampleCS, data.upscaleKernel, HDShaderIDs._DepthTexture, data.depthTexture); ctx.cmd.SetComputeTextureParam(data.bilateralUpsampleCS, data.upscaleKernel, HDShaderIDs._LowResolutionTexture, data.inputBuffer); // Inject the output textures ctx.cmd.SetComputeTextureParam(data.bilateralUpsampleCS, data.upscaleKernel, HDShaderIDs._OutputUpscaledTexture, data.outputBuffer); // Upscale the buffer to full resolution ctx.cmd.DispatchCompute(data.bilateralUpsampleCS, data.upscaleKernel, numTilesXHR, numTilesYHR, data.viewCount); }); return(passData.outputBuffer); } }
public override void Initialize(Size outputSize, IOutputOwner outputOwner) { _device = GraphicsDevice.Create(FeatureLevel.GraphicsLevel11_0, null, DebugLayerConfiguration.Debug.WithDebugFlags(DebugFlags.DebugLayer | DebugFlags.GpuBasedValidation)); _output = Output.Create(OutputConfiguration.Default, _device, outputOwner); _camera = new(); const uint latency = 1; _graph = new RenderGraph(_device, latency); _worldPass = new WorldPass(_device, _camera); _fxaaPass = new FxaaPass(_device); _outputPass = new TonemapPass(_output); }
TraceOutput TraceSSGI(RenderGraph renderGraph, HDCamera hdCamera, GlobalIllumination giSettings, TextureHandle depthPyramid, TextureHandle normalBuffer, TextureHandle motionVectorsBuffer) { using (var builder = renderGraph.AddRenderPass <TraceSSGIPassData>("Trace SSGI", out var passData, ProfilingSampler.Get(HDProfileId.SSGITrace))) { builder.EnableAsyncCompute(false); passData.parameters = PrepareSSGITraceParameters(hdCamera, giSettings); passData.depthTexture = builder.ReadTexture(depthPyramid); passData.normalBuffer = builder.ReadTexture(normalBuffer); passData.motionVectorsBuffer = builder.ReadTexture(motionVectorsBuffer); var colorPyramid = hdCamera.GetPreviousFrameRT((int)HDCameraFrameHistoryType.ColorBufferMipChain); passData.colorPyramid = colorPyramid != null?builder.ReadTexture(renderGraph.ImportTexture(colorPyramid)) : renderGraph.defaultResources.blackTextureXR; var historyDepth = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.Depth); passData.historyDepth = historyDepth != null?builder.ReadTexture(renderGraph.ImportTexture(historyDepth)) : renderGraph.defaultResources.blackTextureXR; passData.hitPointBuffer = builder.CreateTransientTexture(new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite = true, name = "SSGI Hit Point" }); passData.outputBuffer0 = builder.WriteTexture(renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite = true, name = "SSGI Signal0" })); passData.outputBuffer1 = builder.WriteTexture(renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite = true, name = "SSGI Signal1" })); builder.SetRenderFunc( (TraceSSGIPassData data, RenderGraphContext ctx) => { // We need to fill the structure that holds the various resources SSGITraceResources resources = new SSGITraceResources(); resources.depthTexture = data.depthTexture; resources.normalBuffer = data.normalBuffer; resources.motionVectorsBuffer = data.motionVectorsBuffer; resources.colorPyramid = data.colorPyramid; resources.historyDepth = data.historyDepth; resources.hitPointBuffer = data.hitPointBuffer; resources.outputBuffer0 = data.outputBuffer0; resources.outputBuffer1 = data.outputBuffer1; ExecuteSSGITrace(ctx.cmd, data.parameters, resources); }); TraceOutput traceOutput = new TraceOutput(); traceOutput.outputBuffer0 = passData.outputBuffer0; traceOutput.outputBuffer1 = passData.outputBuffer1; return(traceOutput); } }
// Albedo + SSS Profile and mask / Specular occlusion (when no SSS) // This will be used during GBuffer and/or forward passes. RenderGraphMutableResource CreateSSSBuffer(RenderGraph renderGraph, bool msaa) { return(renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R8G8B8A8_SRGB, enableRandomWrite = !msaa, bindTextureMS = msaa, enableMSAA = msaa, clearBuffer = NeedClearGBuffer(), clearColor = Color.clear, name = string.Format("SSSBuffer{0}", msaa ? "MSAA" : "") } )); }
void PushGlobalCameraParams(RenderGraph renderGraph, HDCamera hdCamera) { using (var builder = renderGraph.AddRenderPass <PushGlobalCameraParamPassData>("Push Global Camera Parameters", out var passData)) { passData.hdCamera = hdCamera; passData.frameCount = m_FrameCount; builder.SetRenderFunc( (PushGlobalCameraParamPassData data, RenderGraphContext context) => { data.hdCamera.SetupGlobalParams(context.cmd, data.frameCount); }); } }
protected override IRenderer CreateRenderGraph() { // define renderers var renderers = GetRenderers(_config); renderers.ForEach(renderer => { (renderer as IRgb24Destination)?.SetPalette(new[] { Color.FromRgb(0x0, 0x0, 0xff), Color.FromRgb(0xff, 0x0, 0x0), }); }); // retrieve image var bmp = new BitmapImage(); bmp.BeginInit(); bmp.UriSource = new Uri("pack://application:,,,/dmdext;component/Test/TestImage.png"); bmp.EndInit(); // chain them up if (_config.VirtualAlphaNumericDisplay.Enabled) { var alphaNumericFrame = new AlphaNumericFrame(NumericalLayout.__2x20Alpha, new ushort[] { 0, 10767, 2167, 8719, 0, 2109, 8713, 6259, 56, 2157, 0, 4957, 0, 8719, 62, 8719, 121, 2157, 0, 0, 0, 0, 5120, 8704, 16640, 0, 0, 0, 0, 2112, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }); _graph = new RenderGraph { Source = new VpmAlphaNumericSource(alphaNumericFrame), Destinations = renderers, Resize = _config.Global.Resize, FlipHorizontally = _config.Global.FlipHorizontally, FlipVertically = _config.Global.FlipVertically }; } else { _graph = new RenderGraph { Source = new ImageSource(bmp), Destinations = renderers, Resize = _config.Global.Resize, FlipHorizontally = _config.Global.FlipHorizontally, FlipVertically = _config.Global.FlipVertically }; } return(_graph); }
public TextureHandle DenoiseBufferSphere(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle depthBuffer, TextureHandle normalBuffer, TextureHandle noisyBuffer, TextureHandle distanceBuffer, int kernelSize, Vector3 lightPosition, float lightRadius) { using (var builder = renderGraph.AddRenderPass <DiffuseShadowDenoiserSpherePassData>("DiffuseDenoiser", out var passData, ProfilingSampler.Get(HDProfileId.DiffuseFilter))) { // Cannot run in async builder.EnableAsyncCompute(false); // Fetch all the resources passData.parameters = PrepareDiffuseShadowSphereDenoiserParameters(hdCamera, lightPosition, lightRadius, kernelSize); // Input buffers passData.depthStencilBuffer = builder.UseDepthBuffer(depthBuffer, DepthAccess.Read); passData.normalBuffer = builder.ReadTexture(normalBuffer); passData.distanceBuffer = builder.ReadTexture(distanceBuffer); passData.noisyBuffer = builder.ReadTexture(noisyBuffer); // Temporary buffers passData.intermediateBuffer = builder.CreateTransientTexture(new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite = true, name = "Intermediate buffer" }); // Output buffer passData.outputBuffer = builder.ReadWriteTexture(renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite = true, name = "Denoised Buffer" })); builder.SetRenderFunc( (DiffuseShadowDenoiserSpherePassData data, RenderGraphContext ctx) => { DiffuseShadowSphereDenoiserResources resources = new DiffuseShadowSphereDenoiserResources(); resources.depthStencilBuffer = data.depthStencilBuffer; resources.normalBuffer = data.normalBuffer; resources.distanceBuffer = data.distanceBuffer; resources.noisyBuffer = data.noisyBuffer; resources.intermediateBuffer = data.intermediateBuffer; resources.outputBuffer = data.outputBuffer; ExecuteDiffuseShadowSphereDenoiser(ctx.cmd, data.parameters, resources); }); return(passData.outputBuffer); } }
public TextureHandle Denoise(RenderGraph renderGraph, HDCamera hdCamera, TemporalFilterParameters tfParameters, TextureHandle noisyBuffer, TextureHandle velocityBuffer, TextureHandle historyBuffer, TextureHandle depthBuffer, TextureHandle normalBuffer, TextureHandle motionVectorBuffer, TextureHandle historyValidationBuffer) { using (var builder = renderGraph.AddRenderPass <TemporalFilterPassData>("TemporalDenoiser", out var passData, ProfilingSampler.Get(HDProfileId.TemporalFilter))) { // Cannot run in async builder.EnableAsyncCompute(false); // Fetch all the resources passData.parameters = tfParameters; // Prepass Buffers passData.depthStencilBuffer = builder.ReadTexture(depthBuffer); passData.normalBuffer = builder.ReadTexture(normalBuffer); passData.motionVectorBuffer = builder.ReadTexture(motionVectorBuffer); // Effect buffers passData.velocityBuffer = builder.ReadTexture(velocityBuffer); passData.noisyBuffer = builder.ReadTexture(noisyBuffer); passData.validationBuffer = builder.ReadTexture(historyValidationBuffer); // History buffer passData.historyBuffer = builder.ReadWriteTexture(historyBuffer); // Output buffers passData.outputBuffer = builder.ReadWriteTexture(renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite = true, name = "Temporal Filter Output" })); builder.SetRenderFunc( (TemporalFilterPassData data, RenderGraphContext ctx) => { TemporalFilterResources tfResources = new TemporalFilterResources(); tfResources.depthStencilBuffer = data.depthStencilBuffer; tfResources.normalBuffer = data.normalBuffer; tfResources.velocityBuffer = data.velocityBuffer; tfResources.motionVectorBuffer = data.motionVectorBuffer; tfResources.noisyBuffer = data.noisyBuffer; tfResources.validationBuffer = data.validationBuffer; tfResources.historyBuffer = data.historyBuffer; tfResources.outputBuffer = data.outputBuffer; DenoiseBuffer(ctx.cmd, data.parameters, tfResources); }); return(passData.outputBuffer); } }
void RenderAccumulation(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle inputTexture, TextureHandle outputTexture, List <Tuple <TextureHandle, HDCameraFrameHistoryType> > AOVs, bool needExposure) { int camID = hdCamera.camera.GetInstanceID(); Vector4 frameWeights = m_SubFrameManager.ComputeFrameWeights(camID); if (AOVs != null) { foreach (var aov in AOVs) { RenderAccumulation(renderGraph, hdCamera, aov.Item1, TextureHandle.nullHandle, aov.Item2, frameWeights, needExposure); } } RenderAccumulation(renderGraph, hdCamera, inputTexture, outputTexture, HDCameraFrameHistoryType.PathTracing, frameWeights, needExposure); }
internal static void GenerateMipmaps(RenderGraph renderGraph, TextureHandle texture) { using (var builder = renderGraph.AddRenderPass <GenerateMipmapsPassData>("Generate Mipmaps", out var passData)) { passData.texture = builder.ReadWriteTexture(texture); builder.SetRenderFunc( (GenerateMipmapsPassData data, RenderGraphContext context) => { RTHandle tex = data.texture; Debug.Assert(tex.rt.autoGenerateMips == false); context.cmd.GenerateMips(tex); }); } }
internal TextureHandle CreateScreenSpaceShadowTextureArray(RenderGraph renderGraph) { int numShadowTextures = Math.Max((int)Math.Ceiling(m_Asset.currentPlatformRenderPipelineSettings.hdShadowInitParams.maxScreenSpaceShadowSlots / 4.0f), 1); GraphicsFormat graphicsFormat = (GraphicsFormat)m_Asset.currentPlatformRenderPipelineSettings.hdShadowInitParams.screenSpaceShadowBufferFormat; return(renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true) { colorFormat = graphicsFormat, slices = numShadowTextures * TextureXR.slices, dimension = TextureDimension.Tex2DArray, filterMode = FilterMode.Point, enableRandomWrite = true, useMipMap = false, name = "ScreenSpaceShadowArrayBuffer" })); }