Skip to content

Instantly share code, notes, and snippets.

@phi-lira
Created March 19, 2019 14:02
Show Gist options
  • Save phi-lira/46c98fc67640cda47dcd27e9b3765b85 to your computer and use it in GitHub Desktop.
Save phi-lira/46c98fc67640cda47dcd27e9b3765b85 to your computer and use it in GitHub Desktop.
LWRP FullScreenQuad feature example. This can be used to extend LWRP render to render a full screen quad.
namespace UnityEngine.Rendering.LWRP
{
// A renderer feature contains data and logic to enqueue one or more render passes in the LWRP renderer.
// In order to add a render feature to a LWRP renderer, click on the renderer asset and then on the + icon in
// the renderer features list. LWRP uses reflection to list all renderer features in the project as available to be
// added as renderer features.
public class FullScreenQuad : ScriptableRendererFeature
{
[System.Serializable]
public struct FullScreenQuadSettings
{
// The render pass event to inject this render feature.
public RenderPassEvent renderPassEvent;
// Material to render the quad.
public Material material;
}
// Contains settings for the render pass.
public FullScreenQuadSettings m_Settings;
// The actual render pass we are injecting.
FullScreenQuadPass m_RenderQuadPass;
public override void Create()
{
// Caches the render pass. Create method is called when the renderer instance is being constructed.
m_RenderQuadPass = new FullScreenQuadPass(m_Settings);
}
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
// Enqueues the render pass for execution. Here you can inject one or more render passes in the renderer
// AddRenderPasses is called everyframe.
if (m_Settings.material != null)
renderer.EnqueuePass(m_RenderQuadPass);
}
}
}
namespace UnityEngine.Rendering.LWRP
{
// The render pass contains logic to configure render target and perform drawing.
// It contains a renderPassEvent that tells the pipeline where to inject the custom render pass.
// The execute method contains the rendering logic.
public class FullScreenQuadPass : ScriptableRenderPass
{
string m_ProfilerTag = "DrawFullScreenPass";
FullScreenQuad.FullScreenQuadSettings m_Settings;
public FullScreenQuadPass(FullScreenQuad.FullScreenQuadSettings settings)
{
renderPassEvent = settings.renderPassEvent;
m_Settings = settings;
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
Camera camera = renderingData.cameraData.camera;
var cmd = CommandBufferPool.Get(m_ProfilerTag);
cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity);
cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, m_Settings.material);
cmd.SetViewProjectionMatrices(camera.worldToCameraMatrix, camera.projectionMatrix);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
}
}
@0x6c6565
Copy link

So apparently, m_ in front of the word settings stops the property from displaying. smh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment