|
|
|
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine.Rendering; |
|
|
|
using UnityEngine.Experimental.Rendering; |
|
|
|
using UnityEngine.XR; |
|
|
|
|
|
|
|
// Very basic scriptable rendering loop example:
|
|
|
|
// - Use with BasicRenderPipelineShader.shader (the loop expects "BasicPass" pass type to exist)
|
|
|
|
|
|
|
|
|
|
|
public static void Render(ScriptableRenderContext context, IEnumerable<Camera> cameras) |
|
|
|
{ |
|
|
|
bool stereoEnabled = XRSettings.isDeviceActive; |
|
|
|
|
|
|
|
if (!CullResults.GetCullingParameters(camera, out cullingParams)) |
|
|
|
// Stereo-aware culling parameters are configured to perform a single cull for both eyes
|
|
|
|
if (!CullResults.GetCullingParameters(camera, stereoEnabled, out cullingParams)) |
|
|
|
continue; |
|
|
|
CullResults cull = new CullResults(); |
|
|
|
CullResults.Cull(ref cullingParams, context, ref cull); |
|
|
|
|
|
|
context.SetupCameraProperties(camera); |
|
|
|
// If stereo is enabled, we also configure stereo matrices, viewports, and XR device render targets
|
|
|
|
context.SetupCameraProperties(camera, stereoEnabled); |
|
|
|
|
|
|
|
// Draws in-between [Start|Stop]MultiEye are stereo-ized by engine
|
|
|
|
if (stereoEnabled) |
|
|
|
context.StartMultiEye(camera); |
|
|
|
|
|
|
|
// clear depth buffer
|
|
|
|
var cmd = CommandBufferPool.Get(); |
|
|
|
|
|
|
settings.sorting.flags = SortFlags.CommonTransparent; |
|
|
|
settings.inputFilter.SetQueuesTransparent(); |
|
|
|
context.DrawRenderers(ref settings); |
|
|
|
|
|
|
|
if (stereoEnabled) |
|
|
|
{ |
|
|
|
context.StopMultiEye(camera); |
|
|
|
// StereoEndRender will reset state on the camera to pre-Stereo settings,
|
|
|
|
// and invoke XR based events/callbacks.
|
|
|
|
context.StereoEndRender(camera); |
|
|
|
} |
|
|
|
|
|
|
|
context.Submit(); |
|
|
|
} |
|
|
|