浏览代码

Initial example of VR API in BasicRenderPipeline

Shows how to use the VR API, along with how to create VR render textures
/vr_api_testbed
Robert Srinivasiah 8 年前
当前提交
51c67e90
共有 1 个文件被更改,包括 52 次插入2 次删除
  1. 54
      Assets/ScriptableRenderPipeline/BasicRenderPipelineTutorial/BasicRenderPipeline.cs

54
Assets/ScriptableRenderPipeline/BasicRenderPipelineTutorial/BasicRenderPipeline.cs


using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering;
using UnityEngine.VR;
// Very basic scriptable rendering loop example:
// - Use with BasicRenderPipelineShader.shader (the loop expects "BasicPass" pass type to exist)

{
foreach (var camera in cameras)
{
bool stereoEnabled = VRSettings.isDeviceActive;
if (!CullResults.GetCullingParameters(camera, out cullingParams))
if (!CullResults.GetCullingParameters(camera, stereoEnabled, out cullingParams))
context.SetupCameraProperties(camera);
// If stereo is enabled, we also configure stereo matrices, viewports, and device render targets
context.SetupCameraProperties(camera, stereoEnabled);
// Draws in-between [Start|Stop]MultiEye are stereo-ized by engine
if (stereoEnabled)
context.StartMultiEye(camera);
// This is an example of how to create/use an intermediate VR rendertexture
var intermediateRT = Shader.PropertyToID("_IntermediateTarget");
var intermediateRTID = new RenderTargetIdentifier(intermediateRT);
{
var bindTempRTCmd = new CommandBuffer() { name = "Bind intermediate RT" };
if (stereoEnabled)
{
RenderTextureDescriptor vrDesc = VRSettings.GetVREyeTextureDesc();
vrDesc.depthBufferBits = 24;
bindTempRTCmd.GetTemporaryRT(intermediateRT, vrDesc, FilterMode.Point);
}
else
{
int w = camera.pixelWidth;
int h = camera.pixelHeight;
var aa = QualitySettings.antiAliasing;
if (aa < 1)
aa = 1;
bindTempRTCmd.GetTemporaryRT(intermediateRT, w, h, 24, FilterMode.Point, RenderTextureFormat.Default, RenderTextureReadWrite.Default, aa, true);
}
bindTempRTCmd.SetRenderTarget(intermediateRTID);
context.ExecuteCommandBuffer(bindTempRTCmd);
bindTempRTCmd.Dispose();
}
// clear depth buffer
var cmd = new CommandBuffer();

settings.sorting.flags = SortFlags.CommonTransparent;
settings.inputFilter.SetQueuesTransparent();
context.DrawRenderers(ref settings);
// Copy from intermediate texture to camera target (back buffer or VR device texture)
var copyIntermediateRTToDefault = new CommandBuffer() { name = "Copy intermediate RT to default RT" };
copyIntermediateRTToDefault.Blit(intermediateRTID, BuiltinRenderTextureType.CameraTarget);
context.ExecuteCommandBuffer(copyIntermediateRTToDefault);
copyIntermediateRTToDefault.Dispose();
if (stereoEnabled)
context.StopMultiEye(camera);
// In order to reset state on the camera to pre-Stereo settings, and to invoke
// VR based events/callbacks, we need to call StereoEndRender.
if (stereoEnabled)
context.StereoEndRender(camera);
context.Submit();
}

正在加载...
取消
保存