protected override void Render(ScriptableRenderContext context, Camera[] cameras) { BeginFrameRendering(cameras); foreach (Camera camera in cameras) { BeginCameraRendering(camera); //Culling ScriptableCullingParameters cullingParams; if (!camera.TryGetCullingParameters(out cullingParams)) { continue; } CullingResults cull = context.Cull(ref cullingParams); //Camera setup some builtin variables e.g. camera projection matrices etc context.SetupCameraProperties(camera); //Get the setting from camera component bool drawSkyBox = camera.clearFlags == CameraClearFlags.Skybox? true : false; //Texture Descriptor - Color RenderTextureDescriptor rtDesc = new RenderTextureDescriptor(camera.pixelWidth, camera.pixelHeight); rtDesc.graphicsFormat = m_ColorFormat; rtDesc.depthBufferBits = 0; rtDesc.sRGB = (QualitySettings.activeColorSpace == ColorSpace.Linear); rtDesc.msaaSamples = 1; rtDesc.enableRandomWrite = false; //Texture Descriptor - Depth RenderTextureDescriptor rtDescDepth = new RenderTextureDescriptor(camera.pixelWidth, camera.pixelHeight); rtDescDepth.colorFormat = RenderTextureFormat.Depth; rtDescDepth.depthBufferBits = 24; rtDescDepth.msaaSamples = 1; rtDescDepth.enableRandomWrite = false; //Get Temp Texture for Color Texture CommandBuffer cmdTempId = new CommandBuffer(); cmdTempId.name = "(" + camera.name + ")" + "Setup TempRT"; cmdTempId.GetTemporaryRT(m_AlbedoRTid, rtDesc, FilterMode.Point); cmdTempId.GetTemporaryRT(m_EmissionRTid, rtDesc, FilterMode.Point); cmdTempId.GetTemporaryRT(m_DepthRTid, rtDescDepth, FilterMode.Point); context.ExecuteCommandBuffer(cmdTempId); cmdTempId.Release(); //Setup DrawSettings and FilterSettings var sortingSettings = new SortingSettings(camera); DrawingSettings drawSettings = new DrawingSettings(m_PassName, sortingSettings); FilteringSettings filterSettings = new FilteringSettings(RenderQueueRange.all); //Pass 1========================================================= //SetUp Multi-RenderTargets For the 1st pass & clear CommandBuffer cmdPass1 = new CommandBuffer(); mRTIDs[0] = m_AlbedoRTid; mRTIDs[1] = m_EmissionRTid; cmdPass1.SetRenderTarget(mRTIDs, m_DepthRT); cmdPass1.ClearRenderTarget(true, true, Color.black); context.ExecuteCommandBuffer(cmdPass1); cmdPass1.Release(); //Skybox if (drawSkyBox) { context.DrawSkybox(camera); } //Opaque objects sortingSettings.criteria = SortingCriteria.CommonOpaque; drawSettings.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.opaque; context.DrawRenderers(cull, ref drawSettings, ref filterSettings); //Transparent objects sortingSettings.criteria = SortingCriteria.CommonTransparent; drawSettings.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.transparent; context.DrawRenderers(cull, ref drawSettings, ref filterSettings); //Final blit==================================================== //Blit to CameraTarget, to combine the previous 2 texture results with a blit material CommandBuffer cmd = new CommandBuffer(); cmd.name = "Cam:" + camera.name + " BlitToCamera"; cmd.Blit(BuiltinRenderTextureType.CameraTarget, BuiltinRenderTextureType.CameraTarget, copyColorMaterial); context.ExecuteCommandBuffer(cmd); cmd.Release(); //CleanUp Texture CommandBuffer cmdclean = new CommandBuffer(); cmdclean.name = "(" + camera.name + ")" + "Clean Up"; cmdclean.ReleaseTemporaryRT(m_AlbedoRTid); cmdclean.ReleaseTemporaryRT(m_EmissionRTid); cmdclean.ReleaseTemporaryRT(m_DepthRTid); context.ExecuteCommandBuffer(cmdclean); cmdclean.Release(); context.Submit(); } }
private static IFileSystemNodesSortingViewModel Create(SortingSettings sortingSettings) { var sortingColumn = (SortingColumn)sortingSettings.SortingMode; return(new FileSystemNodesSortingViewModel(sortingColumn, sortingSettings.IsAscending)); }
protected override void Render(ScriptableRenderContext context, Camera[] cameras) { BeginFrameRendering(context, cameras); foreach (Camera camera in cameras) { BeginCameraRendering(context, camera); //Culling ScriptableCullingParameters cullingParams; if (!camera.TryGetCullingParameters(out cullingParams)) { continue; } CullingResults cull = context.Cull(ref cullingParams); //Camera setup some builtin variables e.g. camera projection matrices etc context.SetupCameraProperties(camera); //Get the setting from camera component bool drawSkyBox = camera.clearFlags == CameraClearFlags.Skybox? true : false; bool clearDepth = camera.clearFlags == CameraClearFlags.Nothing? false : true; bool clearColor = camera.clearFlags == CameraClearFlags.Color? true : false; //Camera clear flag CommandBuffer cmd = new CommandBuffer(); cmd.ClearRenderTarget(clearDepth, clearColor, camera.backgroundColor); context.ExecuteCommandBuffer(cmd); cmd.Release(); //Setup DrawSettings and FilterSettings var sortingSettings = new SortingSettings(camera); DrawingSettings drawSettings = new DrawingSettings(m_PassName, sortingSettings) { perObjectData = PerObjectData.Lightmaps | PerObjectData.LightProbe | PerObjectData.LightProbeProxyVolume | PerObjectData.ReflectionProbes }; FilteringSettings filterSettings = new FilteringSettings(RenderQueueRange.all); GraphicsSettings.useScriptableRenderPipelineBatching = false; // ^if it's true it breaks the baked data //Skybox if (drawSkyBox) { context.DrawSkybox(camera); } //Opaque objects sortingSettings.criteria = SortingCriteria.CommonOpaque; drawSettings.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.opaque; context.DrawRenderers(cull, ref drawSettings, ref filterSettings); //Transparent objects sortingSettings.criteria = SortingCriteria.CommonTransparent; drawSettings.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.transparent; context.DrawRenderers(cull, ref drawSettings, ref filterSettings); context.Submit(); EndCameraRendering(context, camera); } EndFrameRendering(context, cameras); }
public Task <List <TEntity> > SearchAsync(PagingInfo pagingInfo, SearchSettings <TEntity> filter = null, SortingSettings <TEntity> orderBy = null) { return(_dal.SearchAsync(pagingInfo, filter, orderBy)); }
protected override void Render(ScriptableRenderContext context, Camera[] cameras) { //base.Render(context, cameras); if (cmd == null) { cmd = new CommandBuffer(); } //int idx = 0; //foreach (var camera in cameras) for (int i = 0; i < cameras.Length; ++i) { var camera = cameras[i]; //剔除那些在摄像机视锥之外的物体 if (!camera.TryGetCullingParameters(out cullingParams)) { continue; } //调用Cull 方法把物体剔除 cull = context.Cull(ref cullingParams); //更新camera的一些view, projection and clipping planes等信息 context.SetupCameraProperties(camera); #if UNITY_EDITOR //UI 层时unity为我们在render时增加的一层overlay ,我们在编辑器时需要对这一层做剔除 if (camera.cameraType == CameraType.SceneView) { ScriptableRenderContext.EmitWorldGeometryForSceneView(camera); } #endif var clearFlags = camera.clearFlags; //清空颜色缓存和深度缓存 cmd.ClearRenderTarget( (clearFlags & CameraClearFlags.Depth) != 0, (clearFlags & CameraClearFlags.Color) != 0, ClearColor); //开始采样 // cmd.BeginSample("My Pipeline Camera"); UnityEngine.Profiling.Profiler.BeginSample("My Pipeline Camera"); context.ExecuteCommandBuffer(cmd); //清除上一帧 cmd.Clear(); context.DrawSkybox(camera); // Directional Light SetUpDirectionalLightParam(cull.visibleLights.ToList()); SortingSettings sortSets = new SortingSettings(camera); sortSets.criteria = SortingCriteria.RenderQueue; DrawCharacter(context, camera, zPrepass, sortSets); SortingSettings sortSets4 = new SortingSettings(camera); sortSets4.criteria = SortingCriteria.CommonOpaque; DrawBg(context, camera, sortSets4); SortingSettings sortSets2 = new SortingSettings(camera); sortSets2.criteria = SortingCriteria.OptimizeStateChanges; DrawCharacter(context, camera, basicPass, sortSets2); SortingSettings sortSets3 = new SortingSettings(camera); sortSets3.criteria = SortingCriteria.CommonTransparent; DrawShadow(context, camera, sortSets3); context.Submit(); UnityEngine.Profiling.Profiler.EndSample(); } }
protected override void Render(ScriptableRenderContext context, Camera[] cameras) { BeginFrameRendering(cameras); foreach (Camera camera in cameras) { BeginCameraRendering(camera); //Culling ScriptableCullingParameters cullingParams; if (!camera.TryGetCullingParameters(out cullingParams)) { continue; } CullingResults cull = context.Cull(ref cullingParams); //Camera setup some builtin variables e.g. camera projection matrices etc context.SetupCameraProperties(camera); //Get the setting from camera component bool drawSkyBox = camera.clearFlags == CameraClearFlags.Skybox? true : false; bool clearDepth = camera.clearFlags == CameraClearFlags.Nothing? false : true; bool clearColor = camera.clearFlags == CameraClearFlags.Color? true : false; //Color Texture Descriptor RenderTextureDescriptor colorRTDesc = new RenderTextureDescriptor(camera.pixelWidth, camera.pixelHeight); colorRTDesc.graphicsFormat = m_ColorFormat; colorRTDesc.depthBufferBits = depthBufferBits; colorRTDesc.sRGB = (QualitySettings.activeColorSpace == ColorSpace.Linear); colorRTDesc.msaaSamples = 1; colorRTDesc.enableRandomWrite = false; //Set Temp RT & set render target to the RT CommandBuffer cmdTempId = new CommandBuffer(); cmdTempId.name = "(" + camera.name + ")" + "Setup TempRT"; cmdTempId.GetTemporaryRT(m_ColorRTid, colorRTDesc, FilterMode.Bilinear); context.ExecuteCommandBuffer(cmdTempId); cmdTempId.Release(); //Setup DrawSettings and FilterSettings var sortingSettings = new SortingSettings(camera); DrawingSettings drawSettings = new DrawingSettings(m_PassName, sortingSettings); DrawingSettings drawSettingsDistortion = new DrawingSettings(m_PassNameDistortion, sortingSettings); FilteringSettings filterSettings = new FilteringSettings(RenderQueueRange.all); //Camera clear flag CommandBuffer cmd = new CommandBuffer(); cmd.ClearRenderTarget(clearDepth, clearColor, camera.backgroundColor); context.ExecuteCommandBuffer(cmd); cmd.Release(); //Skybox if (drawSkyBox) { context.DrawSkybox(camera); } //Opaque objects sortingSettings.criteria = SortingCriteria.CommonOpaque; drawSettings.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.opaque; context.DrawRenderers(cull, ref drawSettings, ref filterSettings); //Transparent objects sortingSettings.criteria = SortingCriteria.CommonTransparent; drawSettings.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.transparent; context.DrawRenderers(cull, ref drawSettings, ref filterSettings); //Blit to color texture CommandBuffer cmdBlitToTex = new CommandBuffer(); cmdBlitToTex.name = "(" + camera.name + ")" + "Blit to Color Texture"; cmdBlitToTex.Blit(BuiltinRenderTextureType.CameraTarget, m_ColorRT); cmdBlitToTex.SetGlobalTexture(m_ColorRTid, m_ColorRT); cmdBlitToTex.SetRenderTarget(BuiltinRenderTextureType.CameraTarget); //Blit will change target, so make sure to reset it context.ExecuteCommandBuffer(cmdBlitToTex); cmdBlitToTex.Release(); //Distortion object sortingSettings.criteria = SortingCriteria.CommonOpaque; drawSettings.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.opaque; context.DrawRenderers(cull, ref drawSettingsDistortion, ref filterSettings); //Clean Up CommandBuffer cmdclean = new CommandBuffer(); cmdclean.name = "(" + camera.name + ")" + "Clean Up"; cmdclean.ReleaseTemporaryRT(m_ColorRTid); context.ExecuteCommandBuffer(cmdclean); cmdclean.Release(); context.Submit(); } }
protected override void Render(ScriptableRenderContext context, Camera[] cameras) { BeginFrameRendering(context, cameras); foreach (Camera camera in cameras) { BeginCameraRendering(context, camera); //Culling ScriptableCullingParameters cullingParams; if (!camera.TryGetCullingParameters(out cullingParams)) { continue; } CullingResults cull = context.Cull(ref cullingParams); //Camera setup some builtin variables e.g. camera projection matrices etc context.SetupCameraProperties(camera); //Get the setting from camera component bool drawSkyBox = camera.clearFlags == CameraClearFlags.Skybox? true : false; bool clearDepth = camera.clearFlags == CameraClearFlags.Nothing? false : true; bool clearColor = camera.clearFlags == CameraClearFlags.Color? true : false; //************************** Set TempRT ************************************ CommandBuffer cmdTempId = new CommandBuffer(); cmdTempId.name = "(" + camera.name + ")" + "Setup TempRT"; //Color m_ColorFormatActive = camera.allowHDR ? m_ColorFormatHDR : m_ColorFormat; RenderTextureDescriptor colorRTDesc = new RenderTextureDescriptor(camera.pixelWidth, camera.pixelHeight); colorRTDesc.graphicsFormat = m_ColorFormatActive; colorRTDesc.depthBufferBits = depthBufferBits; //colorRTDesc.sRGB = ; colorRTDesc.msaaSamples = camera.allowMSAA ? QualitySettings.antiAliasing : 1; colorRTDesc.enableRandomWrite = false; cmdTempId.GetTemporaryRT(m_ColorRTid, colorRTDesc, FilterMode.Bilinear); //Depth RenderTextureDescriptor depthRTDesc = new RenderTextureDescriptor(camera.pixelWidth, camera.pixelHeight); depthRTDesc.colorFormat = RenderTextureFormat.Depth; depthRTDesc.depthBufferBits = depthBufferBits; cmdTempId.GetTemporaryRT(m_DepthRTid, depthRTDesc, FilterMode.Bilinear); //MotionVector RenderTextureDescriptor motionvectorRTDesc = new RenderTextureDescriptor(camera.pixelWidth, camera.pixelHeight); motionvectorRTDesc.graphicsFormat = UnityEngine.Experimental.Rendering.GraphicsFormat.R16G16_SFloat; motionvectorRTDesc.depthBufferBits = depthBufferBits; //colorRTDesc.sRGB = ; motionvectorRTDesc.msaaSamples = 1; motionvectorRTDesc.enableRandomWrite = false; cmdTempId.GetTemporaryRT(m_MotionVectorRTid, motionvectorRTDesc, FilterMode.Bilinear); context.ExecuteCommandBuffer(cmdTempId); cmdTempId.Release(); //************************** Setup DrawSettings and FilterSettings ************************************ camera.depthTextureMode |= DepthTextureMode.MotionVectors | DepthTextureMode.Depth; var sortingSettings = new SortingSettings(camera); DrawingSettings drawSettings = new DrawingSettings(m_PassName, sortingSettings); FilteringSettings filterSettings = new FilteringSettings(RenderQueueRange.all); DrawingSettings drawSettingsMotionVector = new DrawingSettings(m_PassName, sortingSettings) { perObjectData = PerObjectData.MotionVectors, overrideMaterial = motionVectorMaterial, overrideMaterialPassIndex = 0 }; FilteringSettings filterSettingsMotionVector = new FilteringSettings(RenderQueueRange.all) { excludeMotionVectorObjects = false }; DrawingSettings drawSettingsDepth = new DrawingSettings(m_PassName, sortingSettings) { //perObjectData = PerObjectData.None, overrideMaterial = depthOnlyMaterial, overrideMaterialPassIndex = 0, }; FilteringSettings filterSettingsDepth = new FilteringSettings(RenderQueueRange.all); //************************** Rendering depth ************************************ //Set RenderTarget & Camera clear flag CommandBuffer cmdDepth = new CommandBuffer(); cmdDepth.name = "(" + camera.name + ")" + "Depth Clear Flag"; cmdDepth.SetRenderTarget(m_DepthRT); //Set CameraTarget to the depth texture cmdDepth.ClearRenderTarget(true, true, Color.black); context.ExecuteCommandBuffer(cmdDepth); cmdDepth.Release(); //Opaque objects sortingSettings.criteria = SortingCriteria.CommonOpaque; drawSettingsDepth.sortingSettings = sortingSettings; filterSettingsDepth.renderQueueRange = RenderQueueRange.opaque; context.DrawRenderers(cull, ref drawSettingsDepth, ref filterSettingsDepth); //To let shader has _CameraDepthTexture CommandBuffer cmdDepthTexture = new CommandBuffer(); cmdDepthTexture.name = "(" + camera.name + ")" + "Depth Texture"; cmdDepthTexture.SetGlobalTexture(m_DepthRTid, m_DepthRT); context.ExecuteCommandBuffer(cmdDepthTexture); cmdDepthTexture.Release(); //************************** Rendering motion vectors ************************************ //Camera clear flag CommandBuffer cmdMotionvector = new CommandBuffer(); cmdMotionvector.SetRenderTarget(m_MotionVectorRT); //Set CameraTarget to the motion vector texture cmdMotionvector.ClearRenderTarget(true, true, Color.black); context.ExecuteCommandBuffer(cmdMotionvector); cmdMotionvector.Release(); //Opaque objects sortingSettings.criteria = SortingCriteria.CommonOpaque; drawSettingsMotionVector.sortingSettings = sortingSettings; filterSettingsMotionVector.renderQueueRange = RenderQueueRange.opaque; context.DrawRenderers(cull, ref drawSettingsMotionVector, ref filterSettingsMotionVector); //Camera motion vector CommandBuffer cmdCameraMotionVector = new CommandBuffer(); cmdCameraMotionVector.name = "(" + camera.name + ")" + "Camera MotionVector"; _NonJitteredVP = camera.nonJitteredProjectionMatrix * camera.worldToCameraMatrix; cmdCameraMotionVector.SetGlobalMatrix("_CamPrevViewProjMatrix", _PreviousVP); cmdCameraMotionVector.SetGlobalMatrix("_CamNonJitteredViewProjMatrix", _NonJitteredVP); cmdCameraMotionVector.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity); cmdCameraMotionVector.DrawMesh(fullscreenMesh, Matrix4x4.identity, motionVectorMaterial, 0, 1, null); // draw full screen quad to make Camera motion cmdCameraMotionVector.SetViewProjectionMatrices(camera.worldToCameraMatrix, camera.projectionMatrix); context.ExecuteCommandBuffer(cmdCameraMotionVector); cmdCameraMotionVector.Release(); //To let shader has MotionVectorTexture CommandBuffer cmdMotionVectorTexture = new CommandBuffer(); cmdMotionVectorTexture.name = "(" + camera.name + ")" + "MotionVector Texture"; cmdMotionVectorTexture.SetGlobalTexture(m_MotionVectorRTid, m_MotionVectorRT); context.ExecuteCommandBuffer(cmdMotionVectorTexture); cmdMotionVectorTexture.Release(); //************************** Rendering color ************************************ //Camera clear flag CommandBuffer cmd = new CommandBuffer(); cmd.SetRenderTarget(m_ColorRT); //Set CameraTarget to the color texture cmd.ClearRenderTarget(clearDepth, clearColor, camera.backgroundColor); context.ExecuteCommandBuffer(cmd); cmd.Release(); //Skybox if (drawSkyBox) { context.DrawSkybox(camera); } //Opaque objects sortingSettings.criteria = SortingCriteria.CommonOpaque; drawSettings.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.opaque; context.DrawRenderers(cull, ref drawSettings, ref filterSettings); //************************** SetUp Post-processing ************************************ PostProcessLayer m_CameraPostProcessLayer = camera.GetComponent <PostProcessLayer>(); bool hasPostProcessing = m_CameraPostProcessLayer != null; bool usePostProcessing = false; //bool hasOpaqueOnlyEffects = false; PostProcessRenderContext m_PostProcessRenderContext = null; if (hasPostProcessing) { m_PostProcessRenderContext = new PostProcessRenderContext(); usePostProcessing = m_CameraPostProcessLayer.enabled; //hasOpaqueOnlyEffects = m_CameraPostProcessLayer.HasOpaqueOnlyEffects(m_PostProcessRenderContext); } //************************** Opaque Post-processing ************************************ //Ambient Occlusion, Screen-spaced reflection are generally not supported for SRP //So this part is only for custom opaque post-processing // if(usePostProcessing) // { // CommandBuffer cmdpp = new CommandBuffer(); // cmdpp.name = "("+camera.name+")"+ "Post-processing Opaque"; // m_PostProcessRenderContext.Reset(); // m_PostProcessRenderContext.camera = camera; // m_PostProcessRenderContext.source = m_ColorRT; // m_PostProcessRenderContext.sourceFormat = UnityEngine.Experimental.Rendering.GraphicsFormatUtility.GetRenderTextureFormat(m_ColorFormatActive); // m_PostProcessRenderContext.destination = m_ColorRT; // m_PostProcessRenderContext.command = cmdpp; // m_PostProcessRenderContext.flip = camera.targetTexture == null; // m_CameraPostProcessLayer.RenderOpaqueOnly(m_PostProcessRenderContext); // context.ExecuteCommandBuffer(cmdpp); // cmdpp.Release(); // } //************************** Rendering Transparent Objects ************************************ sortingSettings.criteria = SortingCriteria.CommonTransparent; drawSettings.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.transparent; context.DrawRenderers(cull, ref drawSettings, ref filterSettings); //************************** Transparent Post-processing ************************************ //Bloom, Vignette, Grain, ColorGrading, LensDistortion, Chromatic Aberration, Auto Exposure, Motion Blur if (usePostProcessing) { CommandBuffer cmdpp = new CommandBuffer(); cmdpp.name = "(" + camera.name + ")" + "Post-processing Transparent"; m_PostProcessRenderContext.Reset(); m_PostProcessRenderContext.camera = camera; m_PostProcessRenderContext.source = m_ColorRT; m_PostProcessRenderContext.sourceFormat = UnityEngine.Experimental.Rendering.GraphicsFormatUtility.GetRenderTextureFormat(m_ColorFormatActive); m_PostProcessRenderContext.destination = BuiltinRenderTextureType.CameraTarget; m_PostProcessRenderContext.command = cmdpp; m_PostProcessRenderContext.flip = camera.targetTexture == null; m_CameraPostProcessLayer.Render(m_PostProcessRenderContext); context.ExecuteCommandBuffer(cmdpp); cmdpp.Release(); } else { //Make sure screen has the thing when Postprocessing is off CommandBuffer cmdBlitToCam = new CommandBuffer(); cmdBlitToCam.name = "(" + camera.name + ")" + "Blit back to Camera"; cmdBlitToCam.Blit(m_ColorRTid, BuiltinRenderTextureType.CameraTarget); context.ExecuteCommandBuffer(cmdBlitToCam); cmdBlitToCam.Release(); } //************************** Debug ************************************ if (_motionVectorDebug) { CommandBuffer cmdDebug = new CommandBuffer(); RenderTexture rt; rt = new RenderTexture(colorRTDesc); cmdDebug.Blit(BuiltinRenderTextureType.CameraTarget, BuiltinRenderTextureType.CameraTarget, motionVectorDebugMaterial); cmdDebug.Blit(BuiltinRenderTextureType.CameraTarget, rt, motionVectorDebugMaterial); //MyDebug(camera, context, rt, colorRTDesc, cmdDebug); context.ExecuteCommandBuffer(cmdDebug); cmdDebug.Release(); rt.Release(); } //************************** Clean Up ************************************ CommandBuffer cmdclean = new CommandBuffer(); cmdclean.name = "(" + camera.name + ")" + "Clean Up"; cmdclean.ReleaseTemporaryRT(m_ColorRTid); cmdclean.ReleaseTemporaryRT(m_DepthRTid); cmdclean.ReleaseTemporaryRT(m_MotionVectorRTid); context.ExecuteCommandBuffer(cmdclean); cmdclean.Release(); context.Submit(); //For camera motion vector _PreviousVP = _NonJitteredVP; EndCameraRendering(context, camera); } EndFrameRendering(context, cameras); }
protected override void Render(ScriptableRenderContext context, Camera[] cameras) { BeginFrameRendering(context, cameras); foreach (Camera camera in cameras) { BeginCameraRendering(context, camera); //Culling ScriptableCullingParameters cullingParams; if (!camera.TryGetCullingParameters(out cullingParams)) { continue; } CullingResults cull = context.Cull(ref cullingParams); //Camera setup some builtin variables e.g. camera projection matrices etc context.SetupCameraProperties(camera); //Get the setting from camera component bool drawSkyBox = camera.clearFlags == CameraClearFlags.Skybox? true : false; bool clearDepth = camera.clearFlags == CameraClearFlags.Nothing? false : true; bool clearColor = camera.clearFlags == CameraClearFlags.Color? true : false; //Color Texture Descriptor RenderTextureDescriptor colorRTDesc = new RenderTextureDescriptor(camera.pixelWidth, camera.pixelHeight); colorRTDesc.graphicsFormat = m_ColorFormat; colorRTDesc.depthBufferBits = depthBufferBits; colorRTDesc.sRGB = (QualitySettings.activeColorSpace == ColorSpace.Linear); colorRTDesc.msaaSamples = 1; colorRTDesc.enableRandomWrite = true; //For compute //Depth Texture Descriptor RenderTextureDescriptor depthRTDesc = new RenderTextureDescriptor(camera.pixelWidth, camera.pixelHeight); depthRTDesc.colorFormat = RenderTextureFormat.Depth; depthRTDesc.depthBufferBits = depthBufferBits; //Set texture temp RT CommandBuffer cmdTempId = new CommandBuffer(); cmdTempId.name = "(" + camera.name + ")" + "Setup TempRT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"; cmdTempId.GetTemporaryRT(m_ColorRTid, colorRTDesc, FilterMode.Bilinear); cmdTempId.GetTemporaryRT(m_DepthRTid, depthRTDesc, FilterMode.Bilinear); context.ExecuteCommandBuffer(cmdTempId); cmdTempId.Release(); //Setup DrawSettings and FilterSettings var sortingSettings = new SortingSettings(camera); DrawingSettings drawSettings = new DrawingSettings(m_PassName, sortingSettings); FilteringSettings filterSettings = new FilteringSettings(RenderQueueRange.all); DrawingSettings drawSettingsDepth = new DrawingSettings(m_PassName, sortingSettings) { perObjectData = PerObjectData.None, overrideMaterial = depthOnlyMaterial, overrideMaterialPassIndex = 0 }; //Clear Depth Texture CommandBuffer cmdDepth = new CommandBuffer(); cmdDepth.name = "(" + camera.name + ")" + "Depth Clear Flag"; cmdDepth.SetRenderTarget(m_DepthRT); //Set CameraTarget to the depth texture cmdDepth.ClearRenderTarget(true, true, Color.black); //这里不是移除renderTarget而是清空其RT上的颜色 context.ExecuteCommandBuffer(cmdDepth); //DebugRT------------------------------------- DebugRT = RenderTexture.GetTemporary(depthRTDesc); cmdDepth.CopyTexture(m_ColorRT, DebugIdt); //-------------------------------------------- cmdDepth.Release(); //Draw Depth with Opaque objects sortingSettings.criteria = SortingCriteria.CommonOpaque; drawSettingsDepth.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.opaque; context.DrawRenderers(cull, ref drawSettingsDepth, ref filterSettings); //Draw Depth with Transparent objects sortingSettings.criteria = SortingCriteria.CommonTransparent; drawSettingsDepth.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.transparent; context.DrawRenderers(cull, ref drawSettingsDepth, ref filterSettings); //To let shader has _CameraDepthTexture CommandBuffer cmdDepthTexture = new CommandBuffer(); cmdDepthTexture.name = "(" + camera.name + ")" + "Depth Texture"; cmdDepthTexture.SetGlobalTexture(m_DepthRTid, m_DepthRT); context.ExecuteCommandBuffer(cmdDepthTexture); cmdDepthTexture.Release(); //Camera clear flag CommandBuffer cmd = new CommandBuffer(); cmd.SetRenderTarget(m_ColorRT); //Remember to set target cmd.ClearRenderTarget(clearDepth, clearColor, camera.backgroundColor); context.ExecuteCommandBuffer(cmd); cmd.Release(); //Skybox if (drawSkyBox) { context.DrawSkybox(camera); } //Opaque objects sortingSettings.criteria = SortingCriteria.CommonOpaque; drawSettings.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.opaque; context.DrawRenderers(cull, ref drawSettings, ref filterSettings); //Transparent objects sortingSettings.criteria = SortingCriteria.CommonTransparent; drawSettings.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.transparent; context.DrawRenderers(cull, ref drawSettings, ref filterSettings); //Run Compute shader if (m_PipelineAsset.computeShader != null) { CommandBuffer cmdCompute = new CommandBuffer(); cmdCompute.name = "(" + camera.name + ")" + "Compute"; cmdCompute.SetComputeIntParam(m_PipelineAsset.computeShader, "range", m_PipelineAsset.detectRange); cmdCompute.SetComputeFloatParam(m_PipelineAsset.computeShader, "detect", m_PipelineAsset.edgeDetect); cmdCompute.SetComputeTextureParam(m_PipelineAsset.computeShader, _kernel, m_ColorRTid, m_ColorRT); cmdCompute.SetComputeTextureParam(m_PipelineAsset.computeShader, _kernel, m_DepthRTid, m_DepthRT); cmdCompute.DispatchCompute(m_PipelineAsset.computeShader, _kernel, camera.pixelWidth / 8 + 1, camera.pixelHeight / 8 + 1, 1); context.ExecuteCommandBuffer(cmdCompute); cmdCompute.Release(); } //Blit the content back to screen CommandBuffer cmdBlitToCam = new CommandBuffer(); cmdBlitToCam.name = "(" + camera.name + ")" + "Blit back to Camera"; cmdBlitToCam.Blit(m_ColorRT, BuiltinRenderTextureType.CameraTarget); context.ExecuteCommandBuffer(cmdBlitToCam); cmdBlitToCam.Release(); //Clean Up CommandBuffer cmdclean = new CommandBuffer(); cmdclean.name = "(" + camera.name + ")" + "Clean Up"; cmdclean.ReleaseTemporaryRT(m_DepthRTid); cmdclean.ReleaseTemporaryRT(m_ColorRTid); context.ExecuteCommandBuffer(cmdclean); cmdclean.Release(); context.Submit(); EndCameraRendering(context, camera); } EndFrameRendering(context, cameras); }
// Temporarily only support one camera, will render the same thing for the others. // TODO: Add support for multi-camera setups protected void Render(ScriptableRenderContext context, Camera camera) { // Culling ScriptableCullingParameters cullingParams; // TryGetCullingParameters return false if it failed to create valid params if (!camera.TryGetCullingParameters(out cullingParams)) { return; } // Inject world space UI into scene view #if UNITY_EDITOR if (camera.cameraType == CameraType.SceneView) { ScriptableRenderContext.EmitWorldGeometryForSceneView(camera); } #endif // Sends culling instructions to context cullingResults = context.Cull(ref cullingParams); // Sets up camera specific global shader params context.SetupCameraProperties(camera); // Explicitly clear the render target with command buffers CameraClearFlags clearFlags = camera.clearFlags; cameraBuffer.ClearRenderTarget( (clearFlags & CameraClearFlags.Depth) != 0, (clearFlags & CameraClearFlags.Color) != 0, camera.backgroundColor ); ConfigureLights(); cameraBuffer.BeginSample("Render Camera"); // Setup light buffers cameraBuffer.SetGlobalVectorArray(visibleLightColorsId, visibleLightColors); cameraBuffer.SetGlobalVectorArray(visibleLightDirectionsOrPositionsId, visibleLightDirectionsOrPositions); cameraBuffer.SetGlobalVectorArray(visibleLightAttenuationId, visibleLightAttenuations); cameraBuffer.SetGlobalVectorArray(visibleLightSpotDirectionId, visibleLightSpotDirections); context.ExecuteCommandBuffer(cameraBuffer); cameraBuffer.Clear(); // Setup default shaders for drawing DrawingSettings drawingSettings = new DrawingSettings(); drawingSettings.SetShaderPassName(0, new ShaderTagId(MYST_SHADERID_DEFAULT_UNLIT)); drawingSettings.enableDynamicBatching = (currentPipelineFlags & PipelineFlags.DynamicBatching) != 0; drawingSettings.enableInstancing = (currentPipelineFlags & PipelineFlags.Instancing) != 0; // Setup default sort mode SortingSettings sortingSettings = new SortingSettings(camera); drawingSettings.sortingSettings = sortingSettings; // Filters objects to draw different stuff in each pass FilteringSettings filterSettings = new FilteringSettings(RenderQueueRange.all); // Setup sort mode for opaque (front to back) sortingSettings.criteria = SortingCriteria.CommonOpaque; drawingSettings.sortingSettings = sortingSettings; // Render opaque pass filterSettings.renderQueueRange = RenderQueueRange.opaque; context.DrawRenderers(cullingResults, ref drawingSettings, ref filterSettings); // Sends instructions to draw skybox // context.DrawSkybox(camera); // Setup sort mode for transparent (back to front) sortingSettings.criteria = SortingCriteria.CommonTransparent; drawingSettings.sortingSettings = sortingSettings; // Render transparent pass filterSettings.renderQueueRange = RenderQueueRange.transparent; context.DrawRenderers(cullingResults, ref drawingSettings, ref filterSettings); // Fallback for everything else DrawDefaultPipeline(context, camera); cameraBuffer.EndSample("Render Camera"); context.ExecuteCommandBuffer(cameraBuffer); cameraBuffer.Clear(); // Submit render loop for execution context.Submit(); }
void Render(ScriptableRenderContext context, Camera camera) { //culling if (!camera.TryGetCullingParameters(out cullingParameters)) { return; } cullingParameters.shadowDistance = Mathf.Min(shadowDistance, camera.farClipPlane); #if UNITY_EDITOR if (camera.cameraType == CameraType.SceneView) { ScriptableRenderContext.EmitWorldGeometryForSceneView(camera); } #endif culling = context.Cull(ref cullingParameters); //获取可见的方向光 if (culling.visibleLights.Length > 0) { ConfigureLights(); if (mainLightExists) { RenderCascadedShadows(context); } else { CoreUtils.SetKeyword(cameraBuffer, cascadedShadowsHardKeyword, false); CoreUtils.SetKeyword(cameraBuffer, cascadedShadowsSoftKeyword, false); } if (shadowTileCount > 0) { RenderShadows(context); } else { CoreUtils.SetKeyword(cameraBuffer, shadowsHardKeyword, false); CoreUtils.SetKeyword(cameraBuffer, shadowsSoftKeyword, false); } } else { Shader.SetGlobalVector(unity_LightDataId, Vector4.zero); CoreUtils.SetKeyword(cameraBuffer, shadowsHardKeyword, false); CoreUtils.SetKeyword(cameraBuffer, shadowsSoftKeyword, false); CoreUtils.SetKeyword(cameraBuffer, cascadedShadowsHardKeyword, false); CoreUtils.SetKeyword(cameraBuffer, cascadedShadowsSoftKeyword, false); } ConfigureLights(); //将相机的属性(比如相机的视口矩阵)出入shader context.SetupCameraProperties(camera); //根据相机设置来清理RT CameraClearFlags clearFlags = camera.clearFlags; cameraBuffer.ClearRenderTarget((clearFlags & CameraClearFlags.Depth) != 0, (clearFlags & CameraClearFlags.Color) != 0, camera.backgroundColor); cameraBuffer.BeginSample(commandCameraBufferName); //将方向光的颜色和方向传入shader cameraBuffer.SetGlobalVectorArray(visibleLightColorsId, visibleLightColors); cameraBuffer.SetGlobalVectorArray(visibleLightDirectionsOrPositionsId, visibleLightDirectionsOrPositions); cameraBuffer.SetGlobalVectorArray(visibleLightAttenuationsId, visibleLightAttenuations); cameraBuffer.SetGlobalVectorArray(visibleLightSpotDirectionsId, visibleLightSpotDirections); context.ExecuteCommandBuffer(cameraBuffer); cameraBuffer.Clear(); //Drawing SortingSettings sortingSettings = new SortingSettings(camera) { criteria = SortingCriteria.CommonOpaque }; DrawingSettings drawingSettings = new DrawingSettings(shaderTagId, sortingSettings) { enableDynamicBatching = enableDynamicBatching, enableInstancing = enableGPUInstancing, perObjectData = PerObjectData.None }; if (culling.visibleLights.Length > 0) { drawingSettings.perObjectData = PerObjectData.LightIndices | PerObjectData.LightData; } drawingSettings.perObjectData |= PerObjectData.LightProbe | PerObjectData.ReflectionProbes | PerObjectData.Lightmaps | PerObjectData.LightProbeProxyVolume; FilteringSettings filteringSettings = new FilteringSettings(RenderQueueRange.opaque, -1); context.DrawRenderers(culling, ref drawingSettings, ref filteringSettings); context.DrawSkybox(camera); //透明的渲染需要在skybox后面 sortingSettings.criteria = SortingCriteria.CommonTransparent; filteringSettings.renderQueueRange = RenderQueueRange.transparent; context.DrawRenderers(culling, ref drawingSettings, ref filteringSettings); // DrawDefaultPipeline(context, camera); cameraBuffer.EndSample(commandCameraBufferName); context.ExecuteCommandBuffer(cameraBuffer); cameraBuffer.Clear(); context.Submit(); if (shadowMap) { RenderTexture.ReleaseTemporary(shadowMap); shadowMap = null; } if (cascadedShadowMap) { RenderTexture.ReleaseTemporary(cascadedShadowMap); cascadedShadowMap = null; } }
/// <summary> /// 绘制场景 /// </summary> private void drawVisibleGeometry() { //渲染不透明物体 var sortingSettings = new SortingSettings(m_camera) { criteria = SortingCriteria.CommonOpaque }; var drawingSettings = new DrawingSettings(s_unlitShaderTagId, sortingSettings); var filteringSettings = new FilteringSettings(RenderQueueRange.opaque); //设置单个物体输入灯光数据 if (m_cullingResults.visibleLights.Length > 0) { drawingSettings.perObjectData = PerObjectData.LightData | PerObjectData.LightIndices; } //设置启用反射探针 drawingSettings.perObjectData |= PerObjectData.ReflectionProbes; //是否开启动态批处理 drawingSettings.enableDynamicBatching = m_rpp.bDynamicBatching; //是否开启GPU Instancing drawingSettings.enableInstancing = m_rpp.bInsancing; //提交绘制命令 m_context.DrawRenderers(m_cullingResults, ref drawingSettings, ref filteringSettings); //处理不透明物体的后处理 if (m_activeStack) { if (m_needsDepthOnlyPass) { //单独渲染一次深度纹理 var sortSetting = new SortingSettings(m_camera); var depthOnlyDrawSettings = new DrawingSettings(new ShaderTagId("DepthOnly"), sortSetting); var depthOnlyFilterSettings = new FilteringSettings(); depthOnlyFilterSettings.renderQueueRange = RenderQueueRange.opaque; m_cameraBuffer.SetRenderTarget(s_cameraDepthTextureId, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store); m_cameraBuffer.ClearRenderTarget(true, false, Color.clear); executeBuffer(m_cameraBuffer); m_context.DrawRenderers(m_cullingResults, ref depthOnlyDrawSettings, ref depthOnlyFilterSettings); } SPostProcessingParam p = new SPostProcessingParam { cb = m_postProcessingBuffer, cameraColorId = s_cameraColorTextureId, cameraDepthId = s_cameraDepthTextureId, width = m_renderSize.x, height = m_renderSize.y, samples = m_renderSamples, format = m_format }; //调用不透明后处理 m_activeStack.RenderAfterOpaque(p); executeBuffer(m_postProcessingBuffer); //设置相机渲染纹理 if (m_needsDirectDepth) { m_cameraBuffer.SetRenderTarget(s_cameraColorTextureId, RenderBufferLoadAction.Load, RenderBufferStoreAction.Store, s_cameraDepthTextureId, RenderBufferLoadAction.Load, RenderBufferStoreAction.Store); } else { m_cameraBuffer.SetRenderTarget(s_cameraColorTextureId, RenderBufferLoadAction.Load, RenderBufferStoreAction.Store); } executeBuffer(m_cameraBuffer); } //渲染天空盒 m_context.DrawSkybox(m_camera); //渲染不透明物体 sortingSettings.criteria = SortingCriteria.CommonTransparent; drawingSettings.sortingSettings = sortingSettings; filteringSettings.renderQueueRange = RenderQueueRange.transparent; m_context.DrawRenderers(m_cullingResults, ref drawingSettings, ref filteringSettings); //进行不透明后处理 if (m_renderToTexture) { //进行后处理 if (m_activeStack) { m_activeStack.RenderAfterTransparent(); executeBuffer(m_postProcessingBuffer); } else { m_cameraBuffer.Blit(s_cameraColorTextureId, BuiltinRenderTextureType.CameraTarget); } //释放掉相机纹理 m_cameraBuffer.ReleaseTemporaryRT(s_cameraColorTextureId); if (m_needsDepth) { m_cameraBuffer.ReleaseTemporaryRT(s_cameraDepthTextureId); } } }
//这个函数会在绘制管线时调用,两个参数,第一个为所有的渲染相关内容(不只有 //渲染目标,同时还有灯光,反射探针,光照探针等等相关东西),第二个为相机组 protected override void Render(ScriptableRenderContext renderContext, Camera[] cameras) { //渲染开始后,创建CommandBuffer; if (myCommandBuffer == null) { myCommandBuffer = new CommandBuffer() { name = "SRP Study CB" } } ; //将shader中需要的属性参数映射为ID,加速传参 var _LightDir0 = Shader.PropertyToID("_DLightDir"); var _LightColor0 = Shader.PropertyToID("_DLightColor"); var _CameraPos = Shader.PropertyToID("_CameraPos"); //全部相机逐次渲染 foreach (var camera in cameras) { //设置渲染相关相机参数,包含相机的各个矩阵和剪裁平面等 renderContext.SetupCameraProperties(camera); //剪裁,这边应该是相机的视锥剪裁相关。 //自定义一个剪裁参数,cullParam类里有很多可以设置的东西。我们先简单采用相机的默认剪裁参数。 ScriptableCullingParameters cullParam = new ScriptableCullingParameters(); //直接使用相机默认剪裁参数 camera.TryGetCullingParameters(out cullParam); //非正交相机 cullParam.isOrthographic = false; //获取剪裁之后的全部结果(其中不仅有渲染物体,还有相关的其他渲染要素) CullingResults cullResults = renderContext.Cull(ref cullParam); //渲染时,会牵扯到渲染排序,所以先要进行一个相机的排序设置,这里Unity内置了一些默认的排序可以调用 //在剪裁结果中获取灯光并进行参数获取 var lights = cullResults.visibleLights; myCommandBuffer.name = "Render Lights"; foreach (var light in lights) { //判断灯光类型 if (light.lightType != LightType.Directional) { continue; } //获取灯光参数,平行光朝向即为灯光Z轴方向。矩阵第一到三列分别为xyz轴项,第四列为位置。 Vector4 lightpos = light.localToWorldMatrix.GetColumn(2); //灯光方向反向。默认管线中,unity提供的平行光方向也是灯光反向。光照计算决定 Vector4 lightDir = -lightpos; //方向的第四个值(W值)为0,点为1. lightDir.w = 0; //这边获取的灯光的finalColor是灯光颜色乘上强度之后的值,也正好是shader需要的值 Color lightColor = light.finalColor; //利用CommandBuffer进行参数传递。 myCommandBuffer.SetGlobalVector(_LightDir0, lightDir); myCommandBuffer.SetGlobalColor(_LightColor0, lightColor); break; } //传入相机参数。注意是世界空间位置。 Vector4 cameraPos = camera.transform.position; myCommandBuffer.SetGlobalVector(_CameraPos, cameraPos); //执行CommandBuffer中的指令 renderContext.ExecuteCommandBuffer(myCommandBuffer); myCommandBuffer.Clear(); SortingSettings sortSet = new SortingSettings(camera) { criteria = SortingCriteria.CommonOpaque }; //这边进行渲染的相关设置,需要指定渲染的shader的光照模式(就是这里,如果shader中没有标注LightMode的 //话,使用该shader的物体就没法进行渲染了)和上面的排序设置两个参数 DrawingSettings drawSet = new DrawingSettings(new ShaderTagId("BaseLit"), sortSet); //这边是指定渲染的种类(对应shader中的Rendertype)和相关Layer的设置(-1表示全部layer) FilteringSettings filtSet = new FilteringSettings(RenderQueueRange.opaque, -1); renderContext.DrawRenderers(cullResults, ref drawSet, ref filtSet); //绘制天空球 renderContext.DrawSkybox(camera); //开始执行上下文 renderContext.Submit(); } } }
protected override void Render(ScriptableRenderContext context, Camera[] cameras) { BeginFrameRendering(cameras); foreach (Camera camera in cameras) { BeginCameraRendering(camera); //Culling ScriptableCullingParameters cullingParams; if (!camera.TryGetCullingParameters(out cullingParams)) { continue; } CullingResults cull = context.Cull(ref cullingParams); //Camera setup some builtin variables e.g. camera projection matrices etc context.SetupCameraProperties(camera); //Get the setting from camera component bool drawSkyBox = camera.clearFlags == CameraClearFlags.Skybox? true : false; bool clearDepth = camera.clearFlags == CameraClearFlags.Nothing? false : true; bool clearColor = camera.clearFlags == CameraClearFlags.Color? true : false; //Camera clear flag CommandBuffer cmd = new CommandBuffer(); cmd.ClearRenderTarget(clearDepth, clearColor, camera.backgroundColor); context.ExecuteCommandBuffer(cmd); cmd.Release(); //Setup DrawSettings and FilterSettings var sortingSettings = new SortingSettings(camera); DrawingSettings drawSettings = new DrawingSettings(m_PassName, sortingSettings); FilteringSettings filterSettings = new FilteringSettings(RenderQueueRange.all); //Skybox if (drawSkyBox) { context.DrawSkybox(camera); } //SceneViewDrawMode #if UNITY_EDITOR bool isSceneViewCam = camera.cameraType == CameraType.SceneView; if (isSceneViewCam) { Material debugMaterial = CustomDrawModeAssetObject.GetDrawModeMaterial(); if (debugMaterial != null) { sortingSettings.criteria = SortingCriteria.None; filterSettings.renderQueueRange = RenderQueueRange.all; DrawingSettings debugSettings = new DrawingSettings(new ShaderTagId("debugMaterial"), sortingSettings) { perObjectData = PerObjectData.None, overrideMaterial = debugMaterial, overrideMaterialPassIndex = 0 }; debugSettings.SetShaderPassName(1, m_PassName); context.DrawRenderers(cull, ref debugSettings, ref filterSettings); context.Submit(); continue; } } #endif //Opaque objects sortingSettings.criteria = SortingCriteria.CommonOpaque; drawSettings.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.opaque; context.DrawRenderers(cull, ref drawSettings, ref filterSettings); //Transparent objects sortingSettings.criteria = SortingCriteria.CommonTransparent; drawSettings.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.transparent; context.DrawRenderers(cull, ref drawSettings, ref filterSettings); context.Submit(); } }
protected override void Render(ScriptableRenderContext context, Camera[] cameras) { BeginFrameRendering(context, cameras); foreach (Camera camera in cameras) { BeginCameraRendering(context, camera); //Culling ScriptableCullingParameters cullingParams; if (!camera.TryGetCullingParameters(out cullingParams)) { continue; } CullingResults cull = context.Cull(ref cullingParams); //Camera setup some builtin variables e.g. camera projection matrices etc context.SetupCameraProperties(camera); //Get the setting from camera component bool drawSkyBox = camera.clearFlags == CameraClearFlags.Skybox? true : false; bool clearDepth = camera.clearFlags == CameraClearFlags.Nothing? false : true; bool clearColor = camera.clearFlags == CameraClearFlags.Color? true : false; //Set Depth texture temp RT CommandBuffer cmdTempId = new CommandBuffer(); cmdTempId.name = "(" + camera.name + ")" + "Setup TempRT"; RenderTextureDescriptor depthRTDesc = new RenderTextureDescriptor(camera.pixelWidth, camera.pixelHeight); depthRTDesc.colorFormat = RenderTextureFormat.Depth; depthRTDesc.depthBufferBits = depthBufferBits; cmdTempId.GetTemporaryRT(m_DepthRTid, depthRTDesc, FilterMode.Bilinear); context.ExecuteCommandBuffer(cmdTempId); cmdTempId.Release(); //Setup DrawSettings and FilterSettings var sortingSettings = new SortingSettings(camera); DrawingSettings drawSettings = new DrawingSettings(m_PassName, sortingSettings); FilteringSettings filterSettings = new FilteringSettings(RenderQueueRange.all); DrawingSettings drawSettingsDepth = new DrawingSettings(m_PassName, sortingSettings) { perObjectData = PerObjectData.None, overrideMaterial = depthOnlyMaterial, overrideMaterialPassIndex = 0 }; //Clear Depth Textureß CommandBuffer cmdDepth = new CommandBuffer(); cmdDepth.name = "(" + camera.name + ")" + "Depth Clear Flag"; cmdDepth.SetRenderTarget(m_DepthRT); //Set CameraTarget to the depth texture cmdDepth.ClearRenderTarget(false, true, Color.green); //debug MyDebug(camera, context, m_DepthRT, depthRTDesc, null); context.ExecuteCommandBuffer(cmdDepth); cmdDepth.Release(); //Draw Depth with Opaque objects sortingSettings.criteria = SortingCriteria.CommonOpaque; drawSettingsDepth.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.opaque; context.DrawRenderers(cull, ref drawSettingsDepth, ref filterSettings); //To let shader has _CameraDepthTexture CommandBuffer cmdDepthTexture = new CommandBuffer(); cmdDepthTexture.name = "(" + camera.name + ")" + "Depth Texture"; cmdDepthTexture.SetGlobalTexture(m_DepthRTid, m_DepthRT); context.ExecuteCommandBuffer(cmdDepthTexture); cmdDepthTexture.Release(); //Camera clear flag CommandBuffer cmd = new CommandBuffer(); cmd.SetRenderTarget(BuiltinRenderTextureType.CameraTarget); //Rember to reset target cmd.ClearRenderTarget(clearDepth, clearColor, camera.backgroundColor); context.ExecuteCommandBuffer(cmd); cmd.Release(); //Skybox if (drawSkyBox) { context.DrawSkybox(camera); } AfterSkybox(camera, context); //Opaque objects sortingSettings.criteria = SortingCriteria.CommonOpaque; drawSettings.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.opaque; context.DrawRenderers(cull, ref drawSettings, ref filterSettings); AfterOpaqueObject(camera, context); //Transparent objects sortingSettings.criteria = SortingCriteria.CommonTransparent; drawSettings.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.transparent; context.DrawRenderers(cull, ref drawSettings, ref filterSettings); //Clean Up CommandBuffer cmdclean = new CommandBuffer(); cmdclean.name = "(" + camera.name + ")" + "Clean Up"; cmdclean.ReleaseTemporaryRT(m_DepthRTid); context.ExecuteCommandBuffer(cmdclean); cmdclean.Release(); context.Submit(); EndCameraRendering(context, camera); } EndFrameRendering(context, cameras); }
protected override void Render(ScriptableRenderContext context, Camera[] cameras) { BeginFrameRendering(cameras); foreach (Camera camera in cameras) { BeginCameraRendering(camera); //Culling ScriptableCullingParameters cullingParams; if (!camera.TryGetCullingParameters(out cullingParams)) { continue; } CullingResults cull = context.Cull(ref cullingParams); //Camera setup some builtin variables e.g. camera projection matrices etc context.SetupCameraProperties(camera); //Get the setting from camera component bool drawSkyBox = camera.clearFlags == CameraClearFlags.Skybox? true : false; bool clearDepth = camera.clearFlags == CameraClearFlags.Nothing? false : true; bool clearColor = camera.clearFlags == CameraClearFlags.Color? true : false; //Camera clear flag CommandBuffer cmd = new CommandBuffer(); cmd.ClearRenderTarget(clearDepth, clearColor, camera.backgroundColor); context.ExecuteCommandBuffer(cmd); cmd.Release(); //Setup DrawSettings and FilterSettings SortingSettings sortingSettings = new SortingSettings(camera); DrawingSettings drawSettings = new DrawingSettings(m_PassName, sortingSettings); FilteringSettings filterSettings = new FilteringSettings(RenderQueueRange.all); //Skybox if (drawSkyBox) { context.DrawSkybox(camera); } //Opaque objects sortingSettings.criteria = SortingCriteria.CommonOpaque; drawSettings.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.opaque; context.DrawRenderers(cull, ref drawSettings, ref filterSettings); //Error Opaque //DrawErrorShader(context,sortingSettings,cull,filterSettings); //Transparent objects sortingSettings.criteria = SortingCriteria.CommonTransparent; drawSettings.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.transparent; context.DrawRenderers(cull, ref drawSettings, ref filterSettings); //Error Opaque+Transparent DrawErrorShader(context, sortingSettings, cull, filterSettings); context.Submit(); } }
protected override void Render(ScriptableRenderContext context, Camera[] cameras) { BeginFrameRendering(context, cameras); foreach (Camera camera in cameras) { BeginCameraRendering(context, camera); //Culling ScriptableCullingParameters cullingParams; if (!camera.TryGetCullingParameters(out cullingParams)) { continue; } CullingResults cull = context.Cull(ref cullingParams); //Camera setup some builtin variables e.g. camera projection matrices etc context.SetupCameraProperties(camera); //SetUp Lighting variables SetUpRealtimeLightingVariables(context, cull); //Get the setting from camera component bool drawSkyBox = camera.clearFlags == CameraClearFlags.Skybox? true : false; bool clearDepth = camera.clearFlags == CameraClearFlags.Nothing? false : true; bool clearColor = camera.clearFlags == CameraClearFlags.Color? true : false; //Camera clear flag var cmd = CommandBufferPool.Get("Clear"); cmd.ClearRenderTarget(clearDepth, clearColor, camera.backgroundColor); context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); //Setup DrawSettings and FilterSettings var sortingSettings = new SortingSettings(camera); DrawingSettings drawSettings = new DrawingSettings(m_PassName, sortingSettings) { perObjectData = PerObjectData.LightIndices | PerObjectData.LightData }; FilteringSettings filterSettings = new FilteringSettings(RenderQueueRange.all); if (!GraphicsSettings.useScriptableRenderPipelineBatching) { Debug.Log("SRP Batcher is turned off so enabling it for this RenderPipeline now."); GraphicsSettings.useScriptableRenderPipelineBatching = true; } //Skybox if (drawSkyBox) { context.DrawSkybox(camera); } //Opaque objects sortingSettings.criteria = SortingCriteria.CommonOpaque; drawSettings.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.opaque; context.DrawRenderers(cull, ref drawSettings, ref filterSettings); //Transparent objects sortingSettings.criteria = SortingCriteria.CommonTransparent; drawSettings.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.transparent; context.DrawRenderers(cull, ref drawSettings, ref filterSettings); context.Submit(); EndCameraRendering(context, camera); } EndFrameRendering(context, cameras); }
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 } }
protected override void Render(ScriptableRenderContext context, Camera[] cameras) { BeginFrameRendering(context, cameras); foreach (Camera camera in cameras) { BeginCameraRendering(context, camera); //Culling ScriptableCullingParameters cullingParams; if (!camera.TryGetCullingParameters(out cullingParams)) { continue; } CullingResults cull = context.Cull(ref cullingParams); //Camera setup some builtin variables e.g. camera projection matrices etc context.SetupCameraProperties(camera); //Get the setting from camera component bool drawSkyBox = camera.clearFlags == CameraClearFlags.Skybox? true : false; bool clearDepth = camera.clearFlags == CameraClearFlags.Nothing? false : true; bool clearColor = camera.clearFlags == CameraClearFlags.Color? true : false; //Color Texture Descriptor RenderTextureDescriptor colorRTDesc = new RenderTextureDescriptor(camera.pixelWidth, camera.pixelHeight); colorRTDesc.graphicsFormat = m_ColorFormat; colorRTDesc.depthBufferBits = depthBufferBits; colorRTDesc.sRGB = (QualitySettings.activeColorSpace == ColorSpace.Linear); colorRTDesc.msaaSamples = 1; colorRTDesc.enableRandomWrite = false; //Setup DrawSettings and FilterSettings var sortingSettings = new SortingSettings(camera); DrawingSettings drawSettings = new DrawingSettings(m_PassName, sortingSettings); FilteringSettings filterSettings = new FilteringSettings(RenderQueueRange.all); //cmd.BeginSample("xxx"); //cmd.EndSample("xxx"); //UnityEngine.Profiling.Profiler.BeginSample("xxx"); //UnityEngine.Profiling.Profiler.EndSample(); //Camera clear flag { debugTag = "Debug - ClearRenderTarget"; CommandBuffer cmd = CommandBufferPool.Get(debugTag); using (new ProfilingSample(cmd, debugTag)) { context.ExecuteCommandBuffer(cmd); cmd.Clear(); // cmd.GetTemporaryRT(m_ColorRTid, colorRTDesc, FilterMode.Bilinear); cmd.SetRenderTarget(m_ColorRT); cmd.ClearRenderTarget(clearDepth, clearColor, camera.backgroundColor); // } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); } // Skybox { debugTag = "Debug - DrawSkyBox"; CommandBuffer cmd = CommandBufferPool.Get(debugTag); using (new ProfilingSample(cmd, debugTag)) { context.ExecuteCommandBuffer(cmd); cmd.Clear(); // if (drawSkyBox) { context.DrawSkybox(camera); } // } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); } //Opaque objects { debugTag = "Debug - DrawOpaqueObjects"; CommandBuffer cmd = CommandBufferPool.Get(debugTag); using (new ProfilingSample(cmd, debugTag)) { context.ExecuteCommandBuffer(cmd); cmd.Clear(); // sortingSettings.criteria = SortingCriteria.CommonOpaque; drawSettings.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.opaque; context.DrawRenderers(cull, ref drawSettings, ref filterSettings); // } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); } //Transparent objects { debugTag = "Debug - DrawTransparentObjects"; CommandBuffer cmd = CommandBufferPool.Get(debugTag); using (new ProfilingSample(cmd, debugTag)) { context.ExecuteCommandBuffer(cmd); cmd.Clear(); // sortingSettings.criteria = SortingCriteria.CommonTransparent; drawSettings.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.transparent; context.DrawRenderers(cull, ref drawSettings, ref filterSettings); // } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); } //Blit to screen { debugTag = "Debug - BlitToScreen"; CommandBuffer cmd = CommandBufferPool.Get(debugTag); using (new ProfilingSample(cmd, debugTag)) { context.ExecuteCommandBuffer(cmd); cmd.Clear(); // cmd.Blit(m_ColorRT, BuiltinRenderTextureType.CameraTarget); // } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); } //Clean Up { debugTag = "Debug - CleanUp"; CommandBuffer cmd = CommandBufferPool.Get(debugTag); using (new ProfilingSample(cmd, debugTag)) { context.ExecuteCommandBuffer(cmd); cmd.Clear(); // cmd.ReleaseTemporaryRT(m_ColorRTid); // } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); } context.Submit(); EndCameraRendering(context, camera); } EndFrameRendering(context, cameras); }
protected override void Render(ScriptableRenderContext context, Camera[] cameras) { BeginFrameRendering(cameras); foreach (Camera camera in cameras) { #if UNITY_EDITOR bool isSceneViewCam = camera.cameraType == CameraType.SceneView; if (isSceneViewCam) { ScriptableRenderContext.EmitWorldGeometryForSceneView(camera); //This makes the UI Canvas geometry appear on scene view } #endif BeginCameraRendering(camera); //Culling ScriptableCullingParameters cullingParams; if (!camera.TryGetCullingParameters(out cullingParams)) { continue; } CullingResults cull = context.Cull(ref cullingParams); //Camera setup some builtin variables e.g. camera projection matrices etc context.SetupCameraProperties(camera); //Get the setting from camera component bool drawSkyBox = camera.clearFlags == CameraClearFlags.Skybox? true : false; bool clearDepth = camera.clearFlags == CameraClearFlags.Nothing? false : true; bool clearColor = camera.clearFlags == CameraClearFlags.Color? true : false; //Camera clear flag CommandBuffer cmd = new CommandBuffer(); cmd.ClearRenderTarget(clearDepth, clearColor, camera.backgroundColor); context.ExecuteCommandBuffer(cmd); cmd.Release(); //Setup DrawSettings and FilterSettings var sortingSettings = new SortingSettings(camera); DrawingSettings drawSettings = new DrawingSettings(m_PassName, sortingSettings); DrawingSettings drawSettingsDefault = new DrawingSettings(m_PassNameDefault, sortingSettings); //This will let you draw shader passes without the LightMode, //thus it draws the default UGUI materials drawSettingsDefault.SetShaderPassName(1, m_PassNameDefault); FilteringSettings filterSettings = new FilteringSettings(RenderQueueRange.all); //Skybox if (drawSkyBox) { context.DrawSkybox(camera); } //Opaque objects sortingSettings.criteria = SortingCriteria.CommonOpaque; drawSettings.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.opaque; context.DrawRenderers(cull, ref drawSettings, ref filterSettings); //Opaque default context.DrawRenderers(cull, ref drawSettingsDefault, ref filterSettings); //Transparent objects sortingSettings.criteria = SortingCriteria.CommonTransparent; drawSettings.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.transparent; context.DrawRenderers(cull, ref drawSettings, ref filterSettings); //Transparent default context.DrawRenderers(cull, ref drawSettingsDefault, ref filterSettings); //SceneView fix, so that it draws the gizmos on scene view #if UNITY_EDITOR if (isSceneViewCam) { context.DrawGizmos(camera, GizmoSubset.PostImageEffects); } #endif context.Submit(); } }
protected override void Render(ScriptableRenderContext context, Camera[] cameras) { BeginFrameRendering(cameras); foreach (Camera camera in cameras) { BeginCameraRendering(camera); //Culling ScriptableCullingParameters cullingParams; if (!camera.TryGetCullingParameters(out cullingParams)) { continue; } CullingResults cull = context.Cull(ref cullingParams); //Camera setup some builtin variables e.g. camera projection matrices etc context.SetupCameraProperties(camera); //Get the setting from camera component bool drawSkyBox = camera.clearFlags == CameraClearFlags.Skybox? true : false; bool clearDepth = camera.clearFlags == CameraClearFlags.Nothing? false : true; bool clearColor = camera.clearFlags == CameraClearFlags.Color? true : false; //Camera clear flag CommandBuffer cmd = new CommandBuffer(); cmd.ClearRenderTarget(clearDepth, clearColor, camera.backgroundColor); context.ExecuteCommandBuffer(cmd); cmd.Release(); //Setup DrawSettings and FilterSettings var sortingSettings = new SortingSettings(camera); DrawingSettings drawSettings = new DrawingSettings(m_PassName, sortingSettings); FilteringSettings filterSettings = new FilteringSettings(RenderQueueRange.all); //Skybox if (drawSkyBox) { context.DrawSkybox(camera); } //Define positions positions.Clear(); Vector4 pos = Vector4.zero; int splitRow = 5; for (int i = 0; i < m_PipelineAsset.count; i++) { pos.x = i % splitRow; pos.y = Mathf.FloorToInt(i / splitRow); pos.z = 0; pos.w = 1; positions.Add(pos); } //SetUp Position Computebuffers Data positionBuffer = new ComputeBuffer(m_PipelineAsset.count, 16); //4*4 bytes for Vector4 positionBuffer.SetData(positions); m_MaterialPropertyBlock.SetBuffer("positionBuffer", positionBuffer); //SetUp Args Computebuffers Data argsBuffer = new ComputeBuffer(1, args.Length * sizeof(uint), ComputeBufferType.IndirectArguments); args[0] = (uint)m_PipelineAsset.mesh.GetIndexCount(0); args[1] = (uint)m_PipelineAsset.count; args[2] = (uint)m_PipelineAsset.mesh.GetIndexStart(0); args[3] = (uint)m_PipelineAsset.mesh.GetBaseVertex(0); argsBuffer.SetData(args); //Draw Commands CommandBuffer cmdDraw = new CommandBuffer(); cmdDraw.DrawMeshInstancedIndirect(m_PipelineAsset.mesh, 0, m_PipelineAsset.mat, 0, argsBuffer, 0, m_MaterialPropertyBlock); context.ExecuteCommandBuffer(cmdDraw); cmdDraw.Release(); context.Submit(); //CleanUp after rendering this cam if (positionBuffer != null) { positionBuffer.Release(); positionBuffer = null; } if (argsBuffer != null) { argsBuffer.Release(); argsBuffer = null; } } }
public Task <List <TEntity> > GetAsync(PagingInfo pagingInfo, Expression <Func <TEntity, bool> > filter = null, SortingSettings <TEntity> orderBy = null) { return(_dal.GetAsync(pagingInfo, filter, orderBy)); }
void RenderDepthPeeling(ScriptableRenderContext context, ref RenderingData renderingData) { var camera = renderingData.camera; FilteringSettings filteringSettings = new FilteringSettings(RenderQueueRange.transparent); SortingSettings sortingSettings = new SortingSettings(camera); sortingSettings.criteria = SortingCriteria.CommonTransparent; DrawingSettings drawingSettings = new DrawingSettings(new ShaderTagId("DepthPeelingFirstPass"), sortingSettings) { enableDynamicBatching = true, perObjectData = PerObjectData.ReflectionProbes, }; RenderStateBlock stateBlock = new RenderStateBlock(RenderStateMask.Nothing); var cmd = CommandBufferPool.Get("Depth Peeling"); using (new ProfilingSample(cmd, "Depth Peeling")) { // Start profilling context.ExecuteCommandBuffer(cmd); cmd.Clear(); List <int> colorRTs = new List <int>(asset.DepthPeelingPass); List <int> depthRTs = new List <int>(asset.DepthPeelingPass); // Perform depth peeling for (var i = 0; i < asset.DepthPeelingPass; i++) { depthRTs.Add(Shader.PropertyToID($"_DepthPeelingDepth{i}")); colorRTs.Add(Shader.PropertyToID($"_DepthPeelingColor{i}")); cmd.GetTemporaryRT(colorRTs[i], camera.pixelWidth, camera.pixelHeight, 0); cmd.GetTemporaryRT(depthRTs[i], camera.pixelWidth, camera.pixelHeight, 32, FilterMode.Point, RenderTextureFormat.RFloat); if (i == 0) { drawingSettings.SetShaderPassName(0, new ShaderTagId("DepthPeelingFirstPass")); cmd.SetRenderTarget(new RenderTargetIdentifier[] { colorRTs[i], depthRTs[i] }, depthRTs[i]); cmd.ClearRenderTarget(true, true, Color.black); context.ExecuteCommandBuffer(cmd); cmd.Clear(); context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref filteringSettings, ref stateBlock); } else { cmd.SetGlobalTexture("_MaxDepthTex", depthRTs[i - 1]); drawingSettings.SetShaderPassName(0, new ShaderTagId("DepthPeelingPass")); cmd.SetRenderTarget(new RenderTargetIdentifier[] { colorRTs[i], depthRTs[i] }, depthRTs[i]); cmd.ClearRenderTarget(true, true, Color.black); context.ExecuteCommandBuffer(cmd); cmd.Clear(); context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref filteringSettings, ref stateBlock); } } cmd.SetRenderTarget(BuiltinRenderTextureType.CameraTarget, BuiltinRenderTextureType.CameraTarget); var mat = new Material(Shader.Find("SarRP/Transparent")); for (var i = asset.DepthPeelingPass - 1; i >= 0; i--) { cmd.SetGlobalTexture("_DepthTex", depthRTs[i]); cmd.Blit(colorRTs[i], BuiltinRenderTextureType.CameraTarget, mat, 4); cmd.ReleaseTemporaryRT(depthRTs[i]); cmd.ReleaseTemporaryRT(colorRTs[i]); } cmd.SetRenderTarget(BuiltinRenderTextureType.CameraTarget, BuiltinRenderTextureType.CameraTarget); context.ExecuteCommandBuffer(cmd); cmd.Clear(); } context.ExecuteCommandBuffer(cmd); cmd.Clear(); }
private void DrawCharacter(ScriptableRenderContext context, Camera camera, ShaderTagId pass, SortingSettings sortFlags) { var settings = new DrawingSettings(pass, sortFlags); settings.enableInstancing = true; settings.enableDynamicBatching = true; var filterSettings = new FilteringSettings(RenderQueueRange.transparent, 1 << LayerDefine.CHARA, 1 << LayerDefine.CHARA); context.DrawRenderers(cull, ref settings, ref filterSettings); }
public SearchRequestModel() { SortingSettings = new SortingSettings(); PagingSettings = new PagingSettings(); FilterSettings = new FiltersSet(); }
private static void RenderToCubemap(ScriptableRenderContext context, CommandBuffer cmd, HDCamera hd, SensorRenderTarget target, ShaderTagId pass, Color clearColor) { var hdrp = (HDRenderPipeline)RenderPipelineManager.currentPipeline; hdrp.UpdateShaderVariablesForCamera(cmd, hd); context.SetupCameraProperties(hd.camera); var transform = hd.camera.transform; var rot = transform.rotation; var localRot = transform.localRotation; var originalProj = hd.camera.projectionMatrix; hd.camera.projectionMatrix = CubeProj; var sensor = hd.camera.GetComponent <CameraSensorBase>(); var renderPostprocess = sensor != null && sensor.Postprocessing != null && sensor.Postprocessing.Count > 0; cmd.SetInvertCulling(true); // Cubemap uses RHS standard, face culling has to be inverted for (var i = 0; i < 6; ++i) { // Custom face order is used for dynamic exposure - this way it will be based on forward cube face var faceIndex = CubemapFaceOrder[i]; if ((target.CubeFaceMask & (1 << faceIndex)) == 0) { continue; } transform.localRotation = localRot * Quaternion.LookRotation(CoreUtils.lookAtList[faceIndex], CoreUtils.upVectorList[faceIndex]); var view = hd.camera.worldToCameraMatrix; hdrp.SetupGlobalParamsForCubemap(cmd, view, target.ColorHandle.rt.width); CoreUtils.SetRenderTarget(cmd, target.ColorHandle, target.DepthHandle, ClearFlag.None, 0, (CubemapFace)faceIndex); cmd.ClearRenderTarget(true, true, clearColor); context.ExecuteCommandBuffer(cmd); cmd.Clear(); if (hd.camera.TryGetCullingParameters(out var culling)) { var cull = context.Cull(ref culling); var sorting = new SortingSettings(hd.camera); var drawing = new DrawingSettings(pass, sorting); var filter = new FilteringSettings(RenderQueueRange.all); context.DrawRenderers(cull, ref drawing, ref filter); if (renderPostprocess) { var ctx = new PostProcessPassContext(cmd, hd, target); SimulatorManager.Instance.Sensors.PostProcessSystem.RenderForSensor(ctx, sensor, (CubemapFace)i); } } } cmd.SetInvertCulling(false); context.ExecuteCommandBuffer(cmd); cmd.Clear(); transform.rotation = rot; hd.camera.projectionMatrix = originalProj; }
public static void Render(ScriptableRenderContext context, IEnumerable <Camera> cameras, SimpleRenderPipeline.Mode mode) { foreach (var camera in cameras) { // Culling ScriptableCullingParameters cullingParams; if (!camera.TryGetCullingParameters(out cullingParams)) { continue; } CullingResults cull = context.Cull(ref cullingParams); context.SetupCameraProperties(camera); AttachmentDescriptor color = new AttachmentDescriptor(RenderTextureFormat.ARGB32); AttachmentDescriptor depth = new AttachmentDescriptor(RenderTextureFormat.Depth); bool needsFinalBlit = camera.cameraType == CameraType.SceneView; RenderTargetIdentifier tmpBuf = new RenderTargetIdentifier("TempSurface"); if (needsFinalBlit) { using (var cmd = new CommandBuffer()) { cmd.GetTemporaryRT(Shader.PropertyToID("TempSurface"), camera.pixelWidth, camera.pixelHeight, 24, FilterMode.Bilinear, RenderTextureFormat.ARGB32); context.ExecuteCommandBuffer(cmd); } color.ConfigureTarget(tmpBuf, false, true); } else { color.ConfigureTarget(BuiltinRenderTextureType.CameraTarget, false, true); } // No configure target for depth means depth will be memoryless color.ConfigureClear(Color.blue / 3 + Color.red / 2); depth.ConfigureClear(Color.black, 1.0f, 0); using (var attachmentsDisposable = new NativeArray <AttachmentDescriptor>(2, Allocator.Temp)) { var attachments = attachmentsDisposable; const int depthIndex = 0, colorIndex = 1; attachments[depthIndex] = depth; attachments[colorIndex] = color; using (context.BeginScopedRenderPass(camera.pixelWidth, camera.pixelHeight, 1, attachments, depthIndex)) { var fs = new FilteringSettings(RenderQueueRange.opaque); if (mode == SimpleRenderPipeline.Mode.DepthPrepass) { var depthPrePasssettings = new DrawingSettings(new ShaderTagId("DepthPrepass"), new SortingSettings(camera)); using (var depthOnlyDisposable = new NativeArray <int>(0, Allocator.Temp)) { var depthArray = depthOnlyDisposable; using (context.BeginScopedSubPass(depthArray)) { context.DrawRenderers(cull, ref depthPrePasssettings, ref fs); } } var mainPasssettings = new DrawingSettings(new ShaderTagId("AfterZPrepass"), new SortingSettings(camera)); using (var colorsDisposable = new NativeArray <int>(1, Allocator.Temp)) { var colors = colorsDisposable; colors[0] = colorIndex; using (context.BeginScopedSubPass(colors)) { context.DrawRenderers(cull, ref mainPasssettings, ref fs); } } } else if (mode == SimpleRenderPipeline.Mode.OnePassAlphaTest) { var mainPasssettings = new DrawingSettings(new ShaderTagId("OnePassAlphaClip"), new SortingSettings(camera)); using (var colorsDisposable = new NativeArray <int>(1, Allocator.Temp)) { var colors = colorsDisposable; colors[0] = colorIndex; using (context.BeginScopedSubPass(colors)) { context.DrawRenderers(cull, ref mainPasssettings, ref fs); } } } else if (mode == SimpleRenderPipeline.Mode.OnePassAlphaBlend) { var sortingSettings = new SortingSettings(camera); sortingSettings.criteria = SortingCriteria.BackToFront; var mainPasssettings = new DrawingSettings(new ShaderTagId("OnePassAlphaBlend"), sortingSettings); using (var colorsDisposable = new NativeArray <int>(1, Allocator.Temp)) { var colors = colorsDisposable; colors[0] = colorIndex; using (context.BeginScopedSubPass(colors)) { context.DrawRenderers(cull, ref mainPasssettings, ref fs); } } } } } if (needsFinalBlit) { using (var cmd = new CommandBuffer()) { cmd.Blit(tmpBuf, new RenderTargetIdentifier(BuiltinRenderTextureType.CameraTarget)); context.ExecuteCommandBuffer(cmd); } } context.Submit(); } }
private void Render(ScriptableRenderContext context, Camera camera) { ScriptableCullingParameters cullingParameters; if (!camera.TryGetCullingParameters(false, out cullingParameters)) { return; } #if UNITY_EDITOR if (camera.cameraType == CameraType.SceneView) { ScriptableRenderContext.EmitWorldGeometryForSceneView(camera); } #endif cameraBuffer.Clear(); CullingResults cullResults = context.Cull(ref cullingParameters); context.SetupCameraProperties(camera, false); //建立RenderTexture,並指定其為RenderTarget RenderTextureDescriptor descriptor = CreateRenderTextureDescriptor(camera); if (_cameraColorAttachment.id == -1) { _cameraColorAttachment.Init("_CameraColorTexture"); } cameraBuffer.GetTemporaryRT(_cameraColorAttachment.id, descriptor, FilterMode.Bilinear); RenderTargetIdentifier colorIdentifiy = _cameraColorAttachment.Identifier(); cameraBuffer.SetRenderTarget(colorIdentifiy, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store); cameraBuffer.ClearRenderTarget(true, true, Color.clear); context.ExecuteCommandBuffer(cameraBuffer); cameraBuffer.Clear(); SortingSettings sortingSettings = new SortingSettings(camera) { criteria = SortingCriteria.CommonOpaque }; var drawSettings = new DrawingSettings( new ShaderTagId("SRPDefaultUnlit"), sortingSettings ); var filterSettings = new FilteringSettings(RenderQueueRange.opaque); context.DrawRenderers( cullResults, ref drawSettings, ref filterSettings ); _debugRTProcessor.Add(ref context, ref colorIdentifiy); context.DrawSkybox(camera); _debugRTProcessor.Add(ref context, ref colorIdentifiy); sortingSettings.criteria = SortingCriteria.CommonTransparent; filterSettings.renderQueueRange = RenderQueueRange.transparent; context.DrawRenderers( cullResults, ref drawSettings, ref filterSettings ); _debugRTProcessor.Add(ref context, ref colorIdentifiy); //畫在後置特效之前的Gizmos #if UNITY_EDITOR if (UnityEditor.Handles.ShouldRenderGizmos()) { context.DrawGizmos(camera, GizmoSubset.PreImageEffects); } #endif //後置特效處理,在這裡做… //final blit to frame buffer(將目前的RenderTextures的結果 //,用一個Quad畫回FrameBuffer if (camera.cameraType == CameraType.Game) { cameraBuffer.SetGlobalTexture("_BlitTex", colorIdentifiy); cameraBuffer.SetRenderTarget(BuiltinRenderTextureType.CameraTarget, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store); cameraBuffer.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity); cameraBuffer.SetViewport(camera.pixelRect); cameraBuffer.DrawMesh(fullscreenMesh, Matrix4x4.identity, blitMaterial); } else { //因為工具的Camera是指向一個RenderTexture,要直接blitting過去, //否則會導致,Gizmos畫不出來。 cameraBuffer.Blit(colorIdentifiy, BuiltinRenderTextureType.CameraTarget); } context.ExecuteCommandBuffer(cameraBuffer); cameraBuffer.Clear(); //釋放RenderTexture cameraBuffer.ReleaseTemporaryRT(_cameraColorAttachment.id); context.ExecuteCommandBuffer(cameraBuffer); cameraBuffer.Clear(); //畫在後置特效之後的Gizmos #if UNITY_EDITOR if (UnityEditor.Handles.ShouldRenderGizmos()) { context.DrawGizmos(camera, GizmoSubset.PostImageEffects); } #endif _debugRTProcessor.Render(ref context, camera, blitMaterial); context.Submit(); }
private static void RenderToCubemap(ScriptableRenderContext context, CommandBuffer cmd, HDCamera hd, SensorRenderTarget target, ShaderTagId pass, Color clearColor) { hd.SetupGlobalParams(cmd, 0); context.SetupCameraProperties(hd.camera); var transform = hd.camera.transform; var r = transform.rotation; var originalProj = hd.camera.projectionMatrix; hd.camera.projectionMatrix = CubeProj; var sensor = hd.camera.GetComponent <CameraSensorBase>(); var renderPostprocess = sensor != null && sensor.Postprocessing != null && sensor.Postprocessing.Count > 0; for (var i = 0; i < 6; ++i) { // Custom face order is used for dynamic exposure - this way it will be based on forward cube face var faceIndex = CubemapFaceOrder[i]; if ((target.CubeFaceMask & (1 << faceIndex)) == 0) { continue; } transform.localRotation = Quaternion.LookRotation(CoreUtils.lookAtList[faceIndex], CoreUtils.upVectorList[faceIndex]); var view = hd.camera.worldToCameraMatrix; SetupGlobalParamsForCubemap(cmd, view, target.ColorHandle.rt.width); CoreUtils.SetRenderTarget(cmd, target.ColorHandle, target.DepthHandle, ClearFlag.None, 0, (CubemapFace)faceIndex); cmd.ClearRenderTarget(true, true, clearColor); context.ExecuteCommandBuffer(cmd); cmd.Clear(); if (hd.camera.TryGetCullingParameters(out var culling)) { var cull = context.Cull(ref culling); var sorting = new SortingSettings(hd.camera); var drawing = new DrawingSettings(pass, sorting); var filter = new FilteringSettings(RenderQueueRange.all); // NOTE: This should flip culling, not hard-set it to front. SRP API does not provide this option // currently. Expected issues with front-culled geometry. // TODO: investigate HDAdditionalCameraData.FlipYMode.ForceFlipY, it might be a way to solve this var stateBlock = new RenderStateBlock(RenderStateMask.Raster) { rasterState = new RasterState { cullingMode = CullMode.Front } }; context.DrawRenderers(cull, ref drawing, ref filter, ref stateBlock); if (renderPostprocess) { SimulatorManager.Instance.Sensors.PostProcessSystem.RenderForSensor(cmd, hd, sensor, target.ColorHandle, (CubemapFace)i); } } } if (renderPostprocess) { context.ExecuteCommandBuffer(cmd); cmd.Clear(); } transform.rotation = r; hd.camera.projectionMatrix = originalProj; }
protected override void Render(ScriptableRenderContext context, Camera[] cameras) { BeginFrameRendering(context, cameras); foreach (Camera camera in cameras) { BeginCameraRendering(context, camera); //Culling ScriptableCullingParameters cullingParams; if (!camera.TryGetCullingParameters(out cullingParams)) { continue; } CullingResults cull = context.Cull(ref cullingParams); //Camera setup some builtin variables e.g. camera projection matrices etc context.SetupCameraProperties(camera); //Get the setting from camera component bool drawSkyBox = camera.clearFlags == CameraClearFlags.Skybox? true : false; bool clearDepth = camera.clearFlags == CameraClearFlags.Nothing? false : true; bool clearColor = camera.clearFlags == CameraClearFlags.Color? true : false; //************************** Set TempRT ************************************ CommandBuffer cmdTempId = new CommandBuffer(); cmdTempId.name = "(" + camera.name + ")" + "Setup TempRT"; //Color m_ColorFormatActive = camera.allowHDR ? m_ColorFormatHDR : m_ColorFormat; RenderTextureDescriptor colorRTDesc = new RenderTextureDescriptor(camera.pixelWidth, camera.pixelHeight); colorRTDesc.graphicsFormat = m_ColorFormatActive; colorRTDesc.depthBufferBits = depthBufferBits; colorRTDesc.sRGB = (QualitySettings.activeColorSpace == ColorSpace.Linear); colorRTDesc.msaaSamples = camera.allowMSAA ? QualitySettings.antiAliasing : 1; colorRTDesc.enableRandomWrite = false; cmdTempId.GetTemporaryRT(m_ColorRTid, colorRTDesc, FilterMode.Bilinear); //Depth RenderTextureDescriptor depthRTDesc = new RenderTextureDescriptor(camera.pixelWidth, camera.pixelHeight); depthRTDesc.colorFormat = RenderTextureFormat.Depth; depthRTDesc.depthBufferBits = depthBufferBits; cmdTempId.GetTemporaryRT(m_DepthRTid, depthRTDesc, FilterMode.Bilinear); context.ExecuteCommandBuffer(cmdTempId); cmdTempId.Release(); //************************** Setup DrawSettings and FilterSettings ************************************ var sortingSettings = new SortingSettings(camera); DrawingSettings drawSettings = new DrawingSettings(m_PassName, sortingSettings); FilteringSettings filterSettings = new FilteringSettings(RenderQueueRange.all); DrawingSettings drawSettingsDepth = new DrawingSettings(m_PassName, sortingSettings) { perObjectData = PerObjectData.None, overrideMaterial = depthOnlyMaterial, overrideMaterialPassIndex = 0 }; //************************** Rendering depth ************************************ //Set RenderTarget & Camera clear flag CommandBuffer cmdDepth = new CommandBuffer(); cmdDepth.name = "(" + camera.name + ")" + "Depth Clear Flag"; cmdDepth.SetRenderTarget(m_DepthRT); //Set CameraTarget to the depth texture cmdDepth.ClearRenderTarget(true, true, Color.black); //MyDebug(camera,context,m_DepthRT,colorRTDesc,null); context.ExecuteCommandBuffer(cmdDepth); //MyDebug(camera,context,m_DepthRT,colorRTDesc,null); cmdDepth.Release(); //Opaque objects sortingSettings.criteria = SortingCriteria.CommonOpaque; drawSettingsDepth.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.opaque; context.DrawRenderers(cull, ref drawSettingsDepth, ref filterSettings); //To let shader has _CameraDepthTexture, to make Depth of Field work CommandBuffer cmdDepthTexture = new CommandBuffer(); cmdDepthTexture.name = "(" + camera.name + ")" + "Depth Texture"; cmdDepthTexture.SetGlobalTexture(m_DepthRTid, m_DepthRT); context.ExecuteCommandBuffer(cmdDepthTexture); //MyDebug(camera,context,m_DepthRT,colorRTDesc,null); cmdDepthTexture.Release(); //************************** Rendering colors ************************************ //Set RenderTarget & Camera clear flag CommandBuffer cmd = new CommandBuffer(); cmd.name = "(" + camera.name + ")" + "Clear Flag"; cmd.SetRenderTarget(m_ColorRT); //Set CameraTarget to the color texture cmd.ClearRenderTarget(clearDepth, clearColor, camera.backgroundColor); context.ExecuteCommandBuffer(cmd); //MyDebug(camera,context,m_ColorRT,colorRTDesc,null); cmd.Release(); //Skybox if (drawSkyBox) { context.DrawSkybox(camera); } AfterSkybox(camera, context); //************************** Rendering Opaque Objects ************************************ sortingSettings.criteria = SortingCriteria.CommonOpaque; drawSettings.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.opaque; context.DrawRenderers(cull, ref drawSettings, ref filterSettings); AfterOpaqueObject(camera, context); //************************** SetUp Post-processing ************************************ PostProcessLayer m_CameraPostProcessLayer = camera.GetComponent <PostProcessLayer>(); bool hasPostProcessing = m_CameraPostProcessLayer != null; bool usePostProcessing = false; bool hasOpaqueOnlyEffects = false; PostProcessRenderContext m_PostProcessRenderContext = null; if (hasPostProcessing) { m_PostProcessRenderContext = new PostProcessRenderContext(); usePostProcessing = m_CameraPostProcessLayer.enabled; hasOpaqueOnlyEffects = m_CameraPostProcessLayer.HasOpaqueOnlyEffects(m_PostProcessRenderContext); } //************************** Opaque Post-processing ************************************ //Ambient Occlusion, Screen-spaced reflection are generally not supported for SRP //So this part is only for custom opaque post-processing if (usePostProcessing) { CommandBuffer cmdpp = new CommandBuffer(); cmdpp.name = "(" + camera.name + ")" + "Post-processing Opaque"; m_PostProcessRenderContext.Reset(); m_PostProcessRenderContext.camera = camera; m_PostProcessRenderContext.source = m_ColorRT; m_PostProcessRenderContext.sourceFormat = UnityEngine.Experimental.Rendering.GraphicsFormatUtility.GetRenderTextureFormat(m_ColorFormatActive); m_PostProcessRenderContext.destination = m_ColorRT; m_PostProcessRenderContext.command = cmdpp; m_PostProcessRenderContext.flip = camera.targetTexture == null;//是否反转画面 m_CameraPostProcessLayer.RenderOpaqueOnly(m_PostProcessRenderContext); context.ExecuteCommandBuffer(cmdpp); cmdpp.Release(); } //************************** Rendering Transparent Objects ************************************ sortingSettings.criteria = SortingCriteria.CommonTransparent; drawSettings.sortingSettings = sortingSettings; filterSettings.renderQueueRange = RenderQueueRange.transparent; context.DrawRenderers(cull, ref drawSettings, ref filterSettings); AfterTransparentObject(camera, context, m_DepthRTid, depthRTDesc); //************************** Transparent Post-processing ************************************ //Bloom, Vignette, Grain, ColorGrading, LensDistortion, Chromatic Aberration, Auto Exposure if (usePostProcessing) { CommandBuffer cmdpp = new CommandBuffer(); cmdpp.name = "(" + camera.name + ")" + "Post-processing Transparent"; m_PostProcessRenderContext.Reset(); m_PostProcessRenderContext.camera = camera; m_PostProcessRenderContext.source = m_ColorRT; m_PostProcessRenderContext.sourceFormat = UnityEngine.Experimental.Rendering.GraphicsFormatUtility.GetRenderTextureFormat(m_ColorFormatActive); m_PostProcessRenderContext.destination = BuiltinRenderTextureType.CameraTarget; m_PostProcessRenderContext.command = cmdpp; m_PostProcessRenderContext.flip = camera.targetTexture == null; m_CameraPostProcessLayer.Render(m_PostProcessRenderContext); context.ExecuteCommandBuffer(cmdpp); cmdpp.Release(); } //************************** Make sure screen has the thing when Postprocessing is off ************************************ if (!usePostProcessing) { CommandBuffer cmdBlitToCam = new CommandBuffer(); cmdBlitToCam.name = "(" + camera.name + ")" + "Blit back to Camera"; cmdBlitToCam.Blit(m_ColorRTid, BuiltinRenderTextureType.CameraTarget); //MDebug.MyDebug(); context.ExecuteCommandBuffer(cmdBlitToCam); cmdBlitToCam.Release(); } //************************** Clean Up ************************************ CommandBuffer cmdclean = new CommandBuffer(); cmdclean.name = "(" + camera.name + ")" + "Clean Up"; cmdclean.ReleaseTemporaryRT(m_ColorRTid); cmdclean.ReleaseTemporaryRT(m_DepthRTid); context.ExecuteCommandBuffer(cmdclean); cmdclean.Release(); context.Submit(); EndCameraRendering(context, camera); } EndFrameRendering(context, cameras); }
void Render(ScriptableRenderContext context, Camera camera) { //FRUSTRUM CULL ScriptableCullingParameters cullingParams; if (!camera.TryGetCullingParameters(out cullingParams)) { return; } cullingParams.shadowDistance = Mathf.Min(shadowDistance, camera.farClipPlane); //this is used when calculating directional light shadows (specifically the "size" of the directional light's camera) //ADD UI TO SCENE VIEW #if UNITY_EDITOR if (camera.cameraType == CameraType.SceneView) { ScriptableRenderContext.EmitWorldGeometryForSceneView(camera); } #endif //EXECUTE THE CULL cull = context.Cull(ref cullingParams); //LIGHTING ARRAY GENERATION if (cull.visibleLights.Length > 0) { ConfigureLights(); //only run the shadow program if shadows are to be found if (shadowTileCount > 0) { RenderShadows(context); } else { cameraBuffer.DisableShaderKeyword(shadowsHardKeyword); cameraBuffer.DisableShaderKeyword(shadowsSoftKeyword); } CoreUtils.SetKeyword(cameraBuffer, secondaryVertexLightsKeyword, this.secondaryLightsAreVertexLights); } else //because I don't configure lights if there are no visible lights, this part clears the lights` { cameraBuffer.SetGlobalVector(lightIndicesOffsetAndCountID, Vector4.zero); cameraBuffer.DisableShaderKeyword(shadowsHardKeyword); cameraBuffer.DisableShaderKeyword(shadowsSoftKeyword); cameraBuffer.EnableShaderKeyword(secondaryVertexLightsKeyword); } context.SetupCameraProperties(camera); //CLEARFLAGS cameraBuffer.ClearRenderTarget( (camera.clearFlags & CameraClearFlags.Depth) != 0, (camera.clearFlags & CameraClearFlags.Color) != 0, camera.backgroundColor ); cameraBuffer.BeginSample("Render Camera"); cameraBuffer.SetGlobalVectorArray( visibleLightColorsId, visibleLightColors ); cameraBuffer.SetGlobalVectorArray( visibleLightDirectionsOrPositionsId, visibleLightDirectionsOrPositions ); cameraBuffer.SetGlobalVectorArray( visibleLightAttenuationsId, visibleLightAttenuations ); cameraBuffer.SetGlobalVectorArray( visibleLightSpotDirectionsId, visibleLightSpotDirections ); context.ExecuteCommandBuffer(cameraBuffer); cameraBuffer.Clear(); //OPAQUES var drawSettings = new DrawingSettings(new ShaderTagId("SRPDefaultUnlit"), new SortingSettings(camera)) { enableDynamicBatching = enableDynamicBatching, enableInstancing = gpuInstancing }; if (cull.visibleLights.Length > 0) { drawSettings.perObjectData = PerObjectData.LightData | PerObjectData.LightIndices; } var filterSettings = new FilteringSettings(RenderQueueRange.opaque); context.DrawRenderers(cull, ref drawSettings, ref filterSettings); //SKYBOX context.DrawSkybox(camera); //TRANSPARENTS SortingSettings transparentSettings = drawSettings.sortingSettings; transparentSettings.criteria = SortingCriteria.CommonTransparent; drawSettings.sortingSettings = transparentSettings; filterSettings.renderQueueRange = RenderQueueRange.transparent; context.DrawRenderers(cull, ref drawSettings, ref filterSettings); //DEFAULT PIPELINE #if UNITY_EDITOR DrawDefaultPipeline(context, camera); #endif cameraBuffer.EndSample("Render Camera"); context.ExecuteCommandBuffer(cameraBuffer); cameraBuffer.Clear(); context.Submit(); //Cleans shadowmap if (shadowMap) { RenderTexture.ReleaseTemporary(shadowMap); shadowMap = null; } }