internal void ExecuteNativeRenderPass(ScriptableRenderContext context, ScriptableRenderPass renderPass, CameraData cameraData, ref RenderingData renderingData) { using (new ProfilingScope(null, Profiling.execute)) { int currentPassIndex = renderPass.renderPassQueueIndex; Hash128 currentPassHash = m_PassIndexToPassHash[currentPassIndex]; int[] currentMergeablePasses = m_MergeableRenderPassesMap[currentPassHash]; int validColorBuffersCount = m_RenderPassesAttachmentCount[currentPassHash]; bool isLastPass = renderPass.isLastPass; // TODO: review the lastPassToBB logic to mak it work with merged passes // keep track if this is the current camera's last pass and the RT is the backbuffer (BuiltinRenderTextureType.CameraTarget) bool isLastPassToBB = isLastPass && (m_ActiveColorAttachmentDescriptors[0].loadStoreTarget == BuiltinRenderTextureType.CameraTarget); var depthOnly = renderPass.depthOnly || (cameraData.targetTexture != null && cameraData.targetTexture.graphicsFormat == GraphicsFormat.DepthAuto); bool useDepth = depthOnly || (!renderPass.overrideCameraTarget || (renderPass.overrideCameraTarget && renderPass.depthAttachment != BuiltinRenderTextureType.CameraTarget)) && (!(isLastPassToBB || (isLastPass && cameraData.camera.targetTexture != null))); var attachments = new NativeArray <AttachmentDescriptor>(useDepth && !depthOnly ? validColorBuffersCount + 1 : 1, Allocator.Temp); for (int i = 0; i < validColorBuffersCount; ++i) { attachments[i] = m_ActiveColorAttachmentDescriptors[i]; } if (useDepth && !depthOnly) { attachments[validColorBuffersCount] = m_ActiveDepthAttachmentDescriptor; } var rpDesc = InitializeRenderPassDescriptor(cameraData, renderPass); int validPassCount = GetValidPassIndexCount(currentMergeablePasses); var attachmentIndicesCount = GetSubPassAttachmentIndicesCount(renderPass); var attachmentIndices = new NativeArray <int>(!depthOnly ? (int)attachmentIndicesCount : 0, Allocator.Temp); if (!depthOnly) { for (int i = 0; i < attachmentIndicesCount; ++i) { attachmentIndices[i] = renderPass.m_InputAttachmentIndices[i]; } } if (validPassCount == 1 || currentMergeablePasses[0] == currentPassIndex) // Check if it's the first pass { context.BeginRenderPass(rpDesc.w, rpDesc.h, Math.Max(rpDesc.samples, 1), attachments, useDepth ? (!depthOnly ? validColorBuffersCount : 0) : -1); attachments.Dispose(); context.BeginSubPass(attachmentIndices); m_LastBeginSubpassPassIndex = currentPassIndex; } else { if (!AreAttachmentIndicesCompatible(m_ActiveRenderPassQueue[m_LastBeginSubpassPassIndex], m_ActiveRenderPassQueue[currentPassIndex])) { context.EndSubPass(); context.BeginSubPass(attachmentIndices); m_LastBeginSubpassPassIndex = currentPassIndex; } } attachmentIndices.Dispose(); renderPass.Execute(context, ref renderingData); if (validPassCount == 1 || currentMergeablePasses[validPassCount - 1] == currentPassIndex) // Check if it's the last pass { context.EndSubPass(); context.EndRenderPass(); m_LastBeginSubpassPassIndex = 0; } for (int i = 0; i < m_ActiveColorAttachmentDescriptors.Length; ++i) { m_ActiveColorAttachmentDescriptors[i] = RenderingUtils.emptyAttachment; } m_ActiveDepthAttachmentDescriptor = RenderingUtils.emptyAttachment; } }
internal void ExecuteNativeRenderPass(ScriptableRenderContext context, ScriptableRenderPass renderPass, CameraData cameraData, ref RenderingData renderingData) { using (new ProfilingScope(null, Profiling.execute)) { int currentPassIndex = renderPass.renderPassQueueIndex; Hash128 currentPassHash = m_PassIndexToPassHash[currentPassIndex]; int[] currentMergeablePasses = m_MergeableRenderPassesMap[currentPassHash]; int validColorBuffersCount = m_RenderPassesAttachmentCount[currentPassHash]; var depthOnly = (renderPass.colorAttachmentHandle.rt != null && IsDepthOnlyRenderTexture(renderPass.colorAttachmentHandle.rt)) || (cameraData.targetTexture != null && IsDepthOnlyRenderTexture(cameraData.targetTexture)); bool useDepth = depthOnly || (!renderPass.overrideCameraTarget || (renderPass.overrideCameraTarget && renderPass.depthAttachmentHandle.nameID != BuiltinRenderTextureType.CameraTarget));// && var attachments = new NativeArray <AttachmentDescriptor>(useDepth && !depthOnly ? validColorBuffersCount + 1 : 1, Allocator.Temp); for (int i = 0; i < validColorBuffersCount; ++i) { attachments[i] = m_ActiveColorAttachmentDescriptors[i]; } if (useDepth && !depthOnly) { attachments[validColorBuffersCount] = m_ActiveDepthAttachmentDescriptor; } var rpDesc = InitializeRenderPassDescriptor(cameraData, renderPass); int validPassCount = GetValidPassIndexCount(currentMergeablePasses); var attachmentIndicesCount = GetSubPassAttachmentIndicesCount(renderPass); var attachmentIndices = new NativeArray <int>(!depthOnly ? (int)attachmentIndicesCount : 0, Allocator.Temp); if (!depthOnly) { for (int i = 0; i < attachmentIndicesCount; ++i) { attachmentIndices[i] = renderPass.m_ColorAttachmentIndices[i]; } } if (validPassCount == 1 || currentMergeablePasses[0] == currentPassIndex) // Check if it's the first pass { if (PassHasInputAttachments(renderPass)) { Debug.LogWarning("First pass in a RenderPass should not have input attachments."); } context.BeginRenderPass(rpDesc.w, rpDesc.h, Math.Max(rpDesc.samples, 1), attachments, useDepth ? (!depthOnly ? validColorBuffersCount : 0) : -1); attachments.Dispose(); context.BeginSubPass(attachmentIndices); m_LastBeginSubpassPassIndex = currentPassIndex; } else { // Regarding input attachments, currently we always recreate a new subpass if it contains input attachments // This might not the most optimal way though and it should be investigated in the future // Whether merging subpasses with matching input attachments is a more viable option if (!AreAttachmentIndicesCompatible(m_ActiveRenderPassQueue[m_LastBeginSubpassPassIndex], m_ActiveRenderPassQueue[currentPassIndex])) { context.EndSubPass(); if (PassHasInputAttachments(m_ActiveRenderPassQueue[currentPassIndex])) { context.BeginSubPass(attachmentIndices, m_ActiveRenderPassQueue[currentPassIndex].m_InputAttachmentIndices); } else { context.BeginSubPass(attachmentIndices); } m_LastBeginSubpassPassIndex = currentPassIndex; } else if (PassHasInputAttachments(m_ActiveRenderPassQueue[currentPassIndex])) { context.EndSubPass(); context.BeginSubPass(attachmentIndices, m_ActiveRenderPassQueue[currentPassIndex].m_InputAttachmentIndices); m_LastBeginSubpassPassIndex = currentPassIndex; } } attachmentIndices.Dispose(); renderPass.Execute(context, ref renderingData); if (validPassCount == 1 || currentMergeablePasses[validPassCount - 1] == currentPassIndex) // Check if it's the last pass { context.EndSubPass(); context.EndRenderPass(); m_LastBeginSubpassPassIndex = 0; } for (int i = 0; i < m_ActiveColorAttachmentDescriptors.Length; ++i) { m_ActiveColorAttachmentDescriptors[i] = RenderingUtils.emptyAttachment; m_IsActiveColorAttachmentTransient[i] = false; } m_ActiveDepthAttachmentDescriptor = RenderingUtils.emptyAttachment; } }
private void DeferedRender(ScriptableRenderContext context, Camera camera, ref CullingResults cullingResult) { var albedo = new AttachmentDescriptor(RenderTextureFormat.ARGB32); var specRough = new AttachmentDescriptor(RenderTextureFormat.ARGB32); var normal = new AttachmentDescriptor(RenderTextureFormat.ARGB2101010); var emission = new AttachmentDescriptor(RenderTextureFormat.ARGBHalf); var depth = new AttachmentDescriptor(RenderTextureFormat.Depth); emission.ConfigureClear(new Color(0.0f, 0.0f, 0.0f, 0.0f), 1.0f, 0); depth.ConfigureClear(new Color(), 1.0f, 0); NativeArray <AttachmentDescriptor> colorAttachments = new NativeArray <AttachmentDescriptor>(5, Allocator.Temp); colorAttachments[depthIndex] = depth; colorAttachments[specRoughIndex] = specRough; colorAttachments[normalIndex] = normal; colorAttachments[emissionIndex] = emission; colorAttachments[albedoIndex] = albedo; albedo.ConfigureTarget(BuiltinRenderTextureType.CameraTarget, false, true); context.BeginRenderPass(camera.pixelWidth, camera.pixelHeight, 1, colorAttachments, depthIndex); colorAttachments.Dispose(); var gbufferColors = new NativeArray <int>(4, Allocator.Temp); gbufferColors[0] = albedoIndex; gbufferColors[1] = specRoughIndex; gbufferColors[2] = normalIndex; gbufferColors[3] = emissionIndex; //G-Buffer Pass context.BeginSubPass(gbufferColors); gbufferColors.Dispose(); RenderGBuffer(context, camera, ref cullingResult); context.EndSubPass(); var lightingColors = new NativeArray <int>(1, Allocator.Temp); lightingColors[0] = albedoIndex; var lightingInputs = new NativeArray <int>(4, Allocator.Temp); lightingInputs[0] = emissionIndex; lightingInputs[1] = specRoughIndex; lightingInputs[2] = normalIndex; lightingInputs[3] = depthIndex; //Lightning Pass. context.BeginSubPass(lightingColors, lightingInputs, true); lightingInputs.Dispose(); lightingColors.Dispose(); RenderLights(context, camera, ref cullingResult); context.EndSubPass(); context.EndRenderPass(); }