public static void RenderSingleCamera(ScriptableRenderContext context, Camera camera) { if (!camera.TryGetCullingParameters(IsStereoEnabled(camera), out var cullingParameters)) { return; } var settings = asset; LWRPAdditionalCameraData additionalCameraData = null; if (camera.cameraType == CameraType.Game || camera.cameraType == CameraType.VR) #if UNITY_2019_2_OR_NEWER { camera.gameObject.TryGetComponent(out additionalCameraData); } #else { additionalCameraData = camera.gameObject.GetComponent <LWRPAdditionalCameraData>(); } #endif InitializeCameraData(settings, camera, additionalCameraData, out var cameraData); SetupPerCameraShaderConstants(cameraData); ScriptableRenderer renderer = (additionalCameraData != null) ? additionalCameraData.scriptableRenderer : settings.scriptableRenderer; if (renderer == null) { Debug.LogWarning(string.Format("Trying to render {0} with an invalid renderer. Camera rendering will be skipped.", camera.name)); return; } #if UNITY_EDITOR string tag = camera.name; #else string tag = k_RenderCameraTag; #endif CommandBuffer cmd = CommandBufferPool.Get(tag); using (new ProfilingSample(cmd, tag)) { renderer.Clear(); renderer.SetupCullingParameters(ref cullingParameters, ref cameraData); context.ExecuteCommandBuffer(cmd); cmd.Clear(); #if UNITY_EDITOR // Emit scene view UI if (cameraData.isSceneViewCamera) { ScriptableRenderContext.EmitWorldGeometryForSceneView(camera); } #endif var cullResults = context.Cull(ref cullingParameters); InitializeRenderingData(settings, ref cameraData, ref cullResults, out var renderingData); renderer.Setup(context, ref renderingData); renderer.Execute(context, ref renderingData); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); context.Submit(); }
public static void RenderSingleCamera(ScriptableRenderContext context, Camera camera) { if (!camera.TryGetCullingParameters(IsStereoEnabled(camera), out var cullingParameters)) { return; } var settings = asset; LWRPAdditionalCameraData additionalCameraData = null; if (camera.cameraType == CameraType.Game || camera.cameraType == CameraType.VR) { additionalCameraData = camera.gameObject.GetComponent <LWRPAdditionalCameraData>(); } InitializeCameraData(settings, camera, additionalCameraData, out var cameraData); SetupPerCameraShaderConstants(cameraData); ScriptableRenderer renderer = (additionalCameraData != null) ? additionalCameraData.scriptableRenderer : settings.scriptableRenderer; if (renderer == null) { Debug.LogWarning(string.Format("Trying to render {0} with an invalid renderer. Camera rendering will be skipped.", camera.name)); return; } camera.cullingMatrix = Matrix4x4.Ortho(-99999, 99999, -99999, 99999, 0.001f, 99999) * Matrix4x4.Translate(Vector3.forward * -99999 / 2f) * camera.worldToCameraMatrix; CommandBuffer cmd = CommandBufferPool.Get(camera.name); using (new ProfilingSample(cmd, camera.name)) { renderer.Clear(); renderer.SetupCullingParameters(ref cullingParameters, ref cameraData); context.ExecuteCommandBuffer(cmd); cmd.Clear(); #if UNITY_EDITOR // Emit scene view UI if (cameraData.isSceneViewCamera) { ScriptableRenderContext.EmitWorldGeometryForSceneView(camera); } #endif var cullResults = context.Cull(ref cullingParameters); InitializeRenderingData(settings, ref cameraData, ref cullResults, out var renderingData); renderer.Setup(context, ref renderingData); renderer.Execute(context, ref renderingData); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); context.Submit(); }
public static void RenderSingleCamera(LightweightRenderPipeline pipelineInstance, ScriptableRenderContext context, Camera camera) { if (pipelineInstance == null) { Debug.LogError("Trying to render a camera with an invalid render pipeline instance."); return; } if (!camera.TryGetCullingParameters(IsStereoEnabled(camera), out var cullingParameters)) { return; } CommandBuffer cmd = CommandBufferPool.Get(k_RenderCameraTag); using (new ProfilingSample(cmd, k_RenderCameraTag)) { ScriptableRenderer renderer = pipelineInstance.renderer; var settings = asset; LWRPAdditionalCameraData additionalCameraData = camera.gameObject.GetComponent <LWRPAdditionalCameraData>(); InitializeCameraData(settings, camera, additionalCameraData, out var cameraData); SetupPerCameraShaderConstants(cameraData); // TODO: PerObjectCulling also affect reflection probes. Enabling it for now. // if (asset.additionalLightsRenderingMode == LightRenderingMode.Disabled || // asset.maxAdditionalLightsCount == 0) // { // cullingParameters.cullingOptions |= CullingOptions.DisablePerObjectCulling; // } cullingParameters.shadowDistance = Mathf.Min(cameraData.maxShadowDistance, camera.farClipPlane); context.ExecuteCommandBuffer(cmd); cmd.Clear(); #if UNITY_EDITOR // Emit scene view UI if (cameraData.isSceneViewCamera) { ScriptableRenderContext.EmitWorldGeometryForSceneView(camera); } #endif var cullResults = context.Cull(ref cullingParameters); InitializeRenderingData(settings, ref cameraData, ref cullResults, renderer.maxVisibleAdditionalLights, renderer.maxPerObjectAdditionalLights, out var renderingData); renderer.Clear(); IRendererSetup rendererSetup = (additionalCameraData != null) ? additionalCameraData.rendererSetup : settings.rendererSetup; rendererSetup.Setup(renderer, ref renderingData); renderer.Execute(context, ref renderingData); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); context.Submit(); }
public static void RenderSingleCamera(ScriptableRenderContext context, Camera camera, Camera uiCamera = null) { if (!camera.TryGetCullingParameters(IsStereoEnabled(camera), out var cullingParameters)) { return; } var settings = asset; LWRPAdditionalCameraData additionalCameraData = null; if (camera.cameraType == CameraType.Game || camera.cameraType == CameraType.VR || camera.cameraType == CameraType.Reflection) { additionalCameraData = camera.gameObject.GetComponent <LWRPAdditionalCameraData>(); } InitializeCameraData(settings, camera, additionalCameraData, out var cameraData); SetupPerCameraShaderConstants(cameraData); ScriptableRenderer renderer = camera.name == FeedbackGlobals.FeedbackCamName ? settings.feedbackRenderer : (additionalCameraData != null) ? additionalCameraData.scriptableRenderer : settings.scriptableRenderer; // renderer = settings.scriptableRenderer; if (renderer == null) { Debug.LogWarning(string.Format("Trying to render {0} with an invalid renderer. Camera rendering will be skipped.", camera.name)); return; } string camera_tag_string = string.Format("{0},{1}", k_RenderCameraTag, camera.name); CommandBuffer cmd = CommandBufferPool.Get(camera_tag_string); using (new ProfilingSample(cmd, camera_tag_string)) { renderer.Clear(); renderer.SetupCullingParameters(ref cullingParameters, ref cameraData); context.ExecuteCommandBuffer(cmd); cmd.Clear(); #if UNITY_EDITOR // Emit scene view UI if (cameraData.isSceneViewCamera) { ScriptableRenderContext.EmitWorldGeometryForSceneView(camera); } #endif var cullResults = context.Cull(ref cullingParameters); InitializeRenderingData(settings, ref cameraData, ref cullResults, out var renderingData); renderingData.uiCmaera = uiCamera; renderer.Setup(context, ref renderingData); renderer.Execute(context, ref renderingData); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); context.Submit(); }
private Camera CreateMirrorObjects(Camera currentCamera) { LightweightRenderPipelineAsset lwAsset = (LightweightRenderPipelineAsset)GraphicsSettings.renderPipelineAsset; var resMulti = lwAsset.renderScale * GetScaleValue(); m_TextureSize.x = (int)Mathf.Pow(2, Mathf.RoundToInt(Mathf.Log(currentCamera.pixelWidth * resMulti, 2))); m_TextureSize.y = (int)Mathf.Pow(2, Mathf.RoundToInt(Mathf.Log(currentCamera.pixelHeight * resMulti, 2))); // Reflection render texture if (Int2Compare(m_TextureSize, m_OldReflectionTextureSize) || !m_ReflectionTexture) { if (m_ReflectionTexture) { DestroyImmediate(m_ReflectionTexture); } bool useHDR10 = Application.isMobilePlatform && SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.RGB111110Float); RenderTextureFormat hdrFormat = (useHDR10) ? RenderTextureFormat.RGB111110Float : RenderTextureFormat.DefaultHDR; m_ReflectionTexture = new RenderTexture(m_TextureSize.x, m_TextureSize.y, 0, currentCamera.allowHDR ? hdrFormat : RenderTextureFormat.Default); m_ReflectionTexture.useMipMap = m_ReflectionTexture.autoGenerateMips = false; m_ReflectionTexture.autoGenerateMips = false; // no need for mips(unless wanting cheap roughness) m_ReflectionTexture.name = "_PlanarReflection" + GetInstanceID(); m_ReflectionTexture.isPowerOfTwo = true; m_ReflectionTexture.hideFlags = HideFlags.DontSave; m_ReflectionTexture.depth = 32; m_OldReflectionTextureSize = m_TextureSize; } m_ReflectionTexture.DiscardContents(); GameObject go = new GameObject("Planar Refl Camera id" + GetInstanceID() + " for " + currentCamera.GetInstanceID(), typeof(Camera), typeof(Skybox)); LWRPAdditionalCameraData lwrpCamData = go.AddComponent(typeof(LWRPAdditionalCameraData)) as LWRPAdditionalCameraData; lwrpCamData.renderShadows = false; // turn off shadows for the reflection camera lwrpCamData.requiresColorOption = CameraOverrideOption.Off; lwrpCamData.requiresDepthOption = CameraOverrideOption.Off; var reflectionCamera = go.GetComponent <Camera>(); reflectionCamera.transform.SetPositionAndRotation(transform.position, transform.rotation); reflectionCamera.targetTexture = m_ReflectionTexture; reflectionCamera.allowMSAA = currentCamera.allowMSAA; reflectionCamera.depth = -10; reflectionCamera.enabled = false; reflectionCamera.allowHDR = currentCamera.allowHDR; go.hideFlags = HideFlags.DontSave; Shader.SetGlobalTexture("_PlanarReflectionTexture", m_ReflectionTexture); return(reflectionCamera); }
private Camera CreateMirrorObjects(Camera currentCamera) { GameObject go = new GameObject("Planar Refl Camera id" + GetInstanceID() + " for " + currentCamera.GetInstanceID(), typeof(Camera), typeof(Skybox)); LWRPAdditionalCameraData lwrpCamData = go.AddComponent(typeof(LWRPAdditionalCameraData)) as LWRPAdditionalCameraData; lwrpCamData.renderShadows = false; // turn off shadows for the reflection camera lwrpCamData.requiresColorOption = CameraOverrideOption.Off; lwrpCamData.requiresDepthOption = CameraOverrideOption.On; // lwrpCamData.m_RendererOverrideOption = RendererOverrideOption.Custom; // lwrpCamData.GenerateRenderer(); var reflectionCamera = go.GetComponent <Camera>(); reflectionCamera.transform.SetPositionAndRotation(transform.position, transform.rotation); reflectionCamera.targetTexture = m_ReflectionTexture; reflectionCamera.allowMSAA = true; reflectionCamera.depth = -10; reflectionCamera.enabled = false; reflectionCamera.cameraType = CameraType.Reflection; reflectionCamera.allowHDR = false; if (!m_settings.enableSelfCullingDistance) { for (int i = 0, length = m_settings.layerCullingDistances.Length; i < length; ++i) { m_settings.layerCullingDistances[i] = 0; } } else { reflectionCamera.layerCullDistances = m_settings.layerCullingDistances; } go.hideFlags = HideFlags.HideAndDontSave; return(reflectionCamera); }
private Camera CreateMirrorObjects(Camera currentCamera) { GameObject go = new GameObject($"Planar Refl Camera id{GetInstanceID().ToString()} for {currentCamera.GetInstanceID().ToString()}", typeof(Camera)); LWRPAdditionalCameraData lwrpCamData = go.AddComponent(typeof(LWRPAdditionalCameraData)) as LWRPAdditionalCameraData; LWRPAdditionalCameraData lwrpCamDataCurrent = currentCamera.GetComponent <LWRPAdditionalCameraData>(); lwrpCamData.renderShadows = true; // turn off shadows for the reflection camera lwrpCamData.requiresColorOption = CameraOverrideOption.Off; lwrpCamData.requiresDepthOption = CameraOverrideOption.Off; var reflectionCamera = go.GetComponent <Camera>(); reflectionCamera.transform.SetPositionAndRotation(transform.position, transform.rotation); //reflectionCamera.targetTexture = m_ReflectionTexture; reflectionCamera.allowMSAA = currentCamera.allowMSAA; reflectionCamera.depth = -10; reflectionCamera.enabled = false; reflectionCamera.allowHDR = currentCamera.allowHDR; go.hideFlags = HideFlags.HideAndDontSave; return(reflectionCamera); }
static void InitializeCameraData(LightweightRenderPipelineAsset settings, Camera camera, LWRPAdditionalCameraData additionalCameraData, out CameraData cameraData) { const float kRenderScaleThreshold = 0.05f; cameraData.camera = camera; int msaaSamples = 1; if (camera.allowMSAA && settings.msaaSampleCount > 1) { msaaSamples = (camera.targetTexture != null) ? camera.targetTexture.antiAliasing : settings.msaaSampleCount; } if (Camera.main == camera && camera.cameraType == CameraType.Game && camera.targetTexture == null) { // There's no exposed API to control how a backbuffer is created with MSAA // By settings antiAliasing we match what the amount of samples in camera data with backbuffer // We only do this for the main camera and this only takes effect in the beginning of next frame. // This settings should not be changed on a frame basis so that's fine. QualitySettings.antiAliasing = msaaSamples; } cameraData.isSceneViewCamera = camera.cameraType == CameraType.SceneView; cameraData.isStereoEnabled = IsStereoEnabled(camera); cameraData.isHdrEnabled = camera.allowHDR && settings.supportsHDR; cameraData.postProcessLayer = camera.GetComponent <PostProcessLayer>(); cameraData.postProcessEnabled = cameraData.postProcessLayer != null && cameraData.postProcessLayer.isActiveAndEnabled; // Disables postprocessing in mobile VR. It's stable on mobile yet. if (cameraData.isStereoEnabled && Application.isMobilePlatform) { cameraData.postProcessEnabled = false; } Rect cameraRect = camera.rect; cameraData.isDefaultViewport = (!(Math.Abs(cameraRect.x) > 0.0f || Math.Abs(cameraRect.y) > 0.0f || Math.Abs(cameraRect.width) < 1.0f || Math.Abs(cameraRect.height) < 1.0f)); // If XR is enabled, use XR renderScale. // Discard variations lesser than kRenderScaleThreshold. // Scale is only enabled for gameview. float usedRenderScale = XRGraphics.enabled ? XRGraphics.eyeTextureResolutionScale : settings.renderScale; cameraData.renderScale = (Mathf.Abs(1.0f - usedRenderScale) < kRenderScaleThreshold) ? 1.0f : usedRenderScale; cameraData.renderScale = (camera.cameraType == CameraType.Game) ? cameraData.renderScale : 1.0f; bool anyShadowsEnabled = settings.supportsMainLightShadows || settings.supportsAdditionalLightShadows; cameraData.maxShadowDistance = (anyShadowsEnabled) ? settings.shadowDistance : 0.0f; if (additionalCameraData != null) { cameraData.maxShadowDistance = (additionalCameraData.renderShadows) ? cameraData.maxShadowDistance : 0.0f; cameraData.requiresDepthTexture = additionalCameraData.requiresDepthTexture; cameraData.requiresOpaqueTexture = additionalCameraData.requiresColorTexture; } else { cameraData.requiresDepthTexture = settings.supportsCameraDepthTexture; cameraData.requiresOpaqueTexture = settings.supportsCameraOpaqueTexture; } cameraData.requiresDepthTexture |= cameraData.isSceneViewCamera || cameraData.postProcessEnabled; var commonOpaqueFlags = SortingCriteria.CommonOpaque; var noFrontToBackOpaqueFlags = SortingCriteria.SortingLayer | SortingCriteria.RenderQueue | SortingCriteria.OptimizeStateChanges | SortingCriteria.CanvasOrder; bool hasHSRGPU = SystemInfo.hasHiddenSurfaceRemovalOnGPU; bool canSkipFrontToBackSorting = (camera.opaqueSortMode == OpaqueSortMode.Default && hasHSRGPU) || camera.opaqueSortMode == OpaqueSortMode.NoDistanceSort; cameraData.defaultOpaqueSortFlags = canSkipFrontToBackSorting ? noFrontToBackOpaqueFlags : commonOpaqueFlags; cameraData.captureActions = CameraCaptureBridge.GetCaptureActions(camera); cameraData.cameraTargetDescriptor = CreateRenderTextureDescriptor(camera, cameraData.renderScale, cameraData.isStereoEnabled, cameraData.isHdrEnabled, msaaSamples); }
static void InitializeCameraData(LightweightRenderPipelineAsset settings, Camera camera, LWRPAdditionalCameraData additionalCameraData, out CameraData cameraData) { const float kRenderScaleThreshold = 0.05f; cameraData.camera = camera; cameraData.isStereoEnabled = IsStereoEnabled(camera); int msaaSamples = 1; if (camera.allowMSAA && settings.msaaSampleCount > 1) { msaaSamples = (camera.targetTexture != null) ? camera.targetTexture.antiAliasing : settings.msaaSampleCount; } cameraData.isSceneViewCamera = camera.cameraType == CameraType.SceneView; cameraData.isHdrEnabled = camera.allowHDR && settings.supportsHDR; #if UNITY_2019_2_OR_NEWER camera.TryGetComponent(out cameraData.postProcessLayer); #else cameraData.postProcessLayer = camera.GetComponent <PostProcessLayer>(); #endif cameraData.postProcessEnabled = cameraData.postProcessLayer != null && cameraData.postProcessLayer.isActiveAndEnabled; // On Android, Postprocessing v2 works with single-pass double-wide mode and is disabled for multiview var xrDesc = UnityEngine.XR.XRSettings.eyeTextureDesc; if (cameraData.isStereoEnabled && Application.isMobilePlatform && Application.platform == RuntimePlatform.Android && xrDesc.dimension == TextureDimension.Tex2DArray) { cameraData.postProcessEnabled = false; } Rect cameraRect = camera.rect; cameraData.isDefaultViewport = (!(Math.Abs(cameraRect.x) > 0.0f || Math.Abs(cameraRect.y) > 0.0f || Math.Abs(cameraRect.width) < 1.0f || Math.Abs(cameraRect.height) < 1.0f)); // If XR is enabled, use XR renderScale. // Discard variations lesser than kRenderScaleThreshold. // Scale is only enabled for gameview. float usedRenderScale = XRGraphics.enabled ? XRGraphics.eyeTextureResolutionScale : settings.renderScale; cameraData.renderScale = (Mathf.Abs(1.0f - usedRenderScale) < kRenderScaleThreshold) ? 1.0f : usedRenderScale; cameraData.renderScale = (camera.cameraType == CameraType.Game) ? cameraData.renderScale : 1.0f; bool anyShadowsEnabled = settings.supportsMainLightShadows || settings.supportsAdditionalLightShadows; cameraData.maxShadowDistance = Mathf.Min(settings.shadowDistance, camera.farClipPlane); cameraData.maxShadowDistance = (anyShadowsEnabled && cameraData.maxShadowDistance >= camera.nearClipPlane) ? cameraData.maxShadowDistance : 0.0f; if (additionalCameraData != null) { cameraData.maxShadowDistance = (additionalCameraData.renderShadows) ? cameraData.maxShadowDistance : 0.0f; cameraData.requiresDepthTexture = additionalCameraData.requiresDepthTexture; cameraData.requiresOpaqueTexture = additionalCameraData.requiresColorTexture; } else { cameraData.requiresDepthTexture = settings.supportsCameraDepthTexture; cameraData.requiresOpaqueTexture = settings.supportsCameraOpaqueTexture; } cameraData.requiresDepthTexture |= cameraData.isSceneViewCamera || cameraData.postProcessEnabled; var commonOpaqueFlags = SortingCriteria.CommonOpaque; var noFrontToBackOpaqueFlags = SortingCriteria.SortingLayer | SortingCriteria.RenderQueue | SortingCriteria.OptimizeStateChanges | SortingCriteria.CanvasOrder; bool hasHSRGPU = SystemInfo.hasHiddenSurfaceRemovalOnGPU; bool canSkipFrontToBackSorting = (camera.opaqueSortMode == OpaqueSortMode.Default && hasHSRGPU) || camera.opaqueSortMode == OpaqueSortMode.NoDistanceSort; cameraData.defaultOpaqueSortFlags = canSkipFrontToBackSorting ? noFrontToBackOpaqueFlags : commonOpaqueFlags; cameraData.captureActions = CameraCaptureBridge.GetCaptureActions(camera); cameraData.cameraTargetDescriptor = CreateRenderTextureDescriptor(camera, cameraData.renderScale, cameraData.isStereoEnabled, cameraData.isHdrEnabled, msaaSamples); }
static void InitializeCameraData(PipelineSettings settings, Camera camera, out CameraData cameraData) { const float kRenderScaleThreshold = 0.05f; cameraData.camera = camera; bool msaaEnabled = camera.allowMSAA && settings.msaaSampleCount > 1; if (msaaEnabled) { cameraData.msaaSamples = (camera.targetTexture != null) ? camera.targetTexture.antiAliasing : settings.msaaSampleCount; } else { cameraData.msaaSamples = 1; } cameraData.isSceneViewCamera = camera.cameraType == CameraType.SceneView; cameraData.isStereoEnabled = IsStereoEnabled(camera); cameraData.isHdrEnabled = camera.allowHDR && settings.supportsHDR; cameraData.postProcessLayer = camera.GetComponent <PostProcessLayer>(); cameraData.postProcessEnabled = cameraData.postProcessLayer != null && cameraData.postProcessLayer.isActiveAndEnabled; Rect cameraRect = camera.rect; cameraData.isDefaultViewport = (!(Math.Abs(cameraRect.x) > 0.0f || Math.Abs(cameraRect.y) > 0.0f || Math.Abs(cameraRect.width) < 1.0f || Math.Abs(cameraRect.height) < 1.0f)); // If XR is enabled, use XR renderScale. // Discard variations lesser than kRenderScaleThreshold. // Scale is only enabled for gameview. float usedRenderScale = XRGraphics.enabled ? XRGraphics.eyeTextureResolutionScale : settings.renderScale; cameraData.renderScale = (Mathf.Abs(1.0f - usedRenderScale) < kRenderScaleThreshold) ? 1.0f : usedRenderScale; cameraData.renderScale = (camera.cameraType == CameraType.Game) ? cameraData.renderScale : 1.0f; cameraData.opaqueTextureDownsampling = settings.opaqueDownsampling; bool anyShadowsEnabled = settings.supportsMainLightShadows || settings.supportsAdditionalLightShadows; cameraData.maxShadowDistance = (anyShadowsEnabled) ? settings.shadowDistance : 0.0f; LWRPAdditionalCameraData additionalCameraData = camera.gameObject.GetComponent <LWRPAdditionalCameraData>(); if (additionalCameraData != null) { cameraData.maxShadowDistance = (additionalCameraData.renderShadows) ? cameraData.maxShadowDistance : 0.0f; cameraData.requiresDepthTexture = additionalCameraData.requiresDepthTexture; cameraData.requiresOpaqueTexture = additionalCameraData.requiresColorTexture; } else { cameraData.requiresDepthTexture = settings.supportsCameraDepthTexture; cameraData.requiresOpaqueTexture = settings.supportsCameraOpaqueTexture; } cameraData.requiresDepthTexture |= cameraData.isSceneViewCamera || cameraData.postProcessEnabled; var commonOpaqueFlags = SortingCriteria.CommonOpaque; var noFrontToBackOpaqueFlags = SortingCriteria.SortingLayer | SortingCriteria.RenderQueue | SortingCriteria.OptimizeStateChanges | SortingCriteria.CanvasOrder; bool hasHSRGPU = SystemInfo.hasHiddenSurfaceRemovalOnGPU; bool canSkipFrontToBackSorting = (camera.opaqueSortMode == OpaqueSortMode.Default && hasHSRGPU) || camera.opaqueSortMode == OpaqueSortMode.NoDistanceSort; cameraData.defaultOpaqueSortFlags = canSkipFrontToBackSorting ? noFrontToBackOpaqueFlags : commonOpaqueFlags; cameraData.captureActions = CameraCaptureBridge.GetCaptureActions(camera); }
/// <inheritdoc/> public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag); using (new ProfilingSample(cmd, m_ProfilerTag)) { context.ExecuteCommandBuffer(cmd); cmd.Clear(); SetRenderTarget( cmd, m_RenderTargetHandle.Identifier(), RenderBufferLoadAction.Load, RenderBufferStoreAction.Store, ClearFlag.Depth, Color.black, TargetDimension); // GetCameraDescriptor Camera uiCamera = renderingData.uiCmaera; Matrix4x4 projMatrix = uiCamera.projectionMatrix; Matrix4x4 viewMatrix = uiCamera.worldToCameraMatrix; //Matrix4x4 viewProjMatrix = projMatrix * viewMatrix; //cmd.SetGlobalMatrix("UNITY_MATRIX_VP", viewProjMatrix); cmd.SetProjectionMatrix(projMatrix); cmd.SetViewMatrix(viewMatrix); cmd.SetViewProjectionMatrices(viewMatrix, projMatrix); cmd.SetViewport(uiCamera.pixelRect); context.ExecuteCommandBuffer(cmd); cmd.Clear(); LWRPAdditionalCameraData additionalCameraData = null; //LightweightRenderPipeline.BeginCameraRenderingWrapper(context, uiCamera); if (!uiCamera.TryGetCullingParameters(LightweightRenderPipeline.IsStereoEnabled(uiCamera), out var cullingParameters)) { return; } if (uiCamera.cameraType == CameraType.Game || uiCamera.cameraType == CameraType.VR) { additionalCameraData = uiCamera.gameObject.GetComponent <LWRPAdditionalCameraData>(); } LightweightRenderPipeline.InitializeCameraData(renderingData.pipelineAsset, uiCamera, additionalCameraData, out var uiCameraData); LightweightRenderPipeline.SetupPerCameraShaderConstants(uiCameraData); // Get Rendering data var cullResults = context.Cull(ref cullingParameters); LightweightRenderPipeline.InitializeRenderingData(renderingData.pipelineAsset, ref uiCameraData, ref cullResults, out var uiRenderingData); //var drawOpaqueSettings = CreateDrawingSettings(m_ShaderTagIdList, ref uiRenderingData, SortingCriteria.CommonOpaque); //context.DrawRenderers(uiRenderingData.cullResults, ref drawOpaqueSettings, ref m_FilteringSettings); var drawTransparentSettings = CreateDrawingSettings(m_ShaderTagIdList, ref uiRenderingData, SortingCriteria.CommonTransparent); context.DrawRenderers(uiRenderingData.cullResults, ref drawTransparentSettings, ref m_FilteringSettings); // Render objects that did not match any shader pass with error shader RenderingUtils.RenderObjectsWithError(context, ref uiRenderingData.cullResults, uiCamera, m_FilteringSettings, SortingCriteria.None); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }