private void DirLight(PipelineCamera cam, ref PipelineCommandData data) { PipelineBaseBuffer baseBuffer; if (SunLight.current == null || !SunLight.current.enabled || !SceneController.GetBaseBuffer(out baseBuffer)) { return; } cbdr.lightFlag |= 0b100; if (SunLight.current.enableShadow) { cbdr.lightFlag |= 0b010; } CommandBuffer buffer = data.buffer; int pass; if (SunLight.current.enableShadow) { RenderClusterOptions opts = new RenderClusterOptions { frustumPlanes = shadowFrustumVP, command = buffer, cullingShader = data.resources.gpuFrustumCulling, isOrtho = true }; ref ShadowmapSettings settings = ref SunLight.current.settings; buffer.SetGlobalVector(ShaderIDs._NormalBiases, settings.normalBias); //Only Depth buffer.SetGlobalVector(ShaderIDs._ShadowDisableDistance, new Vector4(settings.firstLevelDistance, settings.secondLevelDistance, settings.thirdLevelDistance, settings.farestDistance)); //Only Mask buffer.SetGlobalVector(ShaderIDs._SoftParam, settings.cascadeSoftValue / settings.resolution); SceneController.current.DrawDirectionalShadow(cam.cam, ref opts, ref SunLight.current.settings, ref SunLight.shadMap, cascadeShadowMapVP); buffer.SetGlobalMatrixArray(ShaderIDs._ShadowMapVPs, cascadeShadowMapVP); buffer.SetGlobalTexture(ShaderIDs._DirShadowMap, SunLight.shadMap.shadowmapTexture); cbdr.dirLightShadowmap = SunLight.shadMap.shadowmapTexture; pass = 0; }
public override void DrawClusterOccDoubleCheck(ref RenderClusterOptions options, ref HizOptions hizOpts, ref RenderTargets rendTargets) { CommandBuffer buffer = options.command; ComputeShader gpuFrustumShader = options.cullingShader; PipelineFunctions.UpdateOcclusionBuffer( baseBuffer, gpuFrustumShader, buffer, hizOpts.hizData, options.frustumPlanes, options.isOrtho); //绘制第一次剔除结果 PipelineFunctions.DrawLastFrameCullResult(baseBuffer, buffer, options.proceduralMaterial); //更新Vector,Depth Mip Map hizOpts.hizData.lastFrameCameraUp = hizOpts.currentCameraUpVec; PipelineFunctions.ClearOcclusionData(baseBuffer, buffer, gpuFrustumShader); //TODO 绘制其他物体 //TODO buffer.Blit(hizOpts.currentDepthTex, hizOpts.hizData.historyDepth, hizOpts.linearLODMaterial, 0); hizOpts.hizDepth.GetMipMap(hizOpts.hizData.historyDepth, buffer); //使用新数据进行二次剔除 PipelineFunctions.OcclusionRecheck(baseBuffer, gpuFrustumShader, buffer, hizOpts.hizData); //绘制二次剔除结果 buffer.SetRenderTarget(rendTargets.gbufferIdentifier, rendTargets.depthIdentifier); PipelineFunctions.DrawRecheckCullResult(baseBuffer, options.proceduralMaterial, buffer); buffer.Blit(hizOpts.currentDepthTex, hizOpts.hizData.historyDepth, hizOpts.linearLODMaterial, 0); hizOpts.hizDepth.GetMipMap(hizOpts.hizData.historyDepth, buffer); }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { CommandBuffer buffer = data.buffer; RenderClusterOptions options = new RenderClusterOptions { command = buffer, frustumPlanes = data.frustumPlanes, cullingShader = data.resources.shaders.gpuFrustumCulling, terrainCompute = data.resources.shaders.terrainCompute }; if (enableOcclusionCulling) { if (SceneController.gpurpEnabled) { buffer.SetRenderTarget(hizDepth.backupMip); buffer.ClearRenderTarget(true, true, Color.white); if (OccluderDrawer.current) { OccluderDrawer.current.Drawer(buffer, linearDrawerMat, data.frustumPlanes); } } SceneController.DrawClusterOccDoubleCheck(ref options, ref cam.targets, ref data, ref hizDepth, linearMat, cam.cam); } else { SceneController.DrawCluster(ref options, ref cam.targets, ref data, cam.cam); } }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { CommandBuffer buffer = data.buffer; buffer.SetRenderTarget(cam.targets.gbufferIdentifier, cam.targets.depthIdentifier); buffer.ClearRenderTarget(true, true, Color.black); HizOcclusionData hizData = IPerCameraData.GetProperty(cam, () => new HizOcclusionData()); RenderClusterOptions options = new RenderClusterOptions { command = buffer, frustumPlanes = data.frustumPlanes, cullingShader = data.resources.shaders.gpuFrustumCulling, terrainCompute = data.resources.shaders.terrainCompute }; if (enableOcclusionCulling) { HizOptions hizOptions; hizOptions = new HizOptions { currentCameraUpVec = cam.cam.transform.up, hizData = hizData, hizDepth = hizDepth, linearLODMaterial = linearMat, currentDepthTex = cam.targets.depthIdentifier }; SceneController.DrawClusterOccDoubleCheck(ref options, ref hizOptions, ref cam.targets, ref data, cam.cam); } else { SceneController.DrawCluster(ref options, ref cam.targets, ref data, cam.cam); } }
public void DrawTerrain(ref RenderClusterOptions ops, Material terrainMat, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer) { if (referenceBuffer.Length <= 0) { return; } ComputeShader sh = ops.terrainCompute; CommandBuffer bf = ops.command; bf.SetComputeBufferParam(sh, frustumCullKernel, ShaderIDs.clusterBuffer, clusterBuffer); bf.SetComputeBufferParam(sh, frustumCullKernel, ShaderIDs.resultBuffer, resultBuffer); bf.SetComputeBufferParam(sh, frustumCullKernel, ShaderIDs.instanceCountBuffer, instanceCountBuffer); bf.SetComputeBufferParam(sh, clearCullKernel, ShaderIDs.instanceCountBuffer, instanceCountBuffer); bf.SetComputeVectorArrayParam(sh, ShaderIDs.planes, ops.frustumPlanes); bf.SetComputeIntParam(sh, ShaderIDs._CullingPlaneCount, ops.isOrtho ? 6 : 5); bf.SetGlobalInt(ShaderIDs._MeshSize, meshSize); bf.DispatchCompute(sh, clearCullKernel, 1, 1, 1); ComputeShaderUtility.Dispatch(sh, bf, frustumCullKernel, referenceBuffer.Length, 64); bf.SetGlobalBuffer(ShaderIDs.heightMapBuffer, heightMapBuffer); bf.SetGlobalBuffer(ShaderIDs.triangleBuffer, triangleBuffer); bf.SetGlobalBuffer(ShaderIDs.verticesBuffer, verticesBuffer); bf.SetGlobalBuffer(ShaderIDs.clusterBuffer, clusterBuffer); bf.SetGlobalBuffer(ShaderIDs.resultBuffer, resultBuffer); bf.SetRenderTarget(colorBuffer, depthBuffer); bf.DrawProceduralIndirect(Matrix4x4.identity, terrainMat, 0, MeshTopology.Triangles, instanceCountBuffer); }
public override void DrawCluster(ref RenderClusterOptions options) { PipelineFunctions.SetBaseBuffer(baseBuffer, options.cullingShader, options.frustumPlanes, options.command); PipelineFunctions.RunCullDispatching(baseBuffer, options.cullingShader, options.isOrtho, options.command); PipelineFunctions.RenderProceduralCommand(baseBuffer, options.proceduralMaterial, options.command); //TODO 绘制其他物体 //TODO options.command.DispatchCompute(options.cullingShader, 1, 1, 1, 1); }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { // Material proceduralMaterial = data.baseBuffer.combinedMaterial; CommandBuffer buffer = data.buffer; buffer.SetRenderTarget(cam.targets.gbufferIdentifier, cam.targets.depthIdentifier); buffer.ClearRenderTarget(true, true, Color.black); PipelineBaseBuffer baseBuffer; if (!SceneController.current.GetBaseBufferAndCheck(out baseBuffer)) { return; } HizOcclusionData hizData = IPerCameraData.GetProperty <HizOcclusionData>(cam, getOcclusionData); RenderClusterOptions options = new RenderClusterOptions { command = buffer, frustumPlanes = data.arrayCollection.frustumPlanes, proceduralMaterial = proceduralMaterial, isOrtho = cam.cam.orthographic, cullingShader = data.resources.gpuFrustumCulling }; HizOptions hizOptions; switch (occCullingMod) { case OcclusionCullingMode.None: SceneController.current.DrawCluster(ref options); break; case OcclusionCullingMode.SingleCheck: hizOptions = new HizOptions { currentCameraUpVec = cam.cam.transform.up, hizData = hizData, hizDepth = hizDepth, linearLODMaterial = linearMat }; SceneController.current.DrawClusterOccSingleCheck(ref options, ref hizOptions); break; case OcclusionCullingMode.DoubleCheck: hizOptions = new HizOptions { currentCameraUpVec = cam.cam.transform.up, hizData = hizData, hizDepth = hizDepth, linearLODMaterial = linearMat }; SceneController.current.DrawClusterOccDoubleCheck(ref options, ref hizOptions, ref cam.targets); break; } data.ExecuteCommandBuffer(); }
private void PointLight(PipelineCamera cam, ref PipelineCommandData data) { CommandBuffer buffer = data.buffer; pointLightMaterial.SetBuffer(ShaderIDs.verticesBuffer, sphereBuffer); VoxelLightCommonData(buffer, cam.cam); ClearDispatch(buffer); lightingHandle.Complete(); foreach (var i in addMLightCommandList) { MLight.AddMLight(i); } addMLightCommandList.Clear(); cbdr.pointshadowCount = cubemapVPMatrices.Length; if (LightFilter.pointLightCount > 0) { if (cubemapVPMatrices.Length > 0) { var cullShader = data.resources.gpuFrustumCulling; buffer.SetGlobalTexture(ShaderIDs._CubeShadowMapArray, cbdr.cubeArrayMap); RenderClusterOptions opts = new RenderClusterOptions { cullingShader = cullShader, command = buffer, frustumPlanes = null, isOrtho = false }; List <VisibleLight> allLights = data.cullResults.visibleLights; PointLightStruct * pointLightPtr = pointLightArray.Ptr(); for (int i = 0; i < cubemapVPMatrices.Length; ++i) { ref CubemapViewProjMatrix vpMatrices = ref cubemapVPMatrices[i]; int2 lightIndex = vpMatrices.index; Light lt = allLights[lightIndex.y].light; MLight light = MUnsafeUtility.GetObject <MLight>(vpMatrices.mLightPtr); if (light.updateShadowmap) { light.UpdateShadowCacheType(true); SceneController.DrawPointLight(light, ref pointLightPtr[lightIndex.x], cubeDepthMaterial, ref opts, i, light.shadowMap, ref data, cubemapVPMatrices.unsafePtr, cbdr.cubeArrayMap); } else { PipelineFunctions.CopyToCubeMap(cbdr.cubeArrayMap, light.shadowMap, buffer, i); } //TODO //Multi frame shadowmap } } SetPointLightBuffer(pointLightArray, LightFilter.pointLightCount, buffer); buffer.EnableShaderKeyword("POINTLIGHT"); cbdr.lightFlag |= 1; }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { CommandBuffer buffer = data.buffer; buffer.SetRenderTarget(cam.targets.gbufferIdentifier, cam.targets.depthIdentifier); buffer.ClearRenderTarget(true, true, Color.black); PipelineBaseBuffer baseBuffer; bool isClusterEnabled = SceneController.GetBaseBuffer(out baseBuffer); HizOcclusionData hizData = IPerCameraData.GetProperty <HizOcclusionData>(cam, () => new HizOcclusionData()); RenderClusterOptions options = new RenderClusterOptions { command = buffer, frustumPlanes = data.arrayCollection.frustumPlanes, isOrtho = cam.cam.orthographic, cullingShader = data.resources.gpuFrustumCulling, terrainCompute = data.resources.terrainCompute, isClusterEnabled = isClusterEnabled, isTerrainEnabled = true }; HizOptions hizOptions; switch (occCullingMod) { case OcclusionCullingMode.None: SceneController.current.DrawCluster(ref options, ref cam.targets); break; case OcclusionCullingMode.SingleCheck: hizOptions = new HizOptions { currentCameraUpVec = cam.cam.transform.up, hizData = hizData, hizDepth = hizDepth, linearLODMaterial = linearMat, currentDepthTex = cam.targets.depthTexture }; SceneController.current.DrawClusterOccSingleCheck(ref options, ref hizOptions, ref cam.targets); break; case OcclusionCullingMode.DoubleCheck: hizOptions = new HizOptions { currentCameraUpVec = cam.cam.transform.up, hizData = hizData, hizDepth = hizDepth, linearLODMaterial = linearMat, currentDepthTex = cam.targets.depthTexture }; SceneController.current.DrawClusterOccDoubleCheck(ref options, ref hizOptions, ref cam.targets); break; } data.ExecuteCommandBuffer(); }
public static void DrawCluster(ref RenderClusterOptions options, ref RenderTargets targets, ref PipelineCommandData data, Camera cam) { if (gpurpEnabled) { options.command.SetGlobalBuffer(ShaderIDs._PropertiesBuffer, commonData.propertyBuffer); options.command.SetGlobalTexture(ShaderIDs._MainTex, commonData.texArray); PipelineFunctions.SetBaseBuffer(baseBuffer, options.cullingShader, options.frustumPlanes, options.command); PipelineFunctions.RunCullDispatching(baseBuffer, options.cullingShader, options.isOrtho, options.command); PipelineFunctions.RenderProceduralCommand(baseBuffer, commonData.clusterMaterial, options.command); } RenderScene(ref data, cam); }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { CommandBuffer buffer = data.buffer; RenderClusterOptions options = new RenderClusterOptions { command = buffer, frustumPlanes = data.frustumPlanes, cullingShader = data.resources.shaders.gpuFrustumCulling, terrainCompute = data.resources.shaders.terrainCompute }; SceneController.DrawCluster(ref options, ref cam.targets, ref data, cam.cam); // buffer.Blit(cam.targets.gbufferIdentifier[2], BuiltinRenderTextureType.CameraTarget); }
public static void DrawCluster(ref RenderClusterOptions options, ref RenderTargets targets, ref PipelineCommandData data, Camera cam) { data.buffer.SetRenderTarget(targets.gbufferIdentifier, targets.depthBuffer); data.buffer.ClearRenderTarget(true, true, Color.black); if (gpurpEnabled) { options.command.SetGlobalBuffer(ShaderIDs._PropertiesBuffer, commonData.propertyBuffer); options.command.SetGlobalTexture(ShaderIDs._MainTex, commonData.texArray); options.command.SetGlobalTexture(ShaderIDs._LightMap, commonData.lightmapArray); PipelineFunctions.SetBaseBuffer(baseBuffer, options.cullingShader, options.frustumPlanes, options.command); PipelineFunctions.RunCullDispatching(baseBuffer, options.cullingShader, options.command); PipelineFunctions.RenderProceduralCommand(baseBuffer, commonData.clusterMaterial, options.command); } RenderScene(ref data, cam); }
private void DirLight(PipelineCamera cam, ref PipelineCommandData data) { if (SunLight.current == null || !SunLight.current.enabled) { return; } cbdr.lightFlag |= 0b100; if (SunLight.current.enableShadow) { cbdr.lightFlag |= 0b010; } CommandBuffer buffer = data.buffer; if (SunLight.current.enableShadow) { RenderClusterOptions opts = new RenderClusterOptions { frustumPlanes = shadowFrustumVP, command = buffer, cullingShader = data.resources.shaders.gpuFrustumCulling, }; buffer.SetGlobalVector(ShaderIDs._ShadowDisableDistance, new Vector4(SunLight.current.firstLevelDistance, SunLight.current.secondLevelDistance, SunLight.current.thirdLevelDistance, SunLight.current.farestDistance));//Only Mask buffer.SetGlobalVector(ShaderIDs._SoftParam, SunLight.current.cascadeSoftValue / SunLight.current.resolution); float *cascadeShadowmap = stackalloc float[4]; cascadeShadowmap[0] = 0; float maxCascadeLevel = SunLight.CASCADELEVELCOUNT - 1; for (int i = 1; i < 4; ++i) { cascadeShadowmap[i] = min(maxCascadeLevel, i); } buffer.SetGlobalVector(ShaderIDs._CascadeShadowWeight, *(float4 *)cascadeShadowmap); sunCullResultHandle.Complete(); SceneController.DrawDirectionalShadow(cam, ref data, ref opts, clipDistances, sunShadowCams, cascadeShadowMapVP, proper.overrideOpaqueMaterial); buffer.SetGlobalMatrixArray(ShaderIDs._ShadowMapVPs, cascadeShadowMapVP); buffer.SetGlobalTexture(ShaderIDs._DirShadowMap, SunLight.current.shadowmapTexture); cbdr.dirLightShadowmap = SunLight.current.shadowmapTexture; staticFit.frustumCorners.Dispose(); } buffer.SetGlobalVector(ShaderIDs._DirLightFinalColor, SunLight.current.light.color * SunLight.current.light.intensity); buffer.SetGlobalVector(ShaderIDs._DirLightPos, -SunLight.current.transform.forward); }
private void DirLight(PipelineCamera cam, ref PipelineCommandData data) { if (SunLight.current == null || !SunLight.current.enabled) { return; } cbdr.lightFlag |= 0b100; if (SunLight.current.enableShadow) { cbdr.lightFlag |= 0b010; } CommandBuffer buffer = data.buffer; int pass; if (SunLight.current.enableShadow) { RenderClusterOptions opts = new RenderClusterOptions { frustumPlanes = shadowFrustumVP, command = buffer, cullingShader = data.resources.gpuFrustumCulling, isOrtho = true }; buffer.SetGlobalVector(ShaderIDs._NormalBiases, SunLight.current.normalBias); //Only Depth buffer.SetGlobalVector(ShaderIDs._ShadowDisableDistance, new Vector4(SunLight.current.firstLevelDistance, SunLight.current.secondLevelDistance, SunLight.current.thirdLevelDistance, SunLight.current.farestDistance));//Only Mask buffer.SetGlobalVector(ShaderIDs._SoftParam, SunLight.current.cascadeSoftValue / SunLight.current.resolution); SceneController.DrawDirectionalShadow(cam.cam, ref data, ref opts, SunLight.current, cascadeShadowMapVP); buffer.SetGlobalMatrixArray(ShaderIDs._ShadowMapVPs, cascadeShadowMapVP); buffer.SetGlobalTexture(ShaderIDs._DirShadowMap, SunLight.current.shadowmapTexture); cbdr.dirLightShadowmap = SunLight.current.shadowmapTexture; pass = 0; } else { pass = 1; } buffer.SetGlobalVector(ShaderIDs._DirLightFinalColor, SunLight.current.light.color * SunLight.current.light.intensity); buffer.SetGlobalVector(ShaderIDs._DirLightPos, -(Vector3)SunLight.current.shadCam.forward); buffer.SetRenderTarget(cam.targets.renderTargetIdentifier, cam.targets.depthIdentifier); buffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, shadMaskMaterial, 0, pass); }
private void DirLight(PipelineCamera cam, ref PipelineCommandData data) { if (SunLight.current == null || !SunLight.current.enabled) { return; } cbdr.lightFlag |= 0b100; if (SunLight.current.enableShadow) { cbdr.lightFlag |= 0b010; } CommandBuffer buffer = data.buffer; int pass; if (SunLight.current.enableShadow) { RenderClusterOptions opts = new RenderClusterOptions { frustumPlanes = shadowFrustumVP, command = buffer, cullingShader = data.resources.shaders.gpuFrustumCulling, }; buffer.SetGlobalVector(ShaderIDs._NormalBiases, SunLight.current.normalBias); //Only Depth buffer.SetGlobalVector(ShaderIDs._ShadowDisableDistance, new Vector4(SunLight.current.firstLevelDistance, SunLight.current.secondLevelDistance, SunLight.current.thirdLevelDistance, SunLight.current.farestDistance));//Only Mask buffer.SetGlobalVector(ShaderIDs._SoftParam, SunLight.current.cascadeSoftValue / SunLight.current.resolution); csmHandle.Complete(); SceneController.DrawDirectionalShadow(cam, ref staticFit, ref data, ref opts, clipDistances, cascadeWorldToCamera, cascadeProjection); buffer.SetGlobalMatrixArray(ShaderIDs._ShadowMapVPs, cascadeShadowMapVP); buffer.SetGlobalTexture(ShaderIDs._DirShadowMap, SunLight.current.shadowmapTexture); cbdr.dirLightShadowmap = SunLight.current.shadowmapTexture; staticFit.frustumCorners.Dispose(); pass = 0; } else { pass = 1; } buffer.SetGlobalVector(ShaderIDs._DirLightFinalColor, SunLight.current.light.color * SunLight.current.light.intensity); buffer.SetGlobalVector(ShaderIDs._DirLightPos, -(Vector3)SunLight.current.shadCam.forward); }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { if (SunLight.current == null) { return; } PipelineBaseBuffer baseBuffer; if (!SceneController.current.GetBaseBufferAndCheck(out baseBuffer)) { return; } CommandBuffer buffer = data.buffer; int pass; if (SunLight.current.enableShadow) { RenderClusterOptions opts = new RenderClusterOptions { frustumPlanes = shadowFrustumVP, command = buffer, cullingShader = data.resources.gpuFrustumCulling, isOrtho = true, proceduralMaterial = null }; PipelineFunctions.UpdateShadowMapState(ref SunLight.shadMap, ref SunLight.current.settings, buffer); SceneController.current.DrawDirectionalShadow(cam.cam, ref opts, ref SunLight.current.settings, ref SunLight.shadMap, cascadeShadowMapVP); PipelineFunctions.UpdateShadowMaskState(buffer, ref SunLight.shadMap, cascadeShadowMapVP); pass = 0; } else { pass = 1; } buffer.SetGlobalVector(ShaderIDs._LightFinalColor, SunLight.shadMap.light.color * SunLight.shadMap.light.intensity); buffer.SetRenderTarget(cam.targets.renderTargetIdentifier, cam.targets.depthIdentifier); buffer.SetGlobalVector(ShaderIDs._LightPos, -SunLight.shadMap.shadCam.forward); buffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, shadMaskMaterial, 0, pass); data.ExecuteCommandBuffer(); }
public override void DrawClusterOccSingleCheck(ref RenderClusterOptions options, ref HizOptions hizOpts) { CommandBuffer buffer = options.command; buffer.SetComputeVectorParam(options.cullingShader, ShaderIDs._CameraUpVector, hizOpts.hizData.lastFrameCameraUp); buffer.SetComputeBufferParam(options.cullingShader, 5, ShaderIDs.clusterBuffer, baseBuffer.clusterBuffer); buffer.SetComputeTextureParam(options.cullingShader, 5, ShaderIDs._HizDepthTex, hizOpts.hizData.historyDepth); buffer.SetComputeVectorArrayParam(options.cullingShader, ShaderIDs.planes, options.frustumPlanes); buffer.SetComputeBufferParam(options.cullingShader, 5, ShaderIDs.resultBuffer, baseBuffer.resultBuffer); buffer.SetComputeBufferParam(options.cullingShader, 5, ShaderIDs.instanceCountBuffer, baseBuffer.instanceCountBuffer); buffer.SetComputeBufferParam(options.cullingShader, PipelineBaseBuffer.ComputeShaderKernels.ClearClusterKernel, ShaderIDs.instanceCountBuffer, baseBuffer.instanceCountBuffer); ComputeShaderUtility.Dispatch(options.cullingShader, options.command, 5, baseBuffer.clusterCount, 256); hizOpts.hizData.lastFrameCameraUp = hizOpts.currentCameraUpVec; buffer.SetGlobalBuffer(ShaderIDs.resultBuffer, baseBuffer.resultBuffer); buffer.SetGlobalBuffer(ShaderIDs.verticesBuffer, baseBuffer.verticesBuffer); PipelineFunctions.RenderProceduralCommand(baseBuffer, options.proceduralMaterial, buffer); buffer.DispatchCompute(options.cullingShader, PipelineBaseBuffer.ComputeShaderKernels.ClearClusterKernel, 1, 1, 1); //TODO 绘制其他物体 //TODO buffer.Blit(hizOpts.currentDepthTex, hizOpts.hizData.historyDepth, hizOpts.linearLODMaterial, 0); hizOpts.hizDepth.GetMipMap(hizOpts.hizData.historyDepth, buffer); }
public override void DrawDirectionalShadow(Camera currentCam, ref RenderClusterOptions opts, ref ShadowmapSettings settings, ref ShadowMapComponent shadMap, Matrix4x4[] cascadeShadowMapVP) { const int CASCADELEVELCOUNT = 4; const int CASCADECLIPSIZE = (CASCADELEVELCOUNT + 1) * sizeof(float); ComputeShader gpuFrustumShader = opts.cullingShader; StaticFit staticFit; staticFit.resolution = settings.resolution; staticFit.mainCamTrans = currentCam; staticFit.frustumCorners = shadMap.frustumCorners; float *clipDistances = stackalloc float[CASCADECLIPSIZE]; clipDistances[0] = shadMap.shadCam.nearClipPlane; clipDistances[1] = settings.firstLevelDistance; clipDistances[2] = settings.secondLevelDistance; clipDistances[3] = settings.thirdLevelDistance; clipDistances[4] = settings.farestDistance; opts.command.SetGlobalBuffer(ShaderIDs.verticesBuffer, baseBuffer.verticesBuffer); opts.command.SetGlobalBuffer(ShaderIDs.resultBuffer, baseBuffer.resultBuffer); for (int pass = 0; pass < CASCADELEVELCOUNT; ++pass) { Vector2 farClipDistance = new Vector2(clipDistances[pass], clipDistances[pass + 1]); PipelineFunctions.GetfrustumCorners(farClipDistance, ref shadMap, currentCam); // PipelineFunctions.SetShadowCameraPositionCloseFit(ref shadMap, ref settings); Matrix4x4 invpVPMatrix; PipelineFunctions.SetShadowCameraPositionStaticFit(ref staticFit, ref shadMap.shadCam, pass, cascadeShadowMapVP, out invpVPMatrix); PipelineFunctions.GetCullingPlanes(ref invpVPMatrix, opts.frustumPlanes); PipelineFunctions.SetBaseBuffer(baseBuffer, gpuFrustumShader, opts.frustumPlanes, opts.command); PipelineFunctions.RunCullDispatching(baseBuffer, gpuFrustumShader, true, opts.command); float *biasList = (float *)UnsafeUtility.AddressOf(ref settings.bias); PipelineFunctions.UpdateCascadeState(ref shadMap, opts.command, biasList[pass] / currentCam.farClipPlane, pass); opts.command.DrawProceduralIndirect(Matrix4x4.identity, shadMap.shadowDepthMaterial, 0, MeshTopology.Triangles, baseBuffer.instanceCountBuffer, 0); opts.command.DispatchCompute(gpuFrustumShader, 1, 1, 1, 1); } }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { PipelineBaseBuffer baseBuffer; if (!SceneController.current.GetBaseBufferAndCheck(out baseBuffer)) { return; } CommandBuffer buffer = data.buffer; cullJobHandler.Complete(); UnsafeUtility.ReleaseGCObject(gcHandler); pointLightMaterial.SetBuffer(ShaderIDs.verticesBuffer, sphereBuffer); //Un Shadow Point light buffer.SetRenderTarget(cam.targets.renderTargetIdentifier, cam.targets.depthIdentifier); for (int c = 0; c < unShadowCount; c++) { var i = cullJob.indices[cullJob.length - c]; MPointLight light = MPointLight.allPointLights[i]; buffer.SetGlobalVector(ShaderIDs._LightColor, light.color); buffer.SetGlobalVector(ShaderIDs._LightPos, new Vector4(light.position.x, light.position.y, light.position.z, light.range)); buffer.SetGlobalFloat(ShaderIDs._LightIntensity, light.intensity); buffer.DrawProceduralIndirect(Matrix4x4.identity, pointLightMaterial, 0, MeshTopology.Triangles, sphereIndirectBuffer, 0); } //TODO if (shadowCount > 0) { NativeArray <Vector4> positions = new NativeArray <Vector4>(shadowCount, Allocator.Temp, NativeArrayOptions.UninitializedMemory); for (int i = 0; i < shadowCount; i++) { MPointLight light = MPointLight.allPointLights[cullJob.indices[i]]; positions[i] = new Vector4(light.position.x, light.position.y, light.position.z, light.range); } CubeFunction.UpdateLength(ref cubeBuffer, shadowCount); var cullShader = data.resources.pointLightFrustumCulling; CubeFunction.UpdateData(ref cubeBuffer, baseBuffer, cullShader, buffer, positions); RenderClusterOptions opts = new RenderClusterOptions { cullingShader = cullShader, proceduralMaterial = cubeDepthMaterial, command = buffer, frustumPlanes = null, isOrtho = false }; for (int i = 0; i < shadowCount; i++) { MPointLight light = MPointLight.allPointLights[cullJob.indices[i]]; SceneController.current.DrawCubeMap(light, ref opts, ref cubeBuffer, i); buffer.SetRenderTarget(cam.targets.renderTargetIdentifier, cam.targets.depthIdentifier); buffer.SetGlobalVector(ShaderIDs._LightColor, light.color); buffer.SetGlobalVector(ShaderIDs._LightPos, positions[i]); buffer.SetGlobalFloat(ShaderIDs._LightIntensity, light.intensity); buffer.SetGlobalTexture(ShaderIDs._CubeShadowMap, light.shadowmapTexture); buffer.DrawProceduralIndirect(Matrix4x4.identity, pointLightMaterial, 1, MeshTopology.Triangles, sphereIndirectBuffer, 0); } positions.Dispose(); } //Shadow Point Light indicesArray.Dispose(); data.ExecuteCommandBuffer(); }
public static void DrawSpotLight(ref RenderClusterOptions options, ref PipelineCommandData data, Camera currentCam, ref SpotLight spotLights, ref RenderSpotShadowCommand spotcommand) { ref SpotLightMatrix spotLightMatrix = ref spotcommand.shadowMatrices[spotLights.shadowIndex];
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { CommandBuffer buffer = data.buffer; RenderClusterOptions options = new RenderClusterOptions { command = buffer, frustumPlanes = proper.frustumPlanes, cullingShader = data.resources.shaders.gpuFrustumCulling, terrainCompute = data.resources.shaders.terrainCompute }; FilteringSettings alphaTestFilter = new FilteringSettings { layerMask = cam.cam.cullingMask, renderingLayerMask = 1, renderQueueRange = new RenderQueueRange(2450, 2499) }; FilteringSettings opaqueFilter = new FilteringSettings { layerMask = cam.cam.cullingMask, renderingLayerMask = 1, renderQueueRange = new RenderQueueRange(2000, 2449) }; FilteringSettings mvFilter = new FilteringSettings { layerMask = cam.cam.cullingMask, renderingLayerMask = 1, renderQueueRange = RenderQueueRange.opaque }; DrawingSettings depthAlphaTestDrawSettings = new DrawingSettings(new ShaderTagId("Depth"), new SortingSettings(cam.cam) { criteria = SortingCriteria.QuantizedFrontToBack | SortingCriteria.OptimizeStateChanges } ) { perObjectData = UnityEngine.Rendering.PerObjectData.None, enableDynamicBatching = false, enableInstancing = false }; DrawingSettings depthOpaqueDrawSettings = new DrawingSettings(new ShaderTagId("Depth"), new SortingSettings(cam.cam) { criteria = SortingCriteria.QuantizedFrontToBack }) { perObjectData = UnityEngine.Rendering.PerObjectData.None, enableDynamicBatching = false, enableInstancing = false, overrideMaterial = proper.overrideOpaqueMaterial, overrideMaterialPassIndex = 1 }; DrawingSettings drawSettings = new DrawingSettings(new ShaderTagId("GBuffer"), new SortingSettings(cam.cam) { criteria = SortingCriteria.RenderQueue | SortingCriteria.OptimizeStateChanges }) { perObjectData = UnityEngine.Rendering.PerObjectData.Lightmaps, enableDynamicBatching = false, enableInstancing = false }; DrawingSettings mvDraw = new DrawingSettings(new ShaderTagId("MotionVector"), new SortingSettings { criteria = SortingCriteria.OptimizeStateChanges }) { perObjectData = UnityEngine.Rendering.PerObjectData.None, enableDynamicBatching = false, enableInstancing = false }; //Draw Depth Prepass data.buffer.SetRenderTarget(ShaderIDs._DepthBufferTexture); data.buffer.ClearRenderTarget(true, false, Color.black); cullHandle.Complete(); var lst = CustomDrawRequest.allEvents; foreach (var i in gbufferCullResults) { lst[i].DrawDepthPrepass(buffer); } HizOcclusionData hizOccData = null; PipelineFunctions.UpdateFrustumMinMaxPoint(buffer, proper.frustumMinPoint, proper.frustumMaxPoint); if (useHiZ && SceneController.gpurpEnabled) { #if UNITY_EDITOR if (Application.isPlaying) { #endif hizOccData = IPerCameraData.GetProperty(cam, () => new HizOcclusionData()); SceneController.CullCluster_LastFrameDepthHiZ(ref options, hizOccData, cam); buffer.DrawProceduralIndirect(Matrix4x4.identity, clusterMat, 2, MeshTopology.Triangles, SceneController.baseBuffer.instanceCountBuffer, 0); #if UNITY_EDITOR } #endif } RenderStateBlock depthBlock = new RenderStateBlock { depthState = new DepthState(true, CompareFunction.Less), mask = RenderStateMask.Depth }; SceneController.RenderScene(ref data, ref opaqueFilter, ref depthOpaqueDrawSettings, ref proper.cullResults, ref depthBlock); data.context.DrawRenderers(proper.cullResults, ref depthAlphaTestDrawSettings, ref alphaTestFilter); decalEvt.FrameUpdate(cam, ref data); //Draw GBuffer data.buffer.SetRenderTarget(colors: cam.targets.gbufferIdentifier, depth: ShaderIDs._DepthBufferTexture); data.buffer.ClearRenderTarget(false, true, Color.black); foreach (var i in gbufferCullResults) { lst[i].DrawGBuffer(buffer); } if (useHiZ && SceneController.gpurpEnabled) { #if UNITY_EDITOR if (Application.isPlaying) { #endif buffer.SetGlobalBuffer(ShaderIDs._MaterialBuffer, data.resources.clusterResources.vmManager.materialBuffer); buffer.SetGlobalTexture(ShaderIDs._GPURPMainTex, data.resources.clusterResources.rgbaPool.rt); buffer.SetGlobalTexture(ShaderIDs._GPURPEmissionMap, data.resources.clusterResources.emissionPool.rt); buffer.SetGlobalTexture(ShaderIDs._GPURPBumpMap, data.resources.clusterResources.normalPool.rt); buffer.SetGlobalTexture(ShaderIDs._GPURPHeightMap, data.resources.clusterResources.heightPool.rt); buffer.DrawProceduralIndirect(Matrix4x4.identity, clusterMat, 0, MeshTopology.Triangles, SceneController.baseBuffer.instanceCountBuffer, 0); #if UNITY_EDITOR } #endif } SceneController.RenderScene(ref data, ref opaqueFilter, ref drawSettings, ref proper.cullResults); if (useHiZ && SceneController.gpurpEnabled) { #if UNITY_EDITOR if (Application.isPlaying) #endif SceneController.DrawCluster_RecheckHiz(ref options, ref hizDepth, hizOccData, clusterMat, linearMat, cam); } if (MTerrain.current) { MTerrain.current.DrawTerrain(buffer, 0, proper.frustumPlanes); } //Draw AlphaTest /* SortingSettings st = drawSettings.sortingSettings; * st.criteria = SortingCriteria.SortingLayer | SortingCriteria.RenderQueue | SortingCriteria.OptimizeStateChanges; * drawSettings.sortingSettings = st;*/ SceneController.RenderScene(ref data, ref alphaTestFilter, ref drawSettings, ref proper.cullResults); //Draw Depth data.buffer.Blit(ShaderIDs._DepthBufferTexture, ShaderIDs._CameraDepthTexture); //Draw Motion Vector data.buffer.SetRenderTarget(color: ShaderIDs._CameraMotionVectorsTexture, depth: ShaderIDs._DepthBufferTexture); foreach (var i in gbufferCullResults) { lst[i].DrawMotionVector(buffer); } SceneController.RenderScene(ref data, ref mvFilter, ref mvDraw, ref proper.cullResults); //Draw Static Global Motion Vector data.buffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, motionVecMat, 0, 0); }
public virtual void DrawCubeMap(MPointLight lit, ref RenderClusterOptions opts, ref CubeCullingBuffer buffer, int offset) { }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { CommandBuffer buffer = data.buffer; RenderClusterOptions options = new RenderClusterOptions { command = buffer, frustumPlanes = proper.frustumPlanes, cullingShader = data.resources.shaders.gpuFrustumCulling, terrainCompute = data.resources.shaders.terrainCompute }; FilteringSettings alphaTestFilter = new FilteringSettings { layerMask = cam.cam.cullingMask, renderingLayerMask = 1, renderQueueRange = new RenderQueueRange(2450, 2499) }; FilteringSettings opaqueFilter = new FilteringSettings { layerMask = cam.cam.cullingMask, renderingLayerMask = 1, renderQueueRange = new RenderQueueRange(2000, 2449) }; FilteringSettings mvFilter = new FilteringSettings { layerMask = cam.cam.cullingMask, renderingLayerMask = 1, renderQueueRange = RenderQueueRange.opaque }; DrawingSettings depthPrePassDrawSettings = new DrawingSettings(new ShaderTagId("Depth"), new SortingSettings(cam.cam) { criteria = SortingCriteria.QuantizedFrontToBack }) { perObjectData = UnityEngine.Rendering.PerObjectData.None, enableDynamicBatching = false, enableInstancing = false }; DrawingSettings drawSettings = new DrawingSettings(new ShaderTagId("GBuffer"), new SortingSettings(cam.cam) { criteria = SortingCriteria.CommonOpaque }) { perObjectData = UnityEngine.Rendering.PerObjectData.Lightmaps, enableDynamicBatching = false, enableInstancing = false }; DrawingSettings mvDraw = new DrawingSettings(new ShaderTagId("MotionVector"), new SortingSettings { criteria = SortingCriteria.None }) { perObjectData = UnityEngine.Rendering.PerObjectData.None, enableDynamicBatching = false, enableInstancing = false }; data.buffer.SetRenderTarget(colors: cam.targets.gbufferIdentifier, depth: ShaderIDs._DepthBufferTexture); data.buffer.ClearRenderTarget(true, true, Color.black); HizOcclusionData hizOccData; if (useHiZ) { hizOccData = IPerCameraData.GetProperty(cam, () => new HizOcclusionData()); SceneController.DrawCluster_LastFrameDepthHiZ(ref options, hizOccData, clusterMat, cam); } SceneController.RenderScene(ref data, ref opaqueFilter, ref drawSettings, ref proper.cullResults); if (useHiZ) { SceneController.DrawCluster_RecheckHiz(ref options, ref hizDepth, hizOccData, clusterMat, linearMat, cam); } data.buffer.SetRenderTarget(ShaderIDs._DepthBufferTexture); SceneController.RenderScene(ref data, ref alphaTestFilter, ref depthPrePassDrawSettings, ref proper.cullResults); data.buffer.SetRenderTarget(colors: cam.targets.gbufferIdentifier, depth: ShaderIDs._DepthBufferTexture); SortingSettings st = drawSettings.sortingSettings; st.criteria = SortingCriteria.SortingLayer | SortingCriteria.RenderQueue; drawSettings.sortingSettings = st; SceneController.RenderScene(ref data, ref alphaTestFilter, ref drawSettings, ref proper.cullResults); data.buffer.Blit(ShaderIDs._DepthBufferTexture, ShaderIDs._CameraDepthTexture); data.buffer.SetRenderTarget(color: ShaderIDs._CameraMotionVectorsTexture, depth: ShaderIDs._DepthBufferTexture); SceneController.RenderScene(ref data, ref mvFilter, ref mvDraw, ref proper.cullResults); data.buffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, motionVecMat, 0, 0); decal.FrameUpdate(cam, ref data); //Generate DownSampled GBuffer if ((ao != null && ao.Enabled) || (reflection != null && reflection.Enabled && reflection.ssrEvents.enabled)) { int2 res = int2(cam.cam.pixelWidth, cam.cam.pixelHeight) / 2; data.buffer.GetTemporaryRT(ShaderIDs._DownSampledGBuffer1, res.x, res.y, 0, FilterMode.Point, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear, 1, false); data.buffer.GetTemporaryRT(ShaderIDs._DownSampledGBuffer2, res.x, res.y, 0, FilterMode.Point, RenderTextureFormat.ARGB2101010, RenderTextureReadWrite.Linear, 1, false); data.buffer.GetTemporaryRT(ShaderIDs._DownSampledDepthTexture, res.x, res.y, 0, FilterMode.Point, RenderTextureFormat.RHalf, RenderTextureReadWrite.Linear, 1, false); downSampledGBuffers[0] = ShaderIDs._DownSampledDepthTexture; downSampledGBuffers[1] = ShaderIDs._DownSampledGBuffer1; downSampledGBuffers[2] = ShaderIDs._DownSampledGBuffer2; data.buffer.SetRenderTarget(colors: downSampledGBuffers, depth: downSampledGBuffers[0]); data.buffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, downSampleMat, 0, 0); RenderPipeline.ReleaseRTAfterFrame(ShaderIDs._DownSampledGBuffer1); RenderPipeline.ReleaseRTAfterFrame(ShaderIDs._DownSampledGBuffer2); RenderPipeline.ReleaseRTAfterFrame(ShaderIDs._DownSampledDepthTexture); //TODO } }
public virtual void DrawClusterOccDoubleCheck(ref RenderClusterOptions options, ref HizOptions hizOpts, ref RenderTargets rendTargets) { }
public virtual void DrawDirectionalShadow(Camera currentCam, ref RenderClusterOptions opts, ref ShadowmapSettings settings, ref ShadowMapComponent shadMap, Matrix4x4[] cascadeShadowMapVP) { }
public virtual void DrawClusterOccSingleCheck(ref RenderClusterOptions options, ref HizOptions hizOpts) { }
public virtual void DrawCluster(ref RenderClusterOptions options) { }
public override void DrawCubeMap(MPointLight lit, ref RenderClusterOptions opts, ref CubeCullingBuffer buffer, int offset) { CommandBuffer cb = opts.command; ComputeShader shader = opts.cullingShader; Material depthMaterial = opts.proceduralMaterial; cb.SetComputeIntParam(shader, ShaderIDs._LightOffset, offset); ComputeShaderUtility.Dispatch(shader, cb, CubeFunction.RunFrustumCull, baseBuffer.clusterCount, 256); PerspCam cam = new PerspCam(); cam.aspect = 1; cam.farClipPlane = lit.range; cam.nearClipPlane = 0.3f; cam.position = lit.position; cam.fov = 90f; Matrix4x4 vpMatrix; cb.SetGlobalVector(ShaderIDs._LightPos, new Vector4(lit.position.x, lit.position.y, lit.position.z, lit.range)); cb.SetGlobalBuffer(ShaderIDs.verticesBuffer, baseBuffer.verticesBuffer); cb.SetGlobalBuffer(ShaderIDs.resultBuffer, baseBuffer.resultBuffer); //Forward cam.forward = Vector3.forward; cam.up = Vector3.down; cam.right = Vector3.left; cam.position = lit.position; cam.UpdateTRSMatrix(); cam.UpdateProjectionMatrix(); vpMatrix = GL.GetGPUProjectionMatrix(cam.projectionMatrix, true) * cam.worldToCameraMatrix; cb.SetRenderTarget(lit.shadowmapTexture, 0, CubemapFace.NegativeZ); cb.ClearRenderTarget(true, true, Color.white); cb.SetGlobalMatrix(ShaderIDs._VP, vpMatrix); offset = offset * 20; cb.DrawProceduralIndirect(Matrix4x4.identity, depthMaterial, 0, MeshTopology.Triangles, buffer.indirectDrawBuffer, offset); //Back cam.forward = Vector3.back; cam.up = Vector3.down; cam.right = Vector3.right; cam.UpdateTRSMatrix(); cam.UpdateProjectionMatrix(); vpMatrix = GL.GetGPUProjectionMatrix(cam.projectionMatrix, true) * cam.worldToCameraMatrix; cb.SetRenderTarget(lit.shadowmapTexture, 0, CubemapFace.PositiveZ); cb.ClearRenderTarget(true, true, Color.white); cb.SetGlobalMatrix(ShaderIDs._VP, vpMatrix); cb.DrawProceduralIndirect(Matrix4x4.identity, depthMaterial, 0, MeshTopology.Triangles, buffer.indirectDrawBuffer, offset); //Up cam.forward = Vector3.up; cam.up = Vector3.back; cam.right = Vector3.right; cam.UpdateTRSMatrix(); cam.UpdateProjectionMatrix(); vpMatrix = GL.GetGPUProjectionMatrix(cam.projectionMatrix, true) * cam.worldToCameraMatrix; cb.SetRenderTarget(lit.shadowmapTexture, 0, CubemapFace.PositiveY); cb.ClearRenderTarget(true, true, Color.white); cb.SetGlobalMatrix(ShaderIDs._VP, vpMatrix); cb.DrawProceduralIndirect(Matrix4x4.identity, depthMaterial, 0, MeshTopology.Triangles, buffer.indirectDrawBuffer, offset); //Down cam.forward = Vector3.down; cam.up = Vector3.forward; cam.right = Vector3.right; cam.UpdateTRSMatrix(); cam.UpdateProjectionMatrix(); vpMatrix = GL.GetGPUProjectionMatrix(cam.projectionMatrix, true) * cam.worldToCameraMatrix; cb.SetRenderTarget(lit.shadowmapTexture, 0, CubemapFace.NegativeY); cb.ClearRenderTarget(true, true, Color.white); cb.SetGlobalMatrix(ShaderIDs._VP, vpMatrix); cb.DrawProceduralIndirect(Matrix4x4.identity, depthMaterial, 0, MeshTopology.Triangles, buffer.indirectDrawBuffer, offset); //Right cam.forward = Vector3.right; cam.up = Vector3.down; cam.right = Vector3.forward; cam.UpdateTRSMatrix(); cam.UpdateProjectionMatrix(); vpMatrix = GL.GetGPUProjectionMatrix(cam.projectionMatrix, true) * cam.worldToCameraMatrix; cb.SetRenderTarget(lit.shadowmapTexture, 0, CubemapFace.PositiveX); cb.ClearRenderTarget(true, true, Color.white); cb.SetGlobalMatrix(ShaderIDs._VP, vpMatrix); cb.DrawProceduralIndirect(Matrix4x4.identity, depthMaterial, 0, MeshTopology.Triangles, buffer.indirectDrawBuffer, offset); //Left cam.forward = Vector3.left; cam.up = Vector3.down; cam.right = Vector3.back; cam.UpdateTRSMatrix(); cam.UpdateProjectionMatrix(); vpMatrix = GL.GetGPUProjectionMatrix(cam.projectionMatrix, true) * cam.worldToCameraMatrix; cb.SetRenderTarget(lit.shadowmapTexture, 0, CubemapFace.NegativeX); cb.ClearRenderTarget(true, true, Color.white); cb.SetGlobalMatrix(ShaderIDs._VP, vpMatrix); cb.DrawProceduralIndirect(Matrix4x4.identity, depthMaterial, 0, MeshTopology.Triangles, buffer.indirectDrawBuffer, offset); }
public static void DrawCluster(ref RenderClusterOptions options, ref RenderTargets targets, ref PipelineCommandData data, Camera cam) { data.buffer.SetRenderTarget(targets.gbufferIdentifier, targets.depthBuffer); data.buffer.ClearRenderTarget(true, true, Color.black); RenderScene(ref data, cam); }
public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data) { CommandBuffer buffer = data.buffer; RenderClusterOptions options = new RenderClusterOptions { command = buffer, frustumPlanes = proper.frustumPlanes, cullingShader = data.resources.shaders.gpuFrustumCulling, terrainCompute = data.resources.shaders.terrainCompute }; FilteringSettings alphaTestFilter = new FilteringSettings { layerMask = cam.cam.cullingMask, renderingLayerMask = 1, renderQueueRange = new RenderQueueRange(2450, 2499) }; FilteringSettings opaqueFilter = new FilteringSettings { layerMask = cam.cam.cullingMask, renderingLayerMask = 1, renderQueueRange = new RenderQueueRange(2000, 2449) }; FilteringSettings mvFilter = new FilteringSettings { layerMask = cam.cam.cullingMask, renderingLayerMask = 1, renderQueueRange = RenderQueueRange.opaque }; DrawingSettings depthAlphaTestDrawSettings = new DrawingSettings(new ShaderTagId("Depth"), new SortingSettings(cam.cam) { criteria = SortingCriteria.QuantizedFrontToBack | SortingCriteria.OptimizeStateChanges }) { perObjectData = UnityEngine.Rendering.PerObjectData.None, enableDynamicBatching = false, enableInstancing = false }; DrawingSettings depthOpaqueDrawSettings = new DrawingSettings(new ShaderTagId("Depth"), new SortingSettings(cam.cam) { criteria = SortingCriteria.QuantizedFrontToBack }) { perObjectData = UnityEngine.Rendering.PerObjectData.None, enableDynamicBatching = false, enableInstancing = false, overrideMaterial = proper.overrideOpaqueMaterial, overrideMaterialPassIndex = 1 }; DrawingSettings drawSettings = new DrawingSettings(new ShaderTagId("GBuffer"), new SortingSettings(cam.cam) { criteria = SortingCriteria.RenderQueue | SortingCriteria.OptimizeStateChanges }) { perObjectData = UnityEngine.Rendering.PerObjectData.Lightmaps, enableDynamicBatching = false, enableInstancing = false }; DrawingSettings mvDraw = new DrawingSettings(new ShaderTagId("MotionVector"), new SortingSettings { criteria = SortingCriteria.OptimizeStateChanges }) { perObjectData = UnityEngine.Rendering.PerObjectData.None, enableDynamicBatching = false, enableInstancing = false }; //Draw Depth Prepass data.buffer.SetRenderTarget(ShaderIDs._DepthBufferTexture); data.buffer.ClearRenderTarget(true, false, Color.black); cullHandle.Complete(); var lst = CustomDrawRequest.allEvents; foreach (var i in gbufferCullResults) { lst[i].DrawDepthPrepass(buffer); } SceneController.RenderScene(ref data, ref opaqueFilter, ref depthOpaqueDrawSettings, ref proper.cullResults); data.context.DrawRenderers(proper.cullResults, ref depthAlphaTestDrawSettings, ref alphaTestFilter); decalEvt.FrameUpdate(cam, ref data); //Draw GBuffer data.buffer.SetRenderTarget(colors: cam.targets.gbufferIdentifier, depth: ShaderIDs._DepthBufferTexture); data.buffer.ClearRenderTarget(false, true, Color.black); HizOcclusionData hizOccData; if (useHiZ) { hizOccData = IPerCameraData.GetProperty(cam, () => new HizOcclusionData()); SceneController.DrawCluster_LastFrameDepthHiZ(ref options, hizOccData, clusterMat, cam, proper.frustumMinPoint, proper.frustumMaxPoint); } foreach (var i in gbufferCullResults) { lst[i].DrawGBuffer(buffer); } SceneController.RenderScene(ref data, ref opaqueFilter, ref drawSettings, ref proper.cullResults); if (useHiZ) { SceneController.DrawCluster_RecheckHiz(ref options, ref hizDepth, hizOccData, clusterMat, linearMat, cam); } if (MTerrain.current) { MTerrain.current.DrawTerrain(buffer, 0, proper.frustumPlanes); } //Draw AlphaTest /* SortingSettings st = drawSettings.sortingSettings; * st.criteria = SortingCriteria.SortingLayer | SortingCriteria.RenderQueue | SortingCriteria.OptimizeStateChanges; * drawSettings.sortingSettings = st;*/ SceneController.RenderScene(ref data, ref alphaTestFilter, ref drawSettings, ref proper.cullResults); //Draw Depth data.buffer.Blit(ShaderIDs._DepthBufferTexture, ShaderIDs._CameraDepthTexture); //Draw Motion Vector data.buffer.SetRenderTarget(color: ShaderIDs._CameraMotionVectorsTexture, depth: ShaderIDs._DepthBufferTexture); foreach (var i in gbufferCullResults) { lst[i].DrawMotionVector(buffer); } SceneController.RenderScene(ref data, ref mvFilter, ref mvDraw, ref proper.cullResults); //Draw Static Global Motion Vector data.buffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, motionVecMat, 0, 0); }