比较提交

...
此合并请求有变更与目标分支冲突。
/Assets/ScriptableRenderPipeline/BasicRenderPipelineTutorial/BasicRenderPipeline.cs

1 次代码提交

作者 SHA1 备注 提交日期
Robert Srinivasiah 51c67e90 Initial example of VR API in BasicRenderPipeline 8 年前
共有 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();
}

正在加载...
取消
保存