浏览代码

Start VR hack branch to experiment

Use with Mercurial branch graphics/vr-srp-sandbox

Current functionality:
* Works with VR singlepass only.  Tested with split stereo display and Vive, but should work with other platforms that support singlepass.
* Stereo-izes only the DrawRenderers and DrawSkybox commands, on purpose.  Shadow rendering is done mono
* Supports creation of intermediate targets, though the creation of a target that matches a VR target is currently kinda hacky.
/vr_sandbox
Robert Srinivasiah 8 年前
当前提交
e11fc818
共有 1 个文件被更改,包括 106 次插入8 次删除
  1. 114
      Assets/LowEndMobilePipeline/LowEndMobilePipeline.cs

114
Assets/LowEndMobilePipeline/LowEndMobilePipeline.cs


using UnityEngine.Experimental.Rendering;
using UnityEngine.Rendering;
using UnityEngine.VR;
using UnityEditor;
namespace UnityEngine.Experimental.Rendering.LowendMobile
{
public class LowEndMobilePipeline : RenderPipeline

foreach (Camera camera in cameras)
{
CullingParameters cullingParameters;
if (!CullResults.GetCullingParameters(camera, out cullingParameters))
continue;

var cmd = new CommandBuffer() {name = "Clear"};
// Render Shadow Map
bool shadowsRendered = RenderShadows(cull, context);
// Draw Opaques with support to one directional shadow cascade
// Setup camera matrices
//context.SetupCameraProperties(camera);
if (VRSettings.isDeviceActive)
{
//camera.stereoTargetEye = StereoTargetEyeMask.Left;
context.StereoSetupCameraProperties(camera);
context.StartMultiEye(camera);
}
else
{
context.SetupCameraProperties(camera);
}
// set up a temporary RT to render to
var intermediateRT = Shader.PropertyToID("_IntermediateTarget");
var intermediateRTID = new RenderTargetIdentifier(intermediateRT);
var intermediateDepthRT = Shader.PropertyToID("_IntermediateDepthTarget");
var intermediateDepthRTID = new RenderTargetIdentifier(intermediateDepthRT);
if (VRSettings.isDeviceActive)
{
int w = VRSettings.eyeTextureWidth;
int h = VRSettings.eyeTextureHeight;
var aa = QualitySettings.antiAliasing;
if (aa < 1)
aa = 1;
var bindTempRTCmd = new CommandBuffer() { name = "Bind intermediate RT" };
// TODO: this won't work in...the Player
var stereoPath = PlayerSettings.stereoRenderingPath;
if (StereoRenderingPath.Instancing == stereoPath) // can't actually check for GetGraphicsCaps().hasRenderTargetArrayIndexFromAnyShader...yet
{
bindTempRTCmd.GetTemporaryRTArray(intermediateRT, w, h, 2, 0, FilterMode.Point, RenderTextureFormat.Default, RenderTextureReadWrite.Default, aa, true);
bindTempRTCmd.GetTemporaryRTArray(intermediateDepthRT, w, h, 2, 24, FilterMode.Point, RenderTextureFormat.Depth);
}
else
{
bindTempRTCmd.GetTemporaryRT(intermediateRT, w, h, 0, FilterMode.Point, RenderTextureFormat.Default, RenderTextureReadWrite.Default, aa, true);
bindTempRTCmd.GetTemporaryRT(intermediateDepthRT, w, h, 24, FilterMode.Point, RenderTextureFormat.Depth);
}
bindTempRTCmd.SetRenderTarget(intermediateRTID, intermediateDepthRTID);
context.ExecuteCommandBuffer(bindTempRTCmd);
bindTempRTCmd.Dispose();
}
else
{
int w = camera.pixelWidth;
int h = camera.pixelHeight;
var aa = QualitySettings.antiAliasing;
if (aa < 1)
aa = 1;
var bindTempRTCmd = new CommandBuffer() { name = "Bind intermediate RT" };
// this does the combined color/depth RT
bindTempRTCmd.GetTemporaryRT(intermediateRT, w, h, 24, FilterMode.Point, RenderTextureFormat.Default, RenderTextureReadWrite.Default, aa, true);
bindTempRTCmd.SetRenderTarget(intermediateRTID);
//bindTempRTCmd.GetTemporaryRT(intermediateDepthRT, w, h, 24, FilterMode.Point, RenderTextureFormat.Depth);
//bindTempRTCmd.SetRenderTarget(intermediateRTID, intermediateDepthRTID);
context.ExecuteCommandBuffer(bindTempRTCmd);
bindTempRTCmd.Dispose();
}
var cmd = new CommandBuffer() { name = "Clear" };
// Render Shadow Map
bool shadowsRendered = RenderShadows(cull, context);
// Draw Opaques with support to one directional shadow cascade
// Setup camera matrices
context.SetupCameraProperties(camera);
// Setup light and shadow shader constants
SetupLightShaderVariables(cull.visibleLights, context);

settings.sorting.flags = SortFlags.CommonTransparent;
settings.inputFilter.SetQueuesTransparent();
context.DrawRenderers(ref settings);
// ok, copy from temporary RT into the real RT
if (VRSettings.isDeviceActive)
{
//context.StereoSetupCameraProperties(camera);
var copyIntermediateRTToDefault = new CommandBuffer() { name = "Copy intermediate RT to default RT" };
//copyIntermediateRTToDefault.Blit(intermediateRTID, BuiltinRenderTextureType.CurrentActive);
copyIntermediateRTToDefault.Blit(intermediateRTID, BuiltinRenderTextureType.CameraTarget);
context.ExecuteCommandBuffer(copyIntermediateRTToDefault);
copyIntermediateRTToDefault.Dispose();
}
else
{
//context.SetupCameraProperties(camera);
var copyIntermediateRTToDefault = new CommandBuffer() { name = "Copy intermediate RT to default RT" };
copyIntermediateRTToDefault.Blit(intermediateRTID, BuiltinRenderTextureType.CameraTarget); // this works, but barely
//copyIntermediateRTToDefault.Blit(intermediateRTID, camera.targetTexture); // this won't work, target texture won't be right until SetupCameraProperties ACTUALLY executes
//copyIntermediateRTToDefault.Blit(intermediateRTID, BuiltinRenderTextureType.CurrentActive);
context.ExecuteCommandBuffer(copyIntermediateRTToDefault);
copyIntermediateRTToDefault.Dispose();
}
if (VRSettings.isDeviceActive)
{
context.StopMultiEye(camera);
context.StereoEndRender(camera);
}
}
context.Submit();

正在加载...
取消
保存