Scriptable Render Pipeline (SRP) 之 ScriptableRenderContext

///

ScriptableRenderContext

Description

Defines state and drawing commands that custom render pipelines use.

When you define a custom RenderPipeline, you use a ScriptableRenderContext to schedule and submit state updates and drawing commands to the GPU.

RenderPipeline.Render method implementation typically culls objects that the render pipeline doesn't need to render for every Camera (see CullingResults), and then makes a series of calls to ScriptableRenderContext.DrawRenderers intermixed with ScriptableRenderContext.ExecuteCommandBuffer calls. These calls set up global Shader properties, change render targets, dispatch compute shaders, and other rendering tasks. To actually execute the render loop, call ScriptableRenderContext.Submit.

See Also: RenderPipeline.

Public Methods

BeginRenderPassSchedules the beginning of a new render pass. Only one render pass can be active at any time.
BeginScopedRenderPassSchedules the beginning of a new render pass. If you call this a using-statement, Unity calls EndRenderPass automatically when exiting the using-block. Only one render pass can be active at any time.
BeginScopedSubPassSchedules the beginning of a new sub pass within a render pass. If you call this in a using-statement, Unity executes EndSubPass automatically when exiting the using-block. Render passes can never be standalone, they must always contain at least one sub pass. Only one sub pass can be active at any time.
BeginSubPassSchedules the beginning of a new sub pass within a render pass. Render passes can never be standalone, they must always contain at least one sub pass. Only one sub pass can be active at any time.
CullPerforms culling based on the ScriptableCullingParameters typically obtained from the Camera currently being rendered.
DrawGizmosSchedules the drawing of a subset of Gizmos (before or after post-processing) for the given Camera.
DrawRenderersSchedules the drawing of a set of visible objects, and optionally overrides the GPU's render state.
DrawShadowsSchedules the drawing of shadow casters for a single Light.
DrawSkyboxSchedules the drawing of the skybox.
DrawUIOverlayDraw the UI overlay.
DrawWireOverlaySchedules the drawing of a wireframe overlay for a given Scene view Camera.
EndRenderPassSchedules the end of a currently active render pass.
EndSubPassSchedules the end of the currently active sub pass.
ExecuteCommandBufferSchedules the execution of a custom graphics Command Buffer.
ExecuteCommandBufferAsyncSchedules the execution of a Command Buffer on an async compute queue. The ComputeQueueType that you pass in determines the queue order.
InvokeOnRenderObjectCallbackSchedules an invocation of the OnRenderObject callback for MonoBehaviour scripts.
SetupCameraPropertiesSchedules the setup of Camera specific global Shader variables.
StartMultiEyeSchedules a fine-grained beginning of stereo rendering on the ScriptableRenderContext.
StereoEndRenderSchedule notification of completion of stereo rendering on a single frame.
StopMultiEyeSchedules a stop of stereo rendering on the ScriptableRenderContext.
SubmitSubmits all the scheduled commands to the rendering loop for execution.

Static Methods

EmitGeometryForCameraEmits UI geometry for rendering for the specified camera.
EmitWorldGeometryForSceneViewEmits UI geometry into the Scene view for rendering.

/

CullingResults

Description

A struct containing the results of a culling operation.

In the Scriptable Render Pipeline, when Unity performs a culling operation, it stores the results in a CullingResults struct. This data includes information about visible objects, lights, and reflection probes. Unity uses this data to render objects and process lights. A CullingResults struct also provides several functions to aid shadow rendering.

To obtain a CullingResults struct, call ScriptableRenderContext.Cull.

CullingResults struct is valid within the scope of a RenderPipeline.Render function; its data goes out of scope when the Render function returns. You can use the same CullingResults struct multiple times within the same render loop, and you can share a CullingResults struct between multiple Cameras if you know that they can see the same objects. This can save on wasted CPU operations, and therefore improve performance.

This example demonstrates how to obtain a CullingResults struct, and then pass it to ScriptableRenderContext.DrawRenderers.

using UnityEngine;
using UnityEngine.Rendering;

public class ExampleRenderPipeline : RenderPipeline
{
    public ExampleRenderPipeline()
    {
    }

    protected override void Render(ScriptableRenderContext context, Camera[] cameras)
    {
        foreach (Camera camera in cameras)
        {
            // Get the culling parameters from the current camera
            camera.TryGetCullingParameters(out var cullingParameters);

            // Schedule the cull operation that populates the CullingResults struct
            CullingResults cullingResults = context.Cull(ref cullingParameters);

            // Place code that schedules drawing operations using the CullingResults struct here
            // See ScriptableRenderContext.DrawRenderers for details and examples
            // …

            // Execute all of the scheduled operations, in order
            context.Submit();
        }
    }
}

Properties

lightAndReflectionProbeIndexCountGets the number of per-object light and reflection probe indices.
lightIndexCountGets the number of per-object light indices.
reflectionProbeIndexCountGets the number of per-object reflection probe indices.
visibleLightsArray of visible lights.
visibleOffscreenVertexLightsOff-screen lights that still affect visible vertices.
visibleReflectionProbesArray of visible reflection probes.

Public Methods

ComputeDirectionalShadowMatricesAndCullingPrimitivesCalculates the view and projection matrices and shadow split data for a directional light.
ComputePointShadowMatricesAndCullingPrimitivesCalculates the view and projection matrices and shadow split data for a point light.
ComputeSpotShadowMatricesAndCullingPrimitivesCalculates the view and projection matrices and shadow split data for a spot light.
FillLightAndReflectionProbeIndicesFills a buffer with per-object light indices.
GetLightIndexMapIf a RenderPipeline sorts or otherwise modifies the VisibleLight list, an index remap will be necessary to properly make use of per-object light lists.
GetReflectionProbeIndexMapIf a RenderPipeline sorts or otherwise modifies the VisibleReflectionProbe list, an index remap will be necessary to properly make use of per-object reflection probe lists.
GetShadowCasterBoundsReturns the bounding box that encapsulates the visible shadow casters. Can be used to, for instance, dynamically adjust cascade ranges.
SetLightIndexMapIf a RenderPipeline sorts or otherwise modifies the VisibleLight list, an index remap will be necessary to properly make use of per-object light lists.
SetReflectionProbeIndexMapIf a RenderPipeline sorts or otherwise modifies the VisibleReflectionProbe list, an index remap will be necessary to properly make use of per-object reflection probe lists.

/

//

/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值