public static void DrawFullScreen(CommandBuffer commandBuffer, RTHandleProperties rtHandleProperties, Material material, RenderTargetIdentifier colorBuffer, MaterialPropertyBlock properties = null, int shaderPassId = 0) { CoreUtils.SetRenderTarget(commandBuffer, colorBuffer); commandBuffer.SetGlobalVector(HDShaderIDs._RTHandleScale, rtHandleProperties.rtHandleScale); commandBuffer.DrawProcedural(Matrix4x4.identity, material, shaderPassId, MeshTopology.Triangles, 3, 1, properties); }
RenderAOParameters PrepareRenderAOParameters(HDCamera camera, RTHandleProperties rtHandleProperties, Vector2 historySize, int frameCount) { var parameters = new RenderAOParameters(); // Grab current settings var settings = camera.volumeStack.GetComponent <AmbientOcclusion>(); parameters.fullResolution = settings.fullResolution; if (parameters.fullResolution) { parameters.runningRes = new Vector2(camera.actualWidth, camera.actualHeight); parameters.aoBufferInfo = new Vector4(camera.actualWidth, camera.actualHeight, 1.0f / camera.actualWidth, 1.0f / camera.actualHeight); } else { parameters.runningRes = new Vector2(camera.actualWidth, camera.actualHeight) * 0.5f; parameters.aoBufferInfo = new Vector4(camera.actualWidth * 0.5f, camera.actualHeight * 0.5f, 2.0f / camera.actualWidth, 2.0f / camera.actualHeight); } float invHalfTanFOV = -camera.mainViewConstants.projMatrix[1, 1]; float aspectRatio = parameters.runningRes.y / parameters.runningRes.x; parameters.aoParams0 = new Vector4( parameters.fullResolution ? 0.0f : 1.0f, parameters.runningRes.y * invHalfTanFOV * 0.25f, settings.radius.value, settings.stepCount ); parameters.aoParams1 = new Vector4( settings.intensity.value, 1.0f / (settings.radius.value * settings.radius.value), (frameCount / 6) % 4, (frameCount % 6) ); // We start from screen space position, so we bake in this factor the 1 / resolution as well. parameters.toViewSpaceProj = new Vector4( 2.0f / (invHalfTanFOV * aspectRatio * parameters.runningRes.x), 2.0f / (invHalfTanFOV * parameters.runningRes.y), 1.0f / (invHalfTanFOV * aspectRatio), 1.0f / invHalfTanFOV ); float scaleFactor = (parameters.runningRes.x * parameters.runningRes.y) / (540.0f * 960.0f); float radInPixels = Mathf.Max(16, settings.maximumRadiusInPixels * Mathf.Sqrt(scaleFactor)); parameters.aoParams2 = new Vector4( historySize.x, historySize.y, 1.0f / (settings.stepCount + 1.0f), radInPixels ); float stepSize = m_RunningFullRes ? 1 : 0.5f; float blurTolerance = 1.0f - settings.blurSharpness.value; float maxBlurTolerance = 0.25f; float minBlurTolerance = -2.5f; blurTolerance = minBlurTolerance + (blurTolerance * (maxBlurTolerance - minBlurTolerance)); float bTolerance = 1f - Mathf.Pow(10f, blurTolerance) * stepSize; bTolerance *= bTolerance; const float upsampleTolerance = -7.0f; // TODO: Expose? float uTolerance = Mathf.Pow(10f, upsampleTolerance); float noiseFilterWeight = 1f / (Mathf.Pow(10f, 0.0f) + uTolerance); parameters.aoParams3 = new Vector4( bTolerance, uTolerance, noiseFilterWeight, stepSize ); float upperNudgeFactor = 1.0f - settings.ghostingReduction.value; const float maxUpperNudgeLimit = 5.0f; const float minUpperNudgeLimit = 0.25f; upperNudgeFactor = minUpperNudgeLimit + (upperNudgeFactor * (maxUpperNudgeLimit - minUpperNudgeLimit)); parameters.aoParams4 = new Vector4( settings.directionCount, upperNudgeFactor, minUpperNudgeLimit, 0 ); var hdrp = (RenderPipelineManager.currentPipeline as HDRenderPipeline); var depthMipInfo = hdrp.sharedRTManager.GetDepthBufferMipChainInfo(); parameters.firstAndSecondMipOffsets = new Vector4(depthMipInfo.mipLevelOffsets[1].x, depthMipInfo.mipLevelOffsets[1].y, depthMipInfo.mipLevelOffsets[2].x, depthMipInfo.mipLevelOffsets[2].y); parameters.bilateralUpsample = settings.bilateralUpsample; parameters.gtaoCS = m_Resources.shaders.GTAOCS; parameters.temporalAccumulation = settings.temporalAccumulation.value; if (parameters.temporalAccumulation) { if (parameters.fullResolution) { parameters.gtaoKernel = parameters.gtaoCS.FindKernel("GTAOMain_FullRes_Temporal"); } else { parameters.gtaoKernel = parameters.gtaoCS.FindKernel("GTAOMain_HalfRes_Temporal"); } } else { if (parameters.fullResolution) { parameters.gtaoKernel = parameters.gtaoCS.FindKernel("GTAOMain_FullRes"); } else { parameters.gtaoKernel = parameters.gtaoCS.FindKernel("GTAOMain_HalfRes"); } } parameters.upsampleAndBlurAOCS = m_Resources.shaders.GTAOBlurAndUpsample; parameters.denoiseAOCS = m_Resources.shaders.GTAODenoiseCS; parameters.denoiseKernelSpatial = parameters.denoiseAOCS.FindKernel(parameters.temporalAccumulation ? "GTAODenoise_Spatial_To_Temporal" : "GTAODenoise_Spatial"); parameters.denoiseKernelTemporal = parameters.denoiseAOCS.FindKernel(parameters.fullResolution ? "GTAODenoise_Temporal_FullRes" : "GTAODenoise_Temporal"); parameters.denoiseKernelCopyHistory = parameters.denoiseAOCS.FindKernel("GTAODenoise_CopyHistory"); parameters.upsampleAndBlurKernel = parameters.upsampleAndBlurAOCS.FindKernel("BlurUpsample"); parameters.upsampleAOKernel = parameters.upsampleAndBlurAOCS.FindKernel(settings.bilateralUpsample ? "BilateralUpsampling" : "BoxUpsampling"); parameters.outputWidth = camera.actualWidth; parameters.outputHeight = camera.actualHeight; parameters.viewCount = camera.viewCount; parameters.historyReady = m_HistoryReady; m_HistoryReady = true; // assumes that if this is called, then render is done as well. parameters.runAsync = camera.frameSettings.SSAORunsAsync(); parameters.motionVectorDisabled = !camera.frameSettings.IsEnabled(FrameSettingsField.MotionVectors); return(parameters); }
RenderAOParameters PrepareRenderAOParameters(HDCamera camera, RTHandleProperties rtHandleProperties, int frameCount) { var parameters = new RenderAOParameters(); // Grab current settings var settings = VolumeManager.instance.stack.GetComponent <AmbientOcclusion>(); parameters.fullResolution = settings.fullResolution.value; if (parameters.fullResolution) { parameters.runningRes = new Vector2(camera.actualWidth, camera.actualHeight); parameters.aoBufferInfo = new Vector4(camera.actualWidth, camera.actualHeight, 1.0f / camera.actualWidth, 1.0f / camera.actualHeight); } else { parameters.runningRes = new Vector2(camera.actualWidth, camera.actualHeight) * 0.5f; parameters.aoBufferInfo = new Vector4(camera.actualWidth * 0.5f, camera.actualHeight * 0.5f, 2.0f / camera.actualWidth, 2.0f / camera.actualHeight); } float invHalfTanFOV = -camera.mainViewConstants.projMatrix[1, 1]; float aspectRatio = parameters.runningRes.y / parameters.runningRes.x; parameters.aoParams0 = new Vector4( parameters.fullResolution ? 0.0f : 1.0f, parameters.runningRes.y * invHalfTanFOV * 0.25f, settings.radius.value, settings.stepCount.value ); parameters.aoParams1 = new Vector4( settings.intensity.value, 1.0f / (settings.radius.value * settings.radius.value), (frameCount / 6) % 4, (frameCount % 6) ); // We start from screen space position, so we bake in this factor the 1 / resolution as well. parameters.toViewSpaceProj = new Vector4( 2.0f / (invHalfTanFOV * aspectRatio * parameters.runningRes.x), 2.0f / (invHalfTanFOV * parameters.runningRes.y), 1.0f / (invHalfTanFOV * aspectRatio), 1.0f / invHalfTanFOV ); float radInPixels = Mathf.Max(16, settings.maximumRadiusInPixels.value * ((parameters.runningRes.x * parameters.runningRes.y) / (540.0f * 960.0f))); parameters.aoParams2 = new Vector4( rtHandleProperties.currentRenderTargetSize.x, rtHandleProperties.currentRenderTargetSize.y, 1.0f / (settings.stepCount.value + 1.0f), radInPixels ); parameters.gtaoCS = m_Resources.shaders.GTAOCS; parameters.gtaoKernel = parameters.gtaoCS.FindKernel("GTAOMain_HalfRes"); if (parameters.fullResolution) { parameters.gtaoKernel = parameters.gtaoCS.FindKernel("GTAOMain_FullRes"); } parameters.denoiseAOCS = m_Resources.shaders.GTAODenoiseCS; parameters.denoiseKernelSpatial = parameters.denoiseAOCS.FindKernel("GTAODenoise_Spatial"); parameters.denoiseKernelTemporal = parameters.denoiseAOCS.FindKernel(parameters.fullResolution ? "GTAODenoise_Temporal_FullRes" : "GTAODenoise_Temporal"); parameters.denoiseKernelCopyHistory = parameters.denoiseAOCS.FindKernel("GTAODenoise_CopyHistory"); parameters.upsampleAOCS = m_Resources.shaders.GTAOUpsampleCS; parameters.upsampleAOKernel = parameters.upsampleAOCS.FindKernel("AOUpsample"); parameters.outputWidth = camera.actualWidth; parameters.outputHeight = camera.actualHeight; parameters.viewCount = camera.viewCount; parameters.historyReady = m_HistoryReady; m_HistoryReady = true; // assumes that if this is called, then render is done as well. parameters.runAsync = camera.frameSettings.SSAORunsAsync(); return(parameters); }
RenderAOParameters PrepareRenderAOParameters(HDCamera camera, RTHandleProperties rtHandleProperties, Vector2 historySize, int frameCount) { var parameters = new RenderAOParameters(); ref var cb = ref parameters.cb;