public void RenderAfterOpaque(SPostProcessingParam param) { m_param = param; initializeStatic(); if (m_depthStripes) { depthStripes(); } }
/// <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); } } }