protected override void Render(ScriptableRenderContext context, Camera[] cameras) { RenderPipeline.BeginFrameRendering(context, cameras); foreach (var camera in cameras) { RenderCamera(ref context, camera); } RenderPipeline.EndFrameRendering(context, cameras); }
public override void Render(ScriptableRenderContext context, Camera[] cameras) { base.Render(context, cameras); RenderPipeline.BeginFrameRendering(cameras); GraphicsSettings.lightsUseLinearIntensity = true; SetupPerFrameShaderConstants(); // Sort cameras array by camera depth Array.Sort(cameras, m_CameraComparer); foreach (Camera camera in cameras) { RenderPipeline.BeginCameraRendering(camera); var cameraContext = CameraContext.Create(camera); Render(ref context, cameraContext); { var cmd = CommandBufferPool.Get(""); cmd.name = "After Camera Render"; #if UNITY_EDITOR if (cameraContext.SceneViewCamera) { m_TextureUtil.CopyTexture(cmd, CameraRenderTargetID.depth, BuiltinRenderTextureType.CameraTarget, true); } #endif cmd.ReleaseTemporaryRT(m_ShadowManager.ScreenSpaceShadowMapRTID); cmd.ReleaseTemporaryRT(CameraRenderTargetID.depthCopy); cmd.ReleaseTemporaryRT(CameraRenderTargetID.depth); cmd.ReleaseTemporaryRT(CameraRenderTargetID.color); cmd.ReleaseTemporaryRT(CameraRenderTargetID.copyColor); context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); } context.Submit(); m_ShadowManager.ReleaseRenderTarget(); } }
private static readonly ShaderPassName m_UnlitPassName = new ShaderPassName("SRPDefaultUnlit"); //For default shaders public static void Render(ScriptableRenderContext context, Camera[] cameras, SRP02CustomParameter SRP02CP) { RenderPipeline.BeginFrameRendering(cameras); foreach (Camera camera in cameras) { RenderPipeline.BeginCameraRendering(camera); //Culling ScriptableCullingParameters cullingParams; if (!CullResults.GetCullingParameters(camera, out cullingParams)) { continue; } CullResults cull = new CullResults(); CullResults.Cull(ref cullingParams, context, ref cull); context.SetupCameraProperties(camera); if (camera.renderingPath == RenderingPath.UsePlayerSettings) { // clear depth buffer CommandBuffer cmd = new CommandBuffer(); cmd.ClearRenderTarget(true, !SRP02CP.DrawSkybox, SRP02CP.ClearColor); context.ExecuteCommandBuffer(cmd); cmd.Release(); // Setup global lighting shader variables //SetupLightShaderVariables(cull.visibleLights, context); // Setup DrawSettings and FilterSettings ShaderPassName passName = new ShaderPassName("BasicPass"); DrawRendererSettings drawSettings = new DrawRendererSettings(camera, passName); FilterRenderersSettings filterSettings = new FilterRenderersSettings(true); //Draw passes that has no light mode (default) ShaderPassName passNameDefault = new ShaderPassName(""); DrawRendererSettings drawSettingsDefault = new DrawRendererSettings(camera, passNameDefault); drawSettingsDefault.SetShaderPassName(1, m_UnlitPassName); if (SRP02CP.DrawSkybox) { context.DrawSkybox(camera); } if (SRP02CP.DrawOpaque) { drawSettings.sorting.flags = SortFlags.CommonOpaque; filterSettings.renderQueueRange = RenderQueueRange.opaque; context.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings); } // Default drawSettingsDefault.sorting.flags = SortFlags.CommonOpaque; context.DrawRenderers(cull.visibleRenderers, ref drawSettingsDefault, filterSettings); if (SRP02CP.DrawTransparent) { drawSettings.sorting.flags = SortFlags.CommonTransparent; filterSettings.renderQueueRange = RenderQueueRange.transparent; context.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings); } // Default drawSettingsDefault.sorting.flags = SortFlags.CommonTransparent; context.DrawRenderers(cull.visibleRenderers, ref drawSettingsDefault, filterSettings); } context.Submit(); } }
private static readonly ShaderPassName m_UnlitPassName = new ShaderPassName("SRPDefaultUnlit"); //For default shaders public static void Render(ScriptableRenderContext context, Camera[] cameras) { RenderPipeline.BeginFrameRendering(cameras); string tx = ""; foreach (Camera camera in cameras) { RenderPipeline.BeginCameraRendering(camera); // Culling ScriptableCullingParameters cullingParams; if (!CullResults.GetCullingParameters(camera, out cullingParams)) { continue; } CullResults cull = new CullResults(); CullResults.Cull(ref cullingParams, context, ref cull); if (camera == Camera.main) //Only generate result from main cam { tx = ""; tx += "<color=#0FF>cullingPlaneCount : </color>" + cullingParams.cullingPlaneCount + "\n"; for (int i = 0; i < cullingParams.cullingPlaneCount; i++) { if (cullingParams.cameraProperties.GetCameraCullingPlane(i).ToString() == cullingParams.cameraProperties.GetShadowCullingPlane(i).ToString()) { tx += "<color=#0F0>cameraProperties.GetCameraCullingPlane = GetShadowCullingPlane (" + i + ") : </color>" + cullingParams.cameraProperties.GetCameraCullingPlane(i) + "\n"; } else { tx += "<color=#0FF>cameraProperties.GetCameraCullingPlane(" + i + ") : </color>" + cullingParams.cameraProperties.GetCameraCullingPlane(i) + "\n"; tx += "<color=#0FF>cameraProperties.GetShadowCullingPlane(" + i + ") : </color>" + cullingParams.cameraProperties.GetShadowCullingPlane(i) + "\n"; } } // tx += "<color=#0FF>cullingFlags : </color>" + cullingParams.cullingFlags.ToString() + "\n"; tx += "<color=#0FF>cullingMask : </color>" + cullingParams.cullingMask.ToString() + "\n"; tx += "<color=#0FF>cullingMatrix : </color>" + cullingParams.cullingMatrix + "\n"; // if (cullingParams.isOrthographic == cullingParams.lodParameters.isOrthographic) { tx += "<color=#0F0>isOrthographic = lodParameters.isOrthographic : </color>" + cullingParams.isOrthographic + "\n"; } else { tx += "<color=#0FF>isOrthographic : </color>" + cullingParams.isOrthographic + "\n"; } if (cullingParams.position == cullingParams.lodParameters.cameraPosition) { tx += "<color=#0F0>position = lodParameters.cameraPosition : </color>" + cullingParams.position + "\n"; } else { tx += "<color=#0FF>position : </color>" + cullingParams.position + "\n"; } // tx += "<color=#0FF>reflectionProbeSortOptions : </color>" + cullingParams.reflectionProbeSortOptions.ToString() + "\n"; tx += "<color=#0FF>sceneMask : </color>" + cullingParams.sceneMask + "\n"; tx += "<color=#0FF>shadowDistance : </color>" + cullingParams.shadowDistance + "\n"; // tx += "<color=#0FF>layerCull : </color>" + cullingParams.layerCull + "\n"; for (int i = 0; i < cullingParams.layerCull; i++) { tx += "<color=#0FF>GetLayerCullDistance(" + i + ") : </color>" + cullingParams.GetLayerCullDistance(i) + "\n"; } // tx += "<color=#0FF>lodParameters : </color>" + "\n"; tx += "cameraPixelHeight = " + cullingParams.lodParameters.cameraPixelHeight + "\n"; if (camera.fieldOfView == cullingParams.lodParameters.fieldOfView) { tx += "fieldOfView = camera.fieldOfView : " + "<color=#0F0>" + cullingParams.lodParameters.fieldOfView + "</color>" + "\n"; } else { tx += "fieldOfView != camera.fieldOfView : " + "<color=#FF0>" + cullingParams.lodParameters.fieldOfView + "</color>" + "\n"; } if (camera.orthographicSize == cullingParams.lodParameters.orthoSize) { tx += "orthoSize = camera.orthographicSize : " + "<color=#0F0>" + cullingParams.lodParameters.orthoSize + "</color>" + "\n"; } else { tx += "orthoSize != camera.orthographicSize : " + "<color=#FF0>" + cullingParams.lodParameters.orthoSize + "</color>" + "\n"; } if (cullingParams.isOrthographic != cullingParams.lodParameters.isOrthographic) { tx += "isOrthographic = " + cullingParams.lodParameters.isOrthographic + "\n"; } if (cullingParams.position != cullingParams.lodParameters.cameraPosition) { tx += "cameraPosition = " + cullingParams.lodParameters.cameraPosition + "\n"; } //Debug.Log(tx); if (textMesh != null) { textMesh.text = tx; //Debug.Log("<color=#0F0>TextMesh is updated</color>"); } else { tx = "<color=#F00>TextMesh is null</color> Please hit play if you hasn't"; //Debug.Log(tx); } } context.SetupCameraProperties(camera); // clear depth buffer CommandBuffer cmd = new CommandBuffer(); cmd.ClearRenderTarget(true, true, camera.backgroundColor); context.ExecuteCommandBuffer(cmd); cmd.Release(); // context.DrawSkybox(camera); // Setup DrawSettings and FilterSettings ShaderPassName passName = new ShaderPassName("BasicPass"); DrawRendererSettings drawSettings = new DrawRendererSettings(camera, passName); FilterRenderersSettings filterSettings = new FilterRenderersSettings(true); //Draw passes that has no light mode (default) ShaderPassName passNameDefault = new ShaderPassName(""); DrawRendererSettings drawSettingsDefault = new DrawRendererSettings(camera, passNameDefault); drawSettingsDefault.SetShaderPassName(1, m_UnlitPassName); // Draw opaque objects using BasicPass shader pass drawSettings.sorting.flags = SortFlags.CommonOpaque; filterSettings.renderQueueRange = RenderQueueRange.opaque; context.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings); // Default drawSettingsDefault.sorting.flags = SortFlags.CommonOpaque; context.DrawRenderers(cull.visibleRenderers, ref drawSettingsDefault, filterSettings); // Draw transparent objects using BasicPass shader pass drawSettings.sorting.flags = SortFlags.CommonTransparent; filterSettings.renderQueueRange = RenderQueueRange.transparent; context.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings); // Default drawSettingsDefault.sorting.flags = SortFlags.CommonTransparent; context.DrawRenderers(cull.visibleRenderers, ref drawSettingsDefault, filterSettings); context.Submit(); } }
private static readonly ShaderPassName m_UnlitPassName = new ShaderPassName("SRPDefaultUnlit"); //For default shaders public static void Render(ScriptableRenderContext context, Camera[] cameras) { RenderPipeline.BeginFrameRendering(cameras); foreach (Camera camera in cameras) { RenderPipeline.BeginCameraRendering(camera); // Culling ScriptableCullingParameters cullingParams; if (!CullResults.GetCullingParameters(camera, out cullingParams)) { continue; } CullResults cull = new CullResults(); CullResults.Cull(ref cullingParams, context, ref cull); //============================================== if (camera.name == "MainCamera" || camera.name == "AllCam" || camera.name == "NoneCam") { string tx = ""; tx += "Culling Result of : " + camera.name + " \n"; tx += "\n"; //------------------------------- VisibleLight[] ls = cull.visibleLights.ToArray(); tx += "Lights : Visible : " + ls.Length + "\n"; if (lights != null) { for (int i = 0; i < lights.Length; i++) { int existed = 0; for (int j = 0; j < ls.Length; j++) { if (lights[i] == ls[j].light) { existed++; } } if (existed > 0) { tx += lights[i].gameObject.name + " : <color=#0F0>Visible</color>" + "\n"; } else { tx += lights[i].gameObject.name + " : <color=#F00>Not Visible</color>" + "\n"; } } } else { tx += "Light list is null \n"; } tx += "\n"; //------------------------------- VisibleReflectionProbe[] rs = cull.visibleReflectionProbes.ToArray(); tx += "Reflection Probes : Visible : " + rs.Length + "\n"; if (reflprobes != null) { for (int i = 0; i < reflprobes.Length; i++) { int existed = 0; for (int j = 0; j < rs.Length; j++) { if (reflprobes[i] == rs[j].probe) { existed++; } } if (existed > 0) { tx += reflprobes[i].gameObject.name + " : <color=#0F0>Visible</color>" + "\n"; } else { tx += reflprobes[i].gameObject.name + " : <color=#F00>Not Visible</color>" + "\n"; } } } else { tx += "reflection probe list is null \n"; } tx += "\n"; //------------------------------- tx += "Renderers : \n"; if (rens != null) { for (int i = 0; i < rens.Length; i++) { if (rens[i].isVisible) { tx += rens[i].gameObject.name + " <color=#0F0>Yes</color> \n"; } else { tx += rens[i].gameObject.name + " <color=#F00>No</color> \n"; } } tx += "\n"; } //------------------------------- //Show debug msg on TextMesh //Debug.Log(tx); if (textMesh != null) { textMesh.text = tx; //Debug.Log("<color=#0F0>TextMesh is updated</color>"); } else { tx = "<color=#F00>TextMesh is null</color> Please hit play if you hasn't"; //Debug.Log(tx); } //update = false; } //============================================== context.SetupCameraProperties(camera); // clear depth buffer CommandBuffer cmd = new CommandBuffer(); cmd.ClearRenderTarget(true, false, Color.black); context.ExecuteCommandBuffer(cmd); cmd.Release(); // Setup global lighting shader variables SetupLightShaderVariables(cull.visibleLights, context); // Draw skybox context.DrawSkybox(camera); // Setup DrawSettings and FilterSettings ShaderPassName passName = new ShaderPassName("BasicPass"); DrawRendererSettings drawSettings = new DrawRendererSettings(camera, passName); FilterRenderersSettings filterSettings = new FilterRenderersSettings(true); //Draw passes that has no light mode (default) ShaderPassName passNameDefault = new ShaderPassName(""); DrawRendererSettings drawSettingsDefault = new DrawRendererSettings(camera, passNameDefault); drawSettingsDefault.SetShaderPassName(1, m_UnlitPassName); // Draw opaque objects using BasicPass shader pass drawSettings.sorting.flags = SortFlags.CommonOpaque; filterSettings.renderQueueRange = RenderQueueRange.opaque; context.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings); // Default drawSettingsDefault.sorting.flags = SortFlags.CommonOpaque; context.DrawRenderers(cull.visibleRenderers, ref drawSettingsDefault, filterSettings); // Draw transparent objects using BasicPass shader pass drawSettings.sorting.flags = SortFlags.CommonTransparent; filterSettings.renderQueueRange = RenderQueueRange.transparent; context.DrawRenderers(cull.visibleRenderers, ref drawSettings, filterSettings); // Default drawSettingsDefault.sorting.flags = SortFlags.CommonTransparent; context.DrawRenderers(cull.visibleRenderers, ref drawSettingsDefault, filterSettings); context.Submit(); } }