Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Universal/runtime render pass #2719

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions com.unity.render-pipelines.universal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added 2D Renderer Asset Preset for creating a Universal Renderer Asset
- Added an option to use faster, but less accurate approximation functions when converting between the sRGB and Linear color spaces.
- Added screen space shadow as renderer feature
- Added sample for render passes to show how to enqueue render passes at runtime.

### Changed
- Optimized 2D Renderer performance on mobile GPUs by reducing the number of render target switches.
Expand Down Expand Up @@ -72,6 +73,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed Deferred renderer on some Android devices by forcing accurate GBuffer normals. [case 1288042]
- Fixed an issue where MSAA did not work in Editor Game View on Windows with Vulkan.
- Fixed issue where selecting and deselecting Forward Renderer asset would leak memory [case 1290628](https://issuetracker.unity3d.com/issues/urp-scriptablerendererfeatureeditor-memory-leak-while-interacting-with-forward-renderer-in-the-project-window)
- Fixed an issue such that it is now posible to enqueue render passes at runtime.

## [10.2.0] - 2020-10-19

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# How to add a Render Pass to a Renderer at runtime
To add a Render Pass you need to retrive the scriptable renderer you want to add the Render Pass to and use the function:
'''c++
scriptableRenderer.EnqueuePass(renderPass);
'''
This will have to be done for each frame since the queue is cleared each iteration.

## Example
Here is a small example how to add a Render Pass at Runtime:
```c++
public class RunPassAtRuntime : MonoBehaviour
{
class CustomRenderPass : ScriptableRenderPass
{
// This method is called before executing the render pass.
// It can be used to configure render targets and their clear state. Also to create temporary render target textures.
// When empty this render pass will render to the active camera render target.
// You should never call CommandBuffer.SetRenderTarget. Instead call <c>ConfigureTarget</c> and <c>ConfigureClear</c>.
// The render pipeline will ensure target setup and clearing happens in a performant manner.
public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
{
[...]
}

// Here you can implement the rendering logic.
// Use <c>ScriptableRenderContext</c> to issue drawing commands or execute command buffers
// https://docs.unity3d.com/ScriptReference/Rendering.ScriptableRenderContext.html
// You don't have to call ScriptableRenderContext.submit, the render pipeline will call it at specific points in the pipeline.
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
[...]
}

// Cleanup any allocated resources that were created during the execution of this render pass.
public override void OnCameraCleanup(CommandBuffer cmd)
{
[...]
}
}
CustomRenderPass renderPass;
void Start()
{
renderPass = new CustomRenderPass();
}
void Update()
{
((UniversalRenderPipelineAsset)GraphicsSettings.currentRenderPipeline).scriptableRenderer.EnqueuePass(renderPass);
}
}

A larger code example can be downloaded in: 'Package Manager -> Universal RP -> Samples -> RenderPass Samples'
![Samples located in Universal RP package](Images/urp-download-samples.png)
```
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ protected List<ScriptableRendererFeature> rendererFeatures
}

/// <summary>
/// Returns a list of render passes schedules to be executed by this renderer.
/// Returns a list of render passes scheduled to be executed by this renderer.
/// <seealso cref="ScriptableRenderPass"/>
/// </summary>
protected List<ScriptableRenderPass> activeRenderPassQueue
Expand Down Expand Up @@ -379,6 +379,7 @@ public ScriptableRenderer(ScriptableRendererData data)
m_RendererFeatures.Add(feature);
}
Clear(CameraRenderType.Base);
m_ActiveRenderPassQueue.Clear();
}

public void Dispose()
Expand Down Expand Up @@ -686,8 +687,6 @@ internal void Clear(CameraRenderType cameraType)
m_FirstTimeCameraColorTargetIsBound = cameraType == CameraRenderType.Base;
m_FirstTimeCameraDepthTargetIsBound = true;

m_ActiveRenderPassQueue.Clear();

m_CameraColorTarget = BuiltinRenderTextureType.CameraTarget;
m_CameraDepthTarget = BuiltinRenderTextureType.CameraTarget;
}
Expand Down Expand Up @@ -1050,6 +1049,7 @@ void InternalFinishRendering(ScriptableRenderContext context, bool resolveFinalT
// We finished camera stacking and released all intermediate pipeline textures.
m_IsPipelineExecuting = false;
}
m_ActiveRenderPassQueue.Clear();
}

context.ExecuteCommandBuffer(cmd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,24 @@ public static UniversalAdditionalCameraData GetUniversalAdditionalCameraData(thi

return cameraData;
}

/// <summary>
/// Universal Render Pipeline exposes additional rendering data in a separate component.
/// This method returns the scriptable renderer for the additional data component for the given camera.
/// If the additional camera component doesn't exist create a new additional camera component.
/// </summary>
/// <param name="camera"></param>
/// <returns>The <c>ScriptableRenderer</c> for this camera's additional camera data.</returns>
/// <see cref="UniversalAdditionalCameraData"/>
public static ScriptableRenderer GetRenderer(this Camera camera)
{
var gameObject = camera.gameObject;
bool componentExists = gameObject.TryGetComponent<UniversalAdditionalCameraData>(out var cameraData);
if (!componentExists)
cameraData = gameObject.AddComponent<UniversalAdditionalCameraData>();

return cameraData.scriptableRenderer;
}
}

static class CameraTypeUtility
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"displayName": "RenderPass Samples",
"description": "Adds RenderPass samples to your project. Open the BlurryRefraction scene to see examples of enqueing a renderpass at runtime.",
"createSeparatePackage": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading