// Populates a screen space mask which will inform the underwater postprocess. As a future optimisation we may // be able to avoid this pass completely if we can reuse the camera depth after transparents are rendered. internal static void PopulateOceanMask( CommandBuffer commandBuffer, Camera camera, List <OceanChunkRenderer> chunksToRender, Plane[] frustumPlanes, RTHandle colorBuffer, RTHandle depthBuffer, Material oceanMaskMaterial, bool debugDisableOceanMask ) { // Get all ocean chunks and render them using cmd buffer, but with mask shader CoreUtils.SetRenderTarget(commandBuffer, colorBuffer, depthBuffer); CoreUtils.ClearRenderTarget(commandBuffer, ClearFlag.All, Color.white * UNDERWATER_MASK_NO_MASK); if (!debugDisableOceanMask) { // Spends approx 0.2-0.3ms here on dell laptop foreach (OceanChunkRenderer chunk in chunksToRender) { Renderer renderer = chunk.Rend; Bounds bounds = renderer.bounds; if (GeometryUtility.TestPlanesAABB(frustumPlanes, bounds)) { if ((!chunk._oceanDataHasBeenBound) && chunk.enabled) { chunk.BindOceanData(camera); } commandBuffer.DrawRenderer(renderer, oceanMaskMaterial); } chunk._oceanDataHasBeenBound = false; } } commandBuffer.SetGlobalTexture(sp_CrestOceanMaskTexture, colorBuffer); commandBuffer.SetGlobalTexture(sp_CrestOceanMaskDepthTexture, depthBuffer); }
// This function is called from the custom post process at the before post process injection point, just after TAA public void RenderVideoObjects(CommandBuffer cmd) { // Fix depth buffer jittering if (fixDepthBufferJittering) { using (new ProfilingScope(cmd, new ProfilingSampler("Render Depth Buffer without jittering"))) { // We need to re-render everything to get the non-jittered depth buffer :/ CoreUtils.SetRenderTarget(cmd, videoDepthBuffer); CoreUtils.ClearRenderTarget(cmd, ClearFlag.Depth, Color.black); var tags = new ShaderTagId[] { new ShaderTagId("DepthForwardOnly"), new ShaderTagId("DepthOnly") }; var result = new RendererListDesc(tags, context.cullingResults, context.hdCamera.camera) { rendererConfiguration = PerObjectData.None, renderQueueRange = RenderQueueRange.all, sortingCriteria = SortingCriteria.CommonOpaque, excludeObjectMotionVectors = false, layerMask = fixDepthBufferJitteringMask, // stateBlock = overrideRenderState, }; CoreUtils.DrawRendererList(context.renderContext, context.cmd, RendererList.Create(result)); } } // TODO: add an option to render the "frame" objects in the unjittered depth-buffer to avoid flickering CoreUtils.SetRenderTarget(cmd, videoColorBuffer, fixDepthBufferJittering ? videoDepthBuffer : context.cameraDepthBuffer, ClearFlag.Color); var renderState = new RenderStateBlock(RenderStateMask.Depth) { depthState = new DepthState(false, CompareFunction.LessEqual) }; CustomPassUtils.DrawRenderers(context, videoObjectMask, overrideRenderState: renderState); }
public void CustomRender(ScriptableRenderContext context, HDCamera hd) { var camera = hd.camera; var cmd = CommandBufferPool.Get(); // NOTE: Target setting is done in BeginReadRequest through Camera.SetTargetBuffers. Doing it through // the command queue changes output slightly, probably should be debugged eventually (low priority). // CoreUtils.SetRenderTarget(cmd, activeTarget.colorTexture, activeTarget.depthTexture); hd.SetupGlobalParams(cmd, 0); ScriptableCullingParameters culling; if (camera.TryGetCullingParameters(out culling)) { var cull = context.Cull(ref culling); context.SetupCameraProperties(camera); CoreUtils.ClearRenderTarget(cmd, ClearFlag.All, Color.clear); context.ExecuteCommandBuffer(cmd); cmd.Clear(); var sorting = new SortingSettings(camera); var drawing = new DrawingSettings(new ShaderTagId("SimulatorLidarPass"), sorting); var filter = new FilteringSettings(RenderQueueRange.all); context.DrawRenderers(cull, ref drawing, ref filter); } PointCloudManager.RenderLidar(context, cmd, hd, activeTarget.colorTexture, activeTarget.depthTexture); CommandBufferPool.Release(cmd); }
// Here you can implement the rendering logic. // Use <c>ScriptableRenderContext</c> to issue drawing commands or execute command buffers // https://docs.unity3d.com/ScriptReference/Rendering.ScriptableRenderContext.html // You don't have to call ScriptableRenderContext.submit, the render pipeline will call it at specific points in the pipeline. public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { if (hbaoMaterial == null) { Debug.LogError("HBAO material has not been correctly initialized..."); return; } UpdateMaterialProperties(renderingData); var cmd = CommandBufferPool.Get("HBAO"); CoreUtils.SetRenderTarget(cmd, ShaderProperties.hbaoTex); CoreUtils.ClearRenderTarget(cmd, ClearFlag.Color, Color.white); Blit(cmd, source, ShaderProperties.inputTex); Blit(cmd, ShaderProperties.inputTex, ShaderProperties.hbaoTex, hbaoMaterial, passIndex: GetAoPassId()); if (settings.blurType != Blur.None) { Blit(cmd, ShaderProperties.hbaoTex, ShaderProperties.tempTex, hbaoMaterial, passIndex: GetBlurXPassId()); Blit(cmd, ShaderProperties.tempTex, ShaderProperties.hbaoTex, hbaoMaterial, passIndex: GetBlurYPassId()); } Blit(cmd, ShaderProperties.inputTex, source, hbaoMaterial, passIndex: GetCompositePassId()); context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
protected override void Execute(CustomPassContext ctx) { #region Draw Vertex Color // use MRT to render JTRP Shader after Opaque / Sky // CoreUtils.SetRenderTarget(ctx.cmd, _customBuffer); // CoreUtils.ClearRenderTarget(ctx.cmd, ClearFlag.Color, Color.white); // // CoreUtils.SetRenderTarget(ctx.cmd, new RenderTargetIdentifier[] {ctx.cameraColorBuffer, _customBuffer}, // ctx.cameraDepthBuffer); #endregion // render PP to tempBuffer and zhen copy back to cameraColor if (enablePPOutline) { SetupPPTempBuffer(ctx); CoreUtils.SetRenderTarget(ctx.cmd, _postProcessTempBuffer, ctx.cameraDepthBuffer); CoreUtils.ClearRenderTarget(ctx.cmd, ClearFlag.Color, Color.blue); DoPPOutline(ctx); BlitToCameraColorTexture(ctx, _postProcessTempBuffer); } // draw opaque var resultJTRPOpaque = new RendererListDesc(new ShaderTagId("JTRPLitToon"), ctx.cullingResults, ctx.hdCamera.camera) { rendererConfiguration = (PerObjectData) 2047, // all renderQueueRange = RenderQueueRange.opaque, sortingCriteria = SortingCriteria.CommonOpaque }; SetRenderTargetAuto(ctx.cmd); CoreUtils.DrawRendererList(ctx.renderContext, ctx.cmd, RendererList.Create(resultJTRPOpaque)); // Procedural Geometry Outline if (enableGeometryOutline) { if (enable3XDepth) { Setup3XDepthBuffer(); CoreUtils.SetRenderTarget(ctx.cmd, _depthBuffer, _depthBuffer); CoreUtils.ClearRenderTarget(ctx.cmd, ClearFlag.Depth, Color.black); var resultOpaqueDepthOnly = new RendererListDesc(new ShaderTagId("DepthOnly"), ctx.cullingResults, ctx.hdCamera.camera) { rendererConfiguration = (PerObjectData) 2047, // all renderQueueRange = RenderQueueRange.opaque, sortingCriteria = SortingCriteria.CommonOpaque }; CoreUtils.DrawRendererList(ctx.renderContext, ctx.cmd, RendererList.Create(resultOpaqueDepthOnly)); SetRenderTargetAuto(ctx.cmd); Shader.SetGlobalTexture(_camera3XDepthTexture, _depthBuffer); } DoGeometryOutline(ctx); } }
private static void SetViewportAndClear(CommandBuffer cmd, HDCamera camera, RTHandleSystem.RTHandle buffer, ClearFlag clearFlag, Color clearColor) { // Clearing a partial viewport currently does not go through the hardware clear. // Instead it goes through a quad rendered with a specific shader. // When enabling wireframe mode in the scene view, unfortunately it overrides this shader thus breaking every clears. // That's why in the editor we don't set the viewport before clearing (it's set to full screen by the previous SetRenderTarget) but AFTER so that we benefit from un-bugged hardware clear. // We consider that the small loss in performance is acceptable in the editor. // A refactor of wireframe is needed before we can fix this properly (with not doing anything!) #if !UNITY_EDITOR SetViewport(cmd, camera, buffer); #endif CoreUtils.ClearRenderTarget(cmd, clearFlag, clearColor); #if UNITY_EDITOR SetViewport(cmd, camera, buffer); #endif }
void CustomRender(ScriptableRenderContext context, HDCamera camera) { var cmd = CommandBufferPool.Get(_label); cmd.SetViewport(new Rect(0, 0, Screen.width, Screen.height)); CoreUtils.ClearRenderTarget(cmd, ClearFlag.All, Color.clear); HDUtils.BlitQuad( cmd, _source, new Vector4(1, 1, 0, 0), new Vector4(1, -1, 0, 1), 0, true ); context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
void CustomRender(ScriptableRenderContext context, HDCamera hd) { var camera = hd.camera; var cmd = CommandBufferPool.Get(); hd.SetupGlobalParams(cmd, 0); if (!Fisheye) { CoreUtils.SetRenderTarget(cmd, renderTarget.ColorHandle, renderTarget.DepthHandle); } CoreUtils.ClearRenderTarget(cmd, ClearFlag.All, Color.clear); ScriptableCullingParameters culling; if (camera.TryGetCullingParameters(out culling)) { var cull = context.Cull(ref culling); context.SetupCameraProperties(camera); context.ExecuteCommandBuffer(cmd); cmd.Clear(); var sorting = new SortingSettings(camera); var drawing = new DrawingSettings(new ShaderTagId("SimulatorDepthPass"), sorting); var filter = new FilteringSettings(RenderQueueRange.all); context.DrawRenderers(cull, ref drawing, ref filter); } if (!Fisheye) { PointCloudManager.RenderDepth(context, cmd, hd, renderTarget.ColorHandle, renderTarget.DepthHandle); } CommandBufferPool.Release(cmd); }
// Here you can implement the rendering logic. // Use <c>ScriptableRenderContext</c> to issue drawing commands or execute command buffers // https://docs.unity3d.com/ScriptReference/Rendering.ScriptableRenderContext.html // You don't have to call ScriptableRenderContext.submit, the render pipeline will call it at specific points in the pipeline. public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { if (material == null) { Debug.LogError("Material has not been correctly initialized..."); return; } var cmd = CommandBufferPool.Get("CameraNormals"); var sourceTexId = Shader.PropertyToID("_SourceTex"); cmd.GetTemporaryRT(sourceTexId, sourceDesc); Blit(cmd, source, sourceTexId); CoreUtils.SetRenderTarget(cmd, renderTarget); CoreUtils.ClearRenderTarget(cmd, ClearFlag.All, new Color(0.5f, 0.5f, 1f)); context.ExecuteCommandBuffer(cmd); cmd.Clear(); var drawingSettings = CreateDrawingSettings(m_ShaderTagId, ref renderingData, renderingData.cameraData.defaultOpaqueSortFlags); drawingSettings.overrideMaterial = material; drawingSettings.overrideMaterialPassIndex = 0; context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref m_FilteringSettings, ref m_RenderStateBlock); Blit(cmd, sourceTexId, source); cmd.ReleaseTemporaryRT(sourceTexId); cmd.SetGlobalTexture(Shader.PropertyToID("_CameraNormalsTexture"), renderTarget); context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
private void RenderSolidCore( CommandBuffer cmd, HDCamera targetCamera, RTHandle cameraColorBuffer, bool calculateNormals, bool smoothNormals, ViewportSettings viewportSettings) { var rt = Resources.GetRTHandle(RTUsage.PointRender); var rt1 = Resources.GetRTHandle(RTUsage.Generic0); var rt2 = Resources.GetRTHandle(RTUsage.Generic1); var rtColor = Resources.GetRTHandle(RTUsage.ColorBuffer); var rtDepth = Resources.GetRTHandle(RTUsage.DepthBuffer); var rtDepth2 = Resources.GetRTHandle(RTUsage.DepthBuffer2); // TODO: handle resolutions above reference size // Custom cubemap target can have resolution higher than RT reference size, in which case it will be cut var width = viewportSettings.width; var height = viewportSettings.height; var refSize = rt.referenceSize; var msaaSamples = ((HDRenderPipeline)RenderPipelineManager.currentPipeline).MSAASamples; // TODO: verify if this is still needed after updating HDRP above 10.3.2 // In previous versions (7.3) viewport size was updated automatically - now it has to be manually managed // This can have critical performance impact if new MSAA samples settings don't not match current settings RTHandles.SetReferenceSize(width, height, msaaSamples); var resolution = new Vector2Int(width, height); var rtHandleRefSize = new Vector2Int(RTHandles.maxWidth, RTHandles.maxHeight); var refToCurrent = new Vector2((float)rtHandleRefSize.x / width, (float)rtHandleRefSize.y / height); var fov = viewportSettings.fieldOfView; if (SolidFovReprojection) { fov *= ReprojectionRatio; } var size = Math.Max(width, height); var maxLevel = 0; while (size >> maxLevel >= 16) { maxLevel++; } CalculateMatrices(targetCamera, viewportSettings, out var projMatrix, out var invProjMatrix, out var invViewMatrix, out var invViewProjMatrix, out var solidRenderMvp); var cs = Resources.SolidComputeShader; cmd.SetComputeVectorParam(cs, PointCloudShaderIDs.SolidCompute.TextureSize, new Vector4(width, height, 1f / width, 1f / height)); cmd.SetComputeVectorParam(cs, PointCloudShaderIDs.SolidCompute.RefSizeMult, new Vector4(refToCurrent.x, refToCurrent.y, 1 / refToCurrent.x, 1 / refToCurrent.y)); cmd.SetComputeVectorParam(cs, PointCloudShaderIDs.SolidCompute.FullRTSize, new Vector4(refSize.x - 1, refSize.y - 1, 1f / refSize.x, 1f / refSize.y)); cmd.SetComputeFloatParam(cs, PointCloudShaderIDs.SolidCompute.FarPlane, targetCamera.camera.farClipPlane); cmd.SetComputeMatrixParam(cs, PointCloudShaderIDs.SolidCompute.ProjectionMatrix, projMatrix); cmd.SetComputeMatrixParam(cs, PointCloudShaderIDs.SolidCompute.InverseProjectionMatrix, invProjMatrix); cmd.SetComputeMatrixParam(cs, PointCloudShaderIDs.SolidCompute.InverseViewMatrix, invViewMatrix); cmd.SetComputeMatrixParam(cs, PointCloudShaderIDs.SolidCompute.InverseVPMatrix, invViewProjMatrix); cmd.SetComputeVectorParam(cs, PointCloudShaderIDs.SolidCompute.InverseReprojectionVector, GetInverseUvFovReprojectionVector(viewportSettings)); cmd.SetGlobalBuffer(PointCloudShaderIDs.Shared.Buffer, GetBufferForCamera(targetCamera)); cmd.SetGlobalInt(PointCloudShaderIDs.Shared.Colorize, (int)Colorize); cmd.SetGlobalFloat(PointCloudShaderIDs.Shared.MinHeight, Bounds.min.y); cmd.SetGlobalFloat(PointCloudShaderIDs.Shared.MaxHeight, Bounds.max.y); cmd.SetGlobalMatrix(PointCloudShaderIDs.SolidRender.MVPMatrix, solidRenderMvp); if (ForcedFill == ForcedFillMode.HorizonAndDepth || SolidRemoveHidden && HiddenPointRemoval == HprMode.DepthPrepass) { SetCirclesMaterialProperties(cmd, targetCamera); CoreUtils.SetRenderTarget(cmd, rt2, rtDepth2); CoreUtils.ClearRenderTarget(cmd, ClearFlag.All, Color.clear); var pass = Resources.Passes.circlesDepthPrepass; cmd.DrawProcedural(Matrix4x4.identity, Resources.CirclesMaterial, pass, MeshTopology.Points, GetPointCountForCamera(targetCamera)); } if (ForcedFill == ForcedFillMode.HorizonAndDepth) { var setupCopyFill = Resources.Kernels.Setup; cmd.SetComputeTextureParam(cs, setupCopyFill, PointCloudShaderIDs.SolidCompute.SetupCopy.InputPosition, rtDepth2, 0); cmd.SetComputeTextureParam(cs, setupCopyFill, PointCloudShaderIDs.SolidCompute.SetupCopy.OutputPosition, rt1, 0); cmd.DispatchCompute(cs, setupCopyFill, GetGroupSize(width, 8), GetGroupSize(height, 8), 1); // Prepare rough depth with hole fixing var downsample = Resources.Kernels.Downsample; for (var i = 1; i <= maxLevel + 3; i++) { GetMipData(resolution, i - 1, out var mipRes, out var mipVec); cmd.SetComputeVectorParam(cs, PointCloudShaderIDs.SolidCompute.MipTextureSize, mipVec); cmd.SetComputeTextureParam(cs, downsample, PointCloudShaderIDs.SolidCompute.Downsample.InputPosition, rt1, i - 1); cmd.SetComputeTextureParam(cs, downsample, PointCloudShaderIDs.SolidCompute.Downsample.OutputPosition, rt1, i); cmd.DispatchCompute(cs, downsample, GetGroupSize(mipRes.x, 16), GetGroupSize(mipRes.y, 16), 1); } var fillHolesKernel = Resources.Kernels.FillRoughDepth; GetMipData(resolution, 4, out var gmipRes, out var higherMipVec); GetMipData(resolution, 4 - 1, out _, out var gmipVec); cmd.SetComputeVectorParam(cs, PointCloudShaderIDs.SolidCompute.MipTextureSize, gmipVec); cmd.SetComputeVectorParam(cs, PointCloudShaderIDs.SolidCompute.HigherMipTextureSize, higherMipVec); cmd.SetComputeTextureParam(cs, fillHolesKernel, PointCloudShaderIDs.SolidCompute.FillRoughHoles.TexIn, rt1); cmd.SetComputeTextureParam(cs, fillHolesKernel, PointCloudShaderIDs.SolidCompute.FillRoughHoles.TexOut, rt2, 4); cmd.DispatchCompute(cs, fillHolesKernel, GetGroupSize(gmipRes.x, 8), GetGroupSize(gmipRes.y, 8), 1); } CoreUtils.SetRenderTarget(cmd, rt, rtDepth); CoreUtils.ClearRenderTarget(cmd, ClearFlag.All, Color.clear); cmd.DrawProcedural(Matrix4x4.identity, Resources.SolidRenderMaterial, 0, MeshTopology.Points, GetPointCountForCamera(targetCamera)); var setupCopy = Resources.Kernels.Setup; cmd.SetComputeTextureParam(cs, setupCopy, PointCloudShaderIDs.SolidCompute.SetupCopy.InputPosition, rtDepth, 0); cmd.SetComputeTextureParam(cs, setupCopy, PointCloudShaderIDs.SolidCompute.SetupCopy.OutputPosition, rt1, 0); cmd.DispatchCompute(cs, setupCopy, GetGroupSize(width, 8), GetGroupSize(height, 8), 1); var blendSky = DebugBlendSky && cameraColorBuffer != null; var skyBlend = Resources.Kernels.GetSkyBlendKernel(ForcedFill, blendSky); cmd.SetComputeTextureParam(cs, skyBlend, PointCloudShaderIDs.SolidCompute.SkyBlend.ViewPos, rt1, 0); cmd.SetComputeTextureParam(cs, skyBlend, PointCloudShaderIDs.SolidCompute.SkyBlend.ColorIn, rt, 0); cmd.SetComputeTextureParam(cs, skyBlend, PointCloudShaderIDs.SolidCompute.SkyBlend.ColorOut, rtColor, 0); if (blendSky) { cmd.SetComputeTextureParam(cs, skyBlend, PointCloudShaderIDs.SolidCompute.SkyBlend.PostSkyPreRenderTexture, cameraColorBuffer, 0); } if (ForcedFill == ForcedFillMode.HorizonAndDepth) { cmd.SetComputeTextureParam(cs, skyBlend, PointCloudShaderIDs.SolidCompute.SkyBlend.RoughDepth, rt2, 0); } cmd.SetComputeFloatParam(cs, PointCloudShaderIDs.SolidCompute.SkyBlend.HorizonThreshold, DebugFillThreshold); cmd.DispatchCompute(cs, skyBlend, GetGroupSize(width, 8), GetGroupSize(height, 8), 1); if (SolidRemoveHidden) { switch (HiddenPointRemoval) { case HprMode.ScreenSpace: { var downsample = Resources.Kernels.Downsample; for (var i = 1; i <= maxLevel + 3; i++) { GetMipData(resolution, i - 1, out var mipRes, out var mipVec); cmd.SetComputeVectorParam(cs, PointCloudShaderIDs.SolidCompute.MipTextureSize, mipVec); cmd.SetComputeTextureParam(cs, downsample, PointCloudShaderIDs.SolidCompute.Downsample.InputPosition, rt1, i - 1); cmd.SetComputeTextureParam(cs, downsample, PointCloudShaderIDs.SolidCompute.Downsample.OutputPosition, rt1, i); cmd.DispatchCompute(cs, downsample, GetGroupSize(mipRes.x, 16), GetGroupSize(mipRes.y, 16), 1); } DebugSolidFixedLevel = Math.Min(Math.Max(DebugSolidFixedLevel, 0), maxLevel); var removeHidden = Resources.Kernels.GetRemoveHiddenKernel(DebugShowRemoveHiddenCascades); var removeHiddenMagic = RemoveHiddenCascadeOffset * height * 0.5f / Mathf.Tan(0.5f * fov * Mathf.Deg2Rad); cmd.SetComputeIntParam(cs, PointCloudShaderIDs.SolidCompute.RemoveHidden.LevelCount, maxLevel); cmd.SetComputeTextureParam(cs, removeHidden, PointCloudShaderIDs.SolidCompute.RemoveHidden.Position, rt1); cmd.SetComputeTextureParam(cs, removeHidden, PointCloudShaderIDs.SolidCompute.RemoveHidden.PositionRough, rt1); cmd.SetComputeTextureParam(cs, removeHidden, PointCloudShaderIDs.SolidCompute.RemoveHidden.Color, rtColor, 0); cmd.SetComputeFloatParam(cs, PointCloudShaderIDs.SolidCompute.RemoveHidden.CascadesOffset, removeHiddenMagic); cmd.SetComputeFloatParam(cs, PointCloudShaderIDs.SolidCompute.RemoveHidden.CascadesSize, RemoveHiddenCascadeSize); cmd.SetComputeIntParam(cs, PointCloudShaderIDs.SolidCompute.RemoveHidden.FixedLevel, DebugSolidFixedLevel); cmd.DispatchCompute(cs, removeHidden, GetGroupSize(width, 8), GetGroupSize(height, 8), 1); } break; case HprMode.DepthPrepass: { var removeHidden = Resources.Kernels.RemoveHiddenDepthPrepass; cmd.SetComputeTextureParam(cs, removeHidden, PointCloudShaderIDs.SolidCompute.RemoveHidden.Position, rt1); cmd.SetComputeTextureParam(cs, removeHidden, PointCloudShaderIDs.SolidCompute.RemoveHidden.EarlyDepth, rtDepth2, 0); cmd.SetComputeTextureParam(cs, removeHidden, PointCloudShaderIDs.SolidCompute.RemoveHidden.Color, rtColor, 0); cmd.SetComputeFloatParam(cs, PointCloudShaderIDs.SolidCompute.RemoveHidden.PointScale, AbsoluteSize); cmd.DispatchCompute(cs, removeHidden, GetGroupSize(width, 8), GetGroupSize(height, 8), 1); } break; default: throw new ArgumentOutOfRangeException(); } } if (DebugSolidPullPush) { var pullKernel = Resources.Kernels.Pull; cmd.SetComputeFloatParam(cs, PointCloudShaderIDs.SolidCompute.PullKernel.FilterExponent, DebugSolidPullParam); for (var i = 1; i <= maxLevel; i++) { GetMipData(resolution, i, out var mipRes, out var higherMipVec); GetMipData(resolution, i - 1, out _, out var mipVec); cmd.SetComputeVectorParam(cs, PointCloudShaderIDs.SolidCompute.MipTextureSize, mipVec); cmd.SetComputeVectorParam(cs, PointCloudShaderIDs.SolidCompute.HigherMipTextureSize, higherMipVec); cmd.SetComputeIntParam(cs, PointCloudShaderIDs.SolidCompute.PullKernel.SkipWeightMul, i == maxLevel ? 1 : 0); cmd.SetComputeTextureParam(cs, pullKernel, PointCloudShaderIDs.SolidCompute.PullKernel.InputColor, rtColor, i - 1); cmd.SetComputeTextureParam(cs, pullKernel, PointCloudShaderIDs.SolidCompute.PullKernel.OutputColor, rtColor, i); cmd.DispatchCompute(cs, pullKernel, GetGroupSize(mipRes.x, 8), GetGroupSize(mipRes.y, 8), 1); } var pushKernel = Resources.Kernels.Push; for (var i = maxLevel; i > 0; i--) { GetMipData(resolution, i - 1, out var mipRes, out var mipVec); GetMipData(resolution, i, out _, out var lowerMipVec); cmd.SetComputeVectorParam(cs, PointCloudShaderIDs.SolidCompute.MipTextureSize, mipVec); cmd.SetComputeVectorParam(cs, PointCloudShaderIDs.SolidCompute.HigherMipTextureSize, lowerMipVec); cmd.SetComputeIntParam(cs, PointCloudShaderIDs.SolidCompute.PushKernel.InputLevel, i); cmd.SetComputeTextureParam(cs, pushKernel, PointCloudShaderIDs.SolidCompute.PushKernel.InputColor, rtColor, i); cmd.SetComputeTextureParam(cs, pushKernel, PointCloudShaderIDs.SolidCompute.PushKernel.OutputColor, rtColor, i - 1); cmd.DispatchCompute(cs, pushKernel, GetGroupSize(mipRes.x, 8), GetGroupSize(mipRes.y, 8), 1); } if (calculateNormals) { var calculateNormalsKernel = Resources.Kernels.CalculateNormals; var normalsTarget = smoothNormals ? rt2 : rt1; for (var i = 0; i < maxLevel; ++i) { GetMipData(resolution, i, out var mipRes, out var mipVec); cmd.SetComputeVectorParam(cs, PointCloudShaderIDs.SolidCompute.MipTextureSize, mipVec); cmd.SetComputeIntParam(cs, PointCloudShaderIDs.SolidCompute.CalculateNormals.InputLevel, i); cmd.SetComputeTextureParam(cs, calculateNormalsKernel, PointCloudShaderIDs.SolidCompute.CalculateNormals.Input, rtColor); cmd.SetComputeTextureParam(cs, calculateNormalsKernel, PointCloudShaderIDs.SolidCompute.CalculateNormals.Output, normalsTarget, i); cmd.DispatchCompute(cs, calculateNormalsKernel, GetGroupSize(mipRes.x, 8), GetGroupSize(mipRes.x, 8), 1); } if (smoothNormals) { var smoothNormalsKernel = Resources.Kernels.GetSmoothNormalsKernel(DebugShowSmoothNormalsCascades); var smoothNormalsMagic = SmoothNormalsCascadeOffset * height * 0.5f / Mathf.Tan(0.5f * fov * Mathf.Deg2Rad); cmd.SetComputeTextureParam(cs, smoothNormalsKernel, PointCloudShaderIDs.SolidCompute.SmoothNormals.Input, rt2); cmd.SetComputeTextureParam(cs, smoothNormalsKernel, PointCloudShaderIDs.SolidCompute.SmoothNormals.Output, rt1, 0); cmd.SetComputeFloatParam(cs, PointCloudShaderIDs.SolidCompute.SmoothNormals.CascadesOffset, smoothNormalsMagic); cmd.SetComputeFloatParam(cs, PointCloudShaderIDs.SolidCompute.SmoothNormals.CascadesSize, SmoothNormalsCascadeSize); if (DebugShowSmoothNormalsCascades) { cmd.SetComputeTextureParam(cs, smoothNormalsKernel, PointCloudShaderIDs.SolidCompute.SmoothNormals.ColorDebug, rtColor, 0); } cmd.DispatchCompute(cs, smoothNormalsKernel, GetGroupSize(width, 8), GetGroupSize(height, 8), 1); } } } }
public static void SetRenderTarget(CommandBuffer cmd, HDCamera camera, RenderTargetIdentifier[] colorBuffers, RTHandle depthBuffer, ClearFlag clearFlag, Color clearColor) { cmd.SetRenderTarget(colorBuffers, depthBuffer); SetViewport(cmd, camera, depthBuffer); CoreUtils.ClearRenderTarget(cmd, clearFlag, clearColor); }
// TODO // 1.Draw hair vertex color to custom mask buffer // 2.Draw face with hair buffer and shadow map protected override void Execute(CustomPassContext ctx) { var renderCtx = ctx.renderContext; // Draw Vertex Color Mask CoreUtils.SetRenderTarget(ctx.cmd, _customBuffer); CoreUtils.ClearRenderTarget(ctx.cmd, ClearFlag.Color, Color.black); var resultJTRPMask = new RendererListDesc(_shaderTagId_JTRPMask, ctx.cullingResults, ctx.hdCamera.camera) { rendererConfiguration = PerObjectData.None, renderQueueRange = RenderQueueRange.all, sortingCriteria = SortingCriteria.CommonTransparent, // layerMask = LayerMask.GetMask("Hair"), }; CoreUtils.DrawRendererList(renderCtx, ctx.cmd, renderCtx.CreateRendererList(resultJTRPMask)); // Draw UTS Face SetRenderTargetAuto(ctx.cmd); ctx.cmd.SetGlobalTexture(_jtrpMask_Map, _customBuffer); var resultJTRPFace = new RendererListDesc(_shaderTagId_JTRPFace, ctx.cullingResults, ctx.hdCamera.camera) { rendererConfiguration = (PerObjectData)2047, // all renderQueueRange = RenderQueueRange.all, sortingCriteria = SortingCriteria.CommonTransparent, // layerMask = LayerMask.GetMask("Face"), }; CoreUtils.DrawRendererList(renderCtx, ctx.cmd, renderCtx.CreateRendererList(resultJTRPFace)); // render PP to tempBuffer and zhen copy back to cameraColor if (enablePPOutline) { SetupPPTempBuffer(ctx); CoreUtils.SetRenderTarget(ctx.cmd, _postProcessTempBuffer, ctx.cameraDepthBuffer); CoreUtils.ClearRenderTarget(ctx.cmd, ClearFlag.Color, Color.blue); DoPPOutline(ctx); BlitToCameraColorTexture(ctx, _postProcessTempBuffer); } // Procedural Geometry Outline if (enableGeometryOutline) { if (enable3XDepth) { Setup3XDepthBuffer(); CoreUtils.SetRenderTarget(ctx.cmd, _depthBuffer, _depthBuffer); CoreUtils.ClearRenderTarget(ctx.cmd, ClearFlag.Depth, Color.black); var resultOpaqueDepthOnly = new RendererListDesc(new ShaderTagId("DepthOnly"), ctx.cullingResults, ctx.hdCamera.camera) { rendererConfiguration = (PerObjectData)2047, // all renderQueueRange = RenderQueueRange.opaque, sortingCriteria = SortingCriteria.CommonOpaque }; CoreUtils.DrawRendererList(renderCtx, ctx.cmd, renderCtx.CreateRendererList(resultOpaqueDepthOnly)); SetRenderTargetAuto(ctx.cmd); Shader.SetGlobalTexture(_camera3XDepthTexture, _depthBuffer); } DoGeometryOutline(ctx); } // Set BackFace Outline Shader.SetGlobalFloat("_JTRP_Enable_Global_BackFace_Outline", enableBackFaceOutline ? 1 : 0); }
// Here you can implement the rendering logic. // Use <c>ScriptableRenderContext</c> to issue drawing commands or execute command buffers // https://docs.unity3d.com/ScriptReference/Rendering.ScriptableRenderContext.html // You don't have to call ScriptableRenderContext.submit, the render pipeline will call it at specific points in the pipeline. public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { var ssaa = renderingData.cameraData.camera.GetComponent <MadGoat.SSAA.MadGoatSSAA>(); if (ssaa == null) { return; } else if (!ssaa.enabled) { return; } var isVR = ssaa.GetType() == typeof(MadGoat.SSAA.MadGoatSSAA_VR); #if UNITY_EDITOR if (!UnityEditor.EditorApplication.isPlaying && isVR) { return; } #endif // other pass goes here var material = ssaa.MaterialCurrent; if (material == null) { return; } // set blending - no stacking support on lwrp/urp material.SetOverrideTag("RenderType", "Opaque"); material.SetInt("_SrcBlend", (int)BlendMode.One); material.SetInt("_DstBlend", (int)BlendMode.Zero); material.SetInt("_ZWrite", 1); material.renderQueue = -1; // update values material.SetFloat("_ResizeWidth", ssaa.CameraTargetWidth); material.SetFloat("_ResizeHeight", ssaa.CameraTargetHeight); material.SetFloat("_Sharpness", ssaa.DownsamplerSharpness); material.SetFloat("_SampleDistance", ssaa.DownsamplerDistance); if (!isVR) { // setup command buffer var cmd = CommandBufferPool.Get("SSAA_HDRP_DOWNSAMPLER"); CoreUtils.ClearRenderTarget(cmd, ClearFlag.All, Color.clear); CoreUtils.SetRenderTarget(cmd, BuiltinRenderTextureType.CurrentActive); Blit(cmd, ssaa.RenderCamera.targetTexture, BuiltinRenderTextureType.CurrentActive, material, 0); // execute command buffer context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); } else { // breaks the pipeline // --- //// setup command buffer //var cmd = CommandBufferPool.Get("SSAA_HDRP_DOWNSAMPLER"); //CoreUtils.ClearRenderTarget(cmd, ClearFlag.All, Color.clear); //CoreUtils.SetRenderTarget(cmd, BuiltinRenderTextureType.CurrentActive); //RenderTargetIdentifier ssaaCommandBufferTargetId = new RenderTargetIdentifier(rtDownsampler); //Blit(cmd, BuiltinRenderTextureType.CameraTarget, ssaaCommandBufferTargetId, material, 0); //Blit(cmd, ssaaCommandBufferTargetId, BuiltinRenderTextureType.CameraTarget); //// execute command buffer //context.ExecuteCommandBuffer(cmd); //CommandBufferPool.Release(cmd); } }
private void AO(CommandBuffer cmd) { CoreUtils.SetRenderTarget(cmd, ShaderProperties.hbaoTex); CoreUtils.ClearRenderTarget(cmd, ClearFlag.Color, new Color(0, 0, 0, 1)); Blit(cmd, ShaderProperties.inputTex, ShaderProperties.hbaoTex, material, Pass.AO); }
protected override void Render(ScriptableRenderContext context, Camera[] cameras) { BeginFrameRendering(cameras); #region Rendering setup if (_renderersSorted == null) { GetRenderersForEffects(); } // Constants used in the camera render loop. RenderTextureDescriptor rtDesc = new RenderTextureDescriptor(_settings.m_renderResolution.x, _settings.m_renderResolution.y, RenderTextureFormat.Default, 24); switch (_settings.m_fixedRenderResolution) { case RenderConstraintAxis.Horizontal: rtDesc.height = (int)(((float)Screen.height / (float)Screen.width) * (float)rtDesc.width); break; case RenderConstraintAxis.Vertical: rtDesc.width = (int)(((float)Screen.width / (float)Screen.height) * (float)rtDesc.height); break; case RenderConstraintAxis.None: rtDesc.width = Screen.width; rtDesc.height = Screen.height; break; } var rtID = Shader.PropertyToID("_LowResScreen"); if (_settings.m_simulateVertexPrecision) { Shader.EnableKeyword("VERTEX_PRECISION_ON"); Shader.SetGlobalFloat("_VertexPrecision", _settings.m_vertexPrecision); } else { Shader.DisableKeyword("VERTEX_PRECISION_ON"); } if (_settings.m_perspectiveCorrection) { Shader.EnableKeyword("PERSPECTIVE_CORRECTION_ON"); } else { Shader.DisableKeyword("PERSPECTIVE_CORRECTION_ON"); } #endregion foreach (var camera in cameras) { BeginCameraRendering(camera); var _cb = CommandBufferPool.Get(); #region Per-camera setup // Set the camera up. context.SetupCameraProperties(camera); float fov = _settings.m_viewModelFOV; bool isSceneView = false; #if UNITY_EDITOR if (camera.cameraType == CameraType.SceneView) { fov = camera.fieldOfView; isSceneView = true; } #endif _cb.SetGlobalVectorArray(k_visibleLightColorsId, visibleLightColors); _cb.SetGlobalVectorArray(k_visibleLightDirectionsOrPositionsId, visibleLightDirectionsOrPositions); _cb.SetGlobalVectorArray(k_visibleLightAttenuationsId, visibleLightAttenuations); _cb.SetGlobalVectorArray(k_visibleLightSpotDirectionsId, visibleLightSpotDirections); #region Volume stack setup VolumeStack stack = null; if (_volumeStacks.ContainsKey(camera)) { stack = _volumeStacks[camera]; } else { stack = VolumeManager.instance.CreateStack(); _volumeStacks.Add(camera, stack); } var stackLayer = camera.GetComponent <Retro3DVolumeLayer>(); VolumeManager.instance.Update(stack, camera.transform, stackLayer ? stackLayer.layers : _settings.m_defaultVolumeLayerMask); #endregion var vm_matrix = Matrix4x4.Perspective(fov, camera.aspect, camera.nearClipPlane, camera.farClipPlane); _cb.SetGlobalMatrix("_ViewmodelProjMatrix", GL.GetGPUProjectionMatrix(vm_matrix, true)); // Setup commands: Initialize the temporary render texture. _cb.name = "Setup"; _cb.GetTemporaryRT(rtID, rtDesc.width, rtDesc.height, rtDesc.depthBufferBits, FilterMode.Point, rtDesc.colorFormat, RenderTextureReadWrite.Default, (int)_settings.m_antialiasing); _cb.SetRenderTarget(rtID); CoreUtils.ClearRenderTarget(_cb, ClearFlag.All, camera.backgroundColor); context.ExecuteCommandBuffer(_cb); _cb.Clear(); #endregion PerformSceneRender(context, camera); if (isSceneView) { context.DrawGizmos(camera, GizmoSubset.PreImageEffects); } PerformPostProcessing(context, camera, stack); if (isSceneView) { context.DrawGizmos(camera, GizmoSubset.PostImageEffects); } PerformFinalBlit(context, rtID, _cb); context.Submit(); EndCameraRendering(context, camera); CommandBufferPool.Release(_cb); } EndFrameRendering(context, cameras); }
private void DeinterleavedAO(CommandBuffer cmd) { // Deinterleave depth & normals (4x4) cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity); for (int i = 0; i < 4; i++) { var rtsDepth = new RenderTargetIdentifier[] { ShaderProperties.depthSliceTex[(i << 2) + 0], ShaderProperties.depthSliceTex[(i << 2) + 1], ShaderProperties.depthSliceTex[(i << 2) + 2], ShaderProperties.depthSliceTex[(i << 2) + 3] }; var rtsNormals = new RenderTargetIdentifier[] { ShaderProperties.normalsSliceTex[(i << 2) + 0], ShaderProperties.normalsSliceTex[(i << 2) + 1], ShaderProperties.normalsSliceTex[(i << 2) + 2], ShaderProperties.normalsSliceTex[(i << 2) + 3] }; int offsetX = (i & 1) << 1; int offsetY = (i >> 1) << 1; cmd.SetGlobalVector(ShaderProperties.deinterleaveOffset[0], new Vector2(offsetX + 0, offsetY + 0)); cmd.SetGlobalVector(ShaderProperties.deinterleaveOffset[1], new Vector2(offsetX + 1, offsetY + 0)); cmd.SetGlobalVector(ShaderProperties.deinterleaveOffset[2], new Vector2(offsetX + 0, offsetY + 1)); cmd.SetGlobalVector(ShaderProperties.deinterleaveOffset[3], new Vector2(offsetX + 1, offsetY + 1)); for (int j = 0; j < 4; j++) { cmd.GetTemporaryRT(ShaderProperties.depthSliceTex[j + 4 * i], deinterleavedDepthDesc, FilterMode.Point); cmd.GetTemporaryRT(ShaderProperties.normalsSliceTex[j + 4 * i], deinterleavedNormalsDesc, FilterMode.Point); } cmd.SetRenderTarget(rtsDepth, rtsDepth[0]); cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, material, 0, Pass.Deinterleave_Depth); // outputs 4 render textures cmd.SetRenderTarget(rtsNormals, rtsNormals[0]); cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, material, 0, Pass.Deinterleave_Normals); // outputs 4 render textures } cmd.SetViewProjectionMatrices(cameraData.camera.worldToCameraMatrix, cameraData.camera.projectionMatrix); // AO on each layer for (int i = 0; i < 4 * 4; i++) { cmd.SetGlobalTexture(ShaderProperties.depthTex, ShaderProperties.depthSliceTex[i]); cmd.SetGlobalTexture(ShaderProperties.normalsTex, ShaderProperties.normalsSliceTex[i]); cmd.SetGlobalVector(ShaderProperties.jitter, s_jitter[i]); cmd.GetTemporaryRT(ShaderProperties.aoSliceTex[i], deinterleavedAoDesc, FilterMode.Point); CoreUtils.SetRenderTarget(cmd, ShaderProperties.aoSliceTex[i]); CoreUtils.ClearRenderTarget(cmd, ClearFlag.Color, new Color(0, 0, 0, 1)); Blit(cmd, ShaderProperties.inputTex, ShaderProperties.aoSliceTex[i], material, Pass.AO_Deinterleaved); // ao cmd.ReleaseTemporaryRT(ShaderProperties.depthSliceTex[i]); cmd.ReleaseTemporaryRT(ShaderProperties.normalsSliceTex[i]); } // Atlas Deinterleaved AO, 4x4 cmd.GetTemporaryRT(ShaderProperties.tempTex, reinterleavedAoDesc, FilterMode.Point); for (int i = 0; i < 4 * 4; i++) { cmd.SetGlobalVector(ShaderProperties.atlasOffset, new Vector2(((i & 1) + (((i & 7) >> 2) << 1)) * deinterleavedAoDesc.width, (((i & 3) >> 1) + ((i >> 3) << 1)) * deinterleavedAoDesc.height)); Blit(cmd, ShaderProperties.aoSliceTex[i], ShaderProperties.tempTex, material, Pass.Atlas_AO_Deinterleaved); // atlassing cmd.ReleaseTemporaryRT(ShaderProperties.aoSliceTex[i]); } // Reinterleave AO Blit(cmd, ShaderProperties.tempTex, ShaderProperties.hbaoTex, material, Pass.Reinterleave_AO); // reinterleave cmd.ReleaseTemporaryRT(ShaderProperties.tempTex); }
private void RenderSolidCore(CommandBuffer cmd, HDCamera targetCamera, RTHandle cameraColorBuffer, bool calculateNormals, bool smoothNormals) { CoreUtils.SetKeyword(cmd, PointCloudShaderIDs.SolidCompose.LinearDepthKeyword, DebugUseLinearDepth); var rt = Resources.GetRTHandle(RTUsage.PointRender); var rt1 = Resources.GetRTHandle(RTUsage.Generic0); var rt2 = Resources.GetRTHandle(RTUsage.Generic1); var rtColor = Resources.GetRTHandle(RTUsage.ColorBuffer); var rtDepth = Resources.GetRTHandle(RTUsage.DepthBuffer); var width = targetCamera.actualWidth; var height = targetCamera.actualHeight; var refSize = rt.referenceSize; var resolution = new Vector2Int(width, height); var fov = targetCamera.camera.fieldOfView; if (SolidFovReprojection) { fov *= ReprojectionRatio; } var size = Math.Max(width, height); var maxLevel = 0; while (size >> maxLevel >= 16) { maxLevel++; } CoreUtils.SetRenderTarget(cmd, rt, rtDepth); CoreUtils.ClearRenderTarget(cmd, ClearFlag.All, Color.clear); CalculateMatrices(targetCamera, out var projMatrix, out var invProjMatrix, out var invViewProjMatrix, out var solidRenderMvp); cmd.SetGlobalBuffer(PointCloudShaderIDs.Shared.Buffer, GetBufferForCamera(targetCamera)); cmd.SetGlobalInt(PointCloudShaderIDs.Shared.Colorize, (int)Colorize); cmd.SetGlobalFloat(PointCloudShaderIDs.Shared.MinHeight, Bounds.min.y); cmd.SetGlobalFloat(PointCloudShaderIDs.Shared.MaxHeight, Bounds.max.y); cmd.SetGlobalMatrix(PointCloudShaderIDs.SolidRender.MVPMatrix, solidRenderMvp); cmd.DrawProcedural(Matrix4x4.identity, Resources.SolidRenderMaterial, 0, MeshTopology.Points, GetPointCountForCamera(targetCamera)); var cs = Resources.SolidComputeShader; cmd.SetComputeVectorParam(cs, PointCloudShaderIDs.SolidCompute.TextureSize, new Vector4(width - 1, height - 1, 1f / width, 1f / height)); cmd.SetComputeVectorParam(cs, PointCloudShaderIDs.SolidCompute.FullRTSize, new Vector4(refSize.x - 1, refSize.y - 1, 1f / refSize.x, 1f / refSize.y)); cmd.SetComputeFloatParam(cs, PointCloudShaderIDs.SolidCompute.FarPlane, targetCamera.camera.farClipPlane); cmd.SetComputeMatrixParam(cs, PointCloudShaderIDs.SolidCompute.ProjectionMatrix, projMatrix); cmd.SetComputeMatrixParam(cs, PointCloudShaderIDs.SolidCompute.InverseProjectionMatrix, invProjMatrix); cmd.SetComputeMatrixParam(cs, PointCloudShaderIDs.SolidCompute.InverseVPMatrix, invViewProjMatrix); cmd.SetComputeVectorParam(cs, PointCloudShaderIDs.SolidCompute.InverseReprojectionVector, GetInverseUvFovReprojectionVector(targetCamera.camera)); var blendSky = DebugBlendSky && cameraColorBuffer != null; var setupCopy = Resources.Kernels.GetSetupKernel(DebugUseLinearDepth, DebugForceFill, blendSky); cmd.SetComputeTextureParam(cs, setupCopy, PointCloudShaderIDs.SolidCompute.SetupCopy.InputColor, rt, 0); cmd.SetComputeTextureParam(cs, setupCopy, PointCloudShaderIDs.SolidCompute.SetupCopy.InputPosition, rtDepth, 0); cmd.SetComputeTextureParam(cs, setupCopy, PointCloudShaderIDs.SolidCompute.SetupCopy.OutputPosition, rt1, 0); cmd.SetComputeTextureParam(cs, setupCopy, PointCloudShaderIDs.SolidCompute.SetupCopy.OutputColor, rtColor, 0); if (blendSky) { cmd.SetComputeTextureParam(cs, setupCopy, PointCloudShaderIDs.SolidCompute.SetupCopy.PostSkyPreRenderTexture, cameraColorBuffer, 0); } cmd.SetComputeFloatParam(cs, PointCloudShaderIDs.SolidCompute.SetupCopy.HorizonThreshold, DebugFillThreshold); cmd.DispatchCompute(cs, setupCopy, GetGroupSize(width, 8), GetGroupSize(height, 8), 1); if (SolidRemoveHidden) { var downsample = Resources.Kernels.Downsample; for (var i = 1; i <= maxLevel + 3; i++) { GetMipData(resolution, i - 1, out var mipRes, out var mipVec); cmd.SetComputeVectorParam(cs, PointCloudShaderIDs.SolidCompute.MipTextureSize, mipVec); cmd.SetComputeTextureParam(cs, downsample, PointCloudShaderIDs.SolidCompute.Downsample.InputPosition, rt1, i - 1); cmd.SetComputeTextureParam(cs, downsample, PointCloudShaderIDs.SolidCompute.Downsample.OutputPosition, rt1, i); cmd.DispatchCompute(cs, downsample, GetGroupSize(mipRes.x, 16), GetGroupSize(mipRes.y, 16), 1); } DebugSolidFixedLevel = Math.Min(Math.Max(DebugSolidFixedLevel, 0), maxLevel); var removeHidden = Resources.Kernels.GetRemoveHiddenKernel(DebugShowRemoveHiddenCascades); var removeHiddenMagic = RemoveHiddenCascadeOffset * height * 0.5f / Mathf.Tan(0.5f * fov * Mathf.Deg2Rad); cmd.SetComputeIntParam(cs, PointCloudShaderIDs.SolidCompute.RemoveHidden.LevelCount, maxLevel); cmd.SetComputeTextureParam(cs, removeHidden, PointCloudShaderIDs.SolidCompute.RemoveHidden.Position, rt1); cmd.SetComputeTextureParam(cs, removeHidden, PointCloudShaderIDs.SolidCompute.RemoveHidden.Color, rtColor, 0); cmd.SetComputeFloatParam(cs, PointCloudShaderIDs.SolidCompute.RemoveHidden.CascadesOffset, removeHiddenMagic); cmd.SetComputeFloatParam(cs, PointCloudShaderIDs.SolidCompute.RemoveHidden.CascadesSize, RemoveHiddenCascadeSize); cmd.SetComputeIntParam(cs, PointCloudShaderIDs.SolidCompute.RemoveHidden.FixedLevel, DebugSolidFixedLevel); cmd.DispatchCompute(cs, removeHidden, GetGroupSize(width, 8), GetGroupSize(height, 8), 1); } if (DebugSolidPullPush) { var pullKernel = Resources.Kernels.Pull; cmd.SetComputeFloatParam(cs, PointCloudShaderIDs.SolidCompute.PullKernel.FilterExponent, DebugSolidPullParam); for (var i = 1; i <= maxLevel; i++) { GetMipData(resolution, i, out var mipRes, out var higherMipVec); GetMipData(resolution, i - 1, out _, out var mipVec); cmd.SetComputeVectorParam(cs, PointCloudShaderIDs.SolidCompute.MipTextureSize, mipVec); cmd.SetComputeVectorParam(cs, PointCloudShaderIDs.SolidCompute.HigherMipTextureSize, higherMipVec); cmd.SetComputeIntParam(cs, PointCloudShaderIDs.SolidCompute.PullKernel.SkipWeightMul, i == maxLevel ? 1 : 0); cmd.SetComputeIntParam(cs, PointCloudShaderIDs.SolidCompute.PullKernel.InputLevel, i - 1); cmd.SetComputeTextureParam(cs, pullKernel, PointCloudShaderIDs.SolidCompute.PullKernel.InputColor, rtColor, i - 1); cmd.SetComputeTextureParam(cs, pullKernel, PointCloudShaderIDs.SolidCompute.PullKernel.OutputColor, rtColor, i); cmd.DispatchCompute(cs, pullKernel, GetGroupSize(mipRes.x, 8), GetGroupSize(mipRes.y, 8), 1); } var pushKernel = Resources.Kernels.Push; for (var i = maxLevel; i > 0; i--) { GetMipData(resolution, i - 1, out var mipRes, out var mipVec); GetMipData(resolution, i, out _, out var lowerMipVec); cmd.SetComputeVectorParam(cs, PointCloudShaderIDs.SolidCompute.MipTextureSize, mipVec); cmd.SetComputeVectorParam(cs, PointCloudShaderIDs.SolidCompute.HigherMipTextureSize, lowerMipVec); cmd.SetComputeIntParam(cs, PointCloudShaderIDs.SolidCompute.PushKernel.InputLevel, i); cmd.SetComputeTextureParam(cs, pushKernel, PointCloudShaderIDs.SolidCompute.PushKernel.InputColor, rtColor, i); cmd.SetComputeTextureParam(cs, pushKernel, PointCloudShaderIDs.SolidCompute.PushKernel.OutputColor, rtColor, i - 1); cmd.DispatchCompute(cs, pushKernel, GetGroupSize(mipRes.x, 8), GetGroupSize(mipRes.y, 8), 1); } if (calculateNormals) { var calculateNormalsKernel = Resources.Kernels.GetCalculateNormalsKernel(DebugUseLinearDepth); var normalsTarget = smoothNormals ? rt2 : rt1; for (var i = 0; i < maxLevel; ++i) { GetMipData(resolution, i, out var mipRes, out var mipVec); cmd.SetComputeVectorParam(cs, PointCloudShaderIDs.SolidCompute.MipTextureSize, mipVec); cmd.SetComputeIntParam(cs, PointCloudShaderIDs.SolidCompute.CalculateNormals.InputLevel, i); cmd.SetComputeTextureParam(cs, calculateNormalsKernel, PointCloudShaderIDs.SolidCompute.CalculateNormals.Input, rtColor); cmd.SetComputeTextureParam(cs, calculateNormalsKernel, PointCloudShaderIDs.SolidCompute.CalculateNormals.Output, normalsTarget, i); cmd.DispatchCompute(cs, calculateNormalsKernel, GetGroupSize(mipRes.x, 8), GetGroupSize(mipRes.x, 8), 1); } if (smoothNormals) { var smoothNormalsKernel = Resources.Kernels.GetSmoothNormalsKernel(DebugUseLinearDepth, DebugShowSmoothNormalsCascades); var smoothNormalsMagic = SmoothNormalsCascadeOffset * height * 0.5f / Mathf.Tan(0.5f * fov * Mathf.Deg2Rad); cmd.SetComputeTextureParam(cs, smoothNormalsKernel, PointCloudShaderIDs.SolidCompute.SmoothNormals.Input, rt2); cmd.SetComputeTextureParam(cs, smoothNormalsKernel, PointCloudShaderIDs.SolidCompute.SmoothNormals.Output, rt1, 0); cmd.SetComputeFloatParam(cs, PointCloudShaderIDs.SolidCompute.SmoothNormals.CascadesOffset, smoothNormalsMagic); cmd.SetComputeFloatParam(cs, PointCloudShaderIDs.SolidCompute.SmoothNormals.CascadesSize, SmoothNormalsCascadeSize); if (DebugShowSmoothNormalsCascades) { cmd.SetComputeTextureParam(cs, smoothNormalsKernel, PointCloudShaderIDs.SolidCompute.SmoothNormals.ColorDebug, rtColor, 0); } cmd.DispatchCompute(cs, smoothNormalsKernel, GetGroupSize(width, 8), GetGroupSize(height, 8), 1); } } } }
public static void SetRenderTarget(CommandBuffer cmd, HDCamera camera, RenderTargetIdentifier[] colorBuffers, RTHandle depthBuffer, ClearFlag clearFlag = ClearFlag.None) { CoreUtils.SetRenderTarget(cmd, colorBuffers, depthBuffer); // Don't clear here, viewport needs to be set before we do. SetViewport(cmd, camera, depthBuffer); CoreUtils.ClearRenderTarget(cmd, clearFlag, CoreUtils.clearColorAllBlack); }
public static void SetRenderTarget(CommandBuffer cmd, HDCamera camera, RTHandle colorBuffer, RTHandle depthBuffer, ClearFlag clearFlag, Color clearColor, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown, int depthSlice = 0) { CoreUtils.SetRenderTarget(cmd, colorBuffer, depthBuffer, miplevel, cubemapFace, depthSlice); SetViewport(cmd, camera, colorBuffer); CoreUtils.ClearRenderTarget(cmd, clearFlag, clearColor); }