原文网站:https://docs.unity3d.com/Manual/SinglePassStereoRenderingHoloLens.html

Single-Pass Stereo Rendering for HoloLens

HoloLens的单程立体渲染

There are two stereo rendering methods for Windows Holographic devices (HoloLens); multi-pass and single-pass instanced.

当前有两种针对windows全息设备(HoloLens)的立体渲染方法;多程渲染和单程渲染。

Multi-pass

Multi-pass rendering runs 2 complete render passes (one for each eye). This generates almost double the CPU workload compared to the single-pass instanced rendering method. However this method is the most backwards compatible and doesn’t require any shader changes.

多程渲染会完成两次完整的渲染过程(每只眼睛一次)。相比于单程渲染方法,这会导致将近两倍的 CPU工作量。然而这是向后兼容性最好的方法,并且它并不需要变更着色器。

Single-pass Instanced

单程渲染

Instanced rendering performs a single render pass where each draw call is replaced with an instanced draw call. This heavily decreases CPU utilization. Additionally this decreases GPU utilization due to the cache coherency between the two draw calls. In turn your app’s power consumption will be much lower.

To enable this feature, open PlayerSettings (menu: Edit Project Settings Player). In PlayerSettings, navigate to Other Settings, check the Virtual Reality Supported checkbox, then select Single Pass Instanced (Fastest) from the Stereo Rendering Method dropdown.

实例化渲染时,每执行一次渲染,每一个绘制调用会被替换成一个实例化渲染调用。这极大的减少了CPU的使用量,另外,如果两次绘制调用的内存关联性较大,这也会少量地减少GPU使用量。这样,你的程序的电量消耗也会变得更加的低,如果想使这个特性生效,打开PlayerSettings(菜单:Edit Project Settings Player)。在 PlayerSettings界面,找到Other Settings,勾选Virtual Reality Supported复选框,然后在Stereo Rendering Method 下拉框里选择Single Pass Instanced (Fastest)。

Unity defaults to the slower Multi pass (Slow) setting as you may have custom shaders that do not have the required code in your scripts to support this feature.

Unity的默认设置是较慢的Multi pass (Slow) ,是因为你能有一些自定义的shader不支持这项特性(single pass)。

Shader script requirements

着色器代码要求

Any non built-in shaders will need to be updated to work with instancing. Please read this documentation to see how this is done: GPU Instancing. Furthermore, you’ll need to make two additional changes in the last shader stage used before the fragment shader (Vertex/Hull/Domain/Geometry). First, you will have to add UNITY_VERTEX_OUTPUT_STEREO to the output struct. Second, you will need to add UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO() in the main function for that stage after UNITY_SETUP_INSTANCE_ID() has been called.

任何非内建的着色器都需要被更新来进行实例化工作。请阅读这个文档来了解如何去做:GPU实例化。此外,你将需要在片段着色器(Vertex/Hull/Domain/Geometry)之前,添加两个额外的变化在着色器的最后部分。首先,你将必须把UNITY_VERTEX_OUTPUT_STEREO 加到output结构体中。其次,你将需要添加UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO()到main函数里,这样,那个部分就会在UNITY_SETUP_INSTANCE_ID()之后调用

Post-Processing Shaders

后处理着色器

You will need to add the UNITY_DECLARE_SCREENSPACE_TEXTURE(tex) macro around the input texture declarations, so that 2D texture arrays will be properly declared. Next, you must add a call to UNITY_SETUP_INSTANCE_ID() at the beginning of the fragment shader. Finally, you will need to use the UNITY_SAMPLE_SCREENSPACE_TEXTURE() macro when sampling those textures. See HLSLSupport.cginc for more information on other similar macros depth textures and screen space shadow maps.

你将需要添加UNITY_DECLARE_SCREENSPACE_TEXTURE(tex)宏到输入纹理声明的地方,这样2D纹理数组才能正确地被声明。然后,你必须在段着色器的开始添加一次UNITY_SETUP_INSTANCE_ID()的调用。最后,你将需要在取样那些纹理时使用theUNITY_SAMPLE_SCREENSPACE_TEXTURE()宏。你可以在 HLSLSupport.cginc里看到更多关于其他类似的宏深度纹理和屏幕空间阴影映射的相关信息。

Here’s a simple example that applies all of the previously mentioned changes to the template image effect:

这里是一个简单的案例,它应用了之前提过的改变,实现了一个样板图片特效。

struct appdata {    float4 vertex : POSITION;    float2 uv : TEXCOORD0;    UNITY_INSTANCE_ID }; struct v2f {    float2 uv : TEXCOORD0;    float4 vertex : SV_POSITION;    UNITY_INSTANCE_ID    UNITY_VERTEX_OUTPUT_STEREO }; v2f vert (appdata v) {    v2f o;    UNITY_SETUP_INSTANCE_ID(v);    UNITY_TRANSFER_INSTANCE_ID(v, o);    UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);    o.vertex = UnityObjectToClipPos(v.vertex);    o.uv = v.uv;    return o; } __UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);__ fixed4 frag (v2f i) : SV_Target {    UNITY_SETUP_INSTANCE_ID(i);    fixed4 col = __UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, i.uv);    // just invert the colors    col = 1 - col;    return col; }

DrawProceduralIndirect

间接程序绘制

Graphics.DrawProceduralIndirect() and CommandBuffer.DrawProceduralIndirect() get all of their arguments from a compute buffer, so we can’t easily increase the instance count. Therefore you will have to manually double the instance count contained in your compute buffers.

Graphics.DrawProceduralIndirect()和CommandBuffer.DrawProceduralIndirect() 可以从一块计算缓存里获取所有的参数,所以我们不能简单的增加实例个数。因此你必须手动地加倍实例数量包括你的计算内存数量。

Vertex and fragment shader examplesSee the  page for more information on shader code.

可以通过“顶点着色器和片段着色器例子”页面获取更多关于着色器代码的知识。

Single-Pass Stereo Rendering for HoloLens——HoloLens的单程立体渲染的更多相关文章

  1. [学习笔记]编译sensetime发表的Single View Stereo Matching(SVS)遇到的问题

    最近在研究用深度学习预测图像深度信息的方法,一开始用的是2017年CVPR上Godard大神的monodepth,代码在这里.这篇文章介绍了利用双目的consistency训练网络以对单张图像进行深度 ...

  2. 立体渲染 Volumetric Rendering

    基础概念 在3D游戏引擎中,球体.立方体以及所有其它复杂的集合体都是由三角面片组成的.引擎只会渲染物体的表面,比如球体,半透明物体等.整个世界由各种空壳构成. 立体渲染(Volumetric Rend ...

  3. unity3d Human skin real time rendering plus 真实模拟人皮实时渲染 plus篇

    最近逃课做游戏,逃的有几门都要停考了,呵呵呵,百忙之中不忘超炒冷饭,感觉之前的人皮效果还是不够好,又改进了一些东西 首先上图 放大看细节 显而易见的比上次的效果要好很多,此次我把模型用3dmax进行了 ...

  4. Direct3D 11 Tutorial 2: Rendering a Triangle_Direct3D 11 教程2:渲染一个三角形

    概要 在之前的教程中,我们建立了一个最小的Direct3D 11的应用程序,它用来在窗口上输出一个单一颜色.在本次教程中,我们将扩展这个应用程序,在屏幕上渲染出一个单一颜色的三角形.我们将通过设置数据 ...

  5. Unity3d 2017

    Unity3d引擎的新纪元--Unity3d 2017 来源 http://blog.csdn.net/dark00800/article/details/75209544 Unity3d不久之前正式 ...

  6. Load store and memoryless

    metal https://developer.apple.com/library/archive/documentation/3DDrawing/Conceptual/MTLBestPractice ...

  7. 微软Hololens学院教程-Hologram 230-空间场景建模(Spatial mapping )【微软教程已经更新,本文是老版本】

    这是老版本的教程,为了不耽误大家的时间,请直接看原文,本文仅供参考哦!原文链接:https://developer.microsoft.com/EN-US/WINDOWS/HOLOGRAPHIC/ho ...

  8. HoloLens开发手记 - Unity之摄像头篇

    当你穿戴好HoloLens后,你就会处在全息应用世界的中心.当你的项目开启了"Virtual Reality Support"选项并选中了"Windows Hologra ...

  9. Unity开发概览(HoloLens开发系列)

    本文翻译自:Unity development overview 要开始使用Unity创建全息应用,点此安装包含Unity HoloLens技术预览的开发工具.Unity HoloLens技术预览基于 ...

随机推荐

  1. [bzoj2665] [cqoi2012]编号

    首先有一个直观暴力的想法.. 枚举每个数,如果这个数可行的话,就加进答案里,然后把和它超过4个位置相同的数去掉. 然后正解真的是这个>_< 假设取到了数x,只要和x有5位相同的数就可以排除 ...

  2. hdu_1006 Tick and Tick(暴力模拟)

    hdu1006 标签(空格分隔): 暴力枚举 好久没有打题了,退队了有好几个月了,从心底不依赖那个人了,原来以为的爱情戏原来都只是我的独角戏.之前的我有时候好希望有个人出现,告诉自己去哪里,做什么,哪 ...

  3. Open-air shopping malls(二分半径,两元交面积)

    http://acm.hdu.edu.cn/showproblem.php?pid=3264 Open-air shopping malls Time Limit: 2000/1000 MS (Jav ...

  4. hbmy周赛1--E

    E - Combination Lock Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I6 ...

  5. SDP(1):ScalikeJDBC-基本操作介绍

    简单来说:JDBC是一种开放标准的跨编程语言.跨数据库类型编程API.各类型数据库产品厂商都会按它的标准要求来提供针对自身产品的JDBC驱动程序.最主要的这是一套成熟的工具,在编程人员中使用很普及.既 ...

  6. Java多线程编程—锁优化

    并发环境下进行编程时,需要使用锁机制来同步多线程间的操作,保证共享资源的互斥访问.加锁会带来性能上的损坏,似乎是众所周知的事情.然而,加锁本身不会带来多少的性能消耗,性能主要是在线程的获取锁的过程.如 ...

  7. C++异常层次结构

    #define _CRT_SECURE_NO_WARNINGS #include <iostream> using namespace std; class MyArray { publi ...

  8. 两种方法上传本地文件到github

    https://www.jianshu.com/p/c70ca3a02087 自从使用github以来,一直都是在github网站在线上传文件到仓库中,但是有时因为网络或者电脑的原因上传失败.最重要的 ...

  9. Vuejs实例-00Vuejs2.0全家桶结合ELementUI制作后台管理系统

    Vuejs2.0全家桶结合ELementUI制作后台管理系统 0: 系统环境的介绍 1: Vuejs实例-01使用vue-cli脚手架搭建Vue.js项目 2: Vuejs实例-02Vue.js项目集 ...

  10. Oracle 数据库中在使用中文模糊查询时输入中文查询不到结果的解决方法

    添加环境变量 变量名:NLS_LANG 变量值:SIMPLIFIED CHINESE_CHINA.ZHS16GBK