Dynamic resolution 动态分辨率

本文档主要是对Unity官方手册的个人理解与总结(其实以翻译记录为主:>)
仅作为个人学习使用,不得作为商业用途,欢迎转载,并请注明出处。
文章中涉及到的操作都是基于Unity2018.3版本
参考链接:https://docs.unity3d.com/Manual/DynamicResolution.html

Dynamic resolution is a Camera setting that allows you to dynamically scale individual render targets, to reduce workload on the GPU. In cases where the application’s frame rate reduces, you can gradually scale down the resolution to maintain a consistent frame rate instead. Unity triggers this scaling if performance data suggests that the frame rate is about to decrease as a result of the application being GPU-bound. You can also trigger the scaling manually by preempting a particularly GPU-intensive section of the application and controlling the scaling via a script. If scaled gradually, dynamic resolution can be almost unnoticeable.
动态分辨率是相机设置中允许您动态缩放单个渲染目标,以减少GPU上的工作负载。在应用程序的帧率降低的情况下,您可以逐步降低分辨率,以保持一致的帧率。如果性能数据表明,由于应用程序受GPU限制,帧速率将会降低,那么Unity将触发这种扩展。您还可以通过抢占调度应用程序中占用GPU特别多的部分并通过脚本控制缩放。如果逐步缩放,动态分辨率几乎不被发觉。

Supported platforms 支持平台

Unity supports dynamic resolution on Xbox One, PS4, Nintendo Switch, iOS/tvOS (Metal only) and Android (Vulkan only).

Impact on render targets 对渲染目标的影响

With dynamic resolution, Unity does not re-allocate render targets. Conceptually, Unity scales the render target; however, in reality, Unity uses aliasing, and the scaled-down render target only uses a small portion of the original render target. Unity allocates the render targets at their full resolution, and then the dynamic resolution system scales them down and back up again, using a portion of the original target instead of re-allocating a new target.
使用动态分辨率,Unity不会重新申请渲染目标。理论上,Unity会缩放渲染目标;然而,在现实中,Unity使用了混叠,缩小的渲染目标只使用了原始渲染目标的一小部分。Unity以完整的分辨率申请渲染目标,然后动态分辨率系统对它们进行向下和向上的缩放,使用原始目标的一部分,而不是重新分配一个新的目标。

Scaling render targets 缩放渲染目标

With dynamic resolution, render targets have the DynamicallyScalable flag. You can set this to state whether Unity should scale this render texture as part of the dynamic resolution process or not. Cameras also have the allowDynamicResolution flag, which you can use to set up dynamic resolution so that there is no need to override the render target if you just want to apply dynamic resolution to a less complex Scene.
使用动态分辨率,渲染目标有动态可伸缩的标志。可以设置Unity是否应该缩放这个RT作为动态分辨率处理的状态。相机也有是否允许使用动态分辨率的标志,你可以用它来设置动态分辨率。这样,如果你只是想在一个不太复杂的场景中应用动态分辨率,就不需要重写渲染目标。

MRT buffers

When you enable Allow Dynamic Resolution on the Camera, Unity scales all of that Camera’s targets.
当你启用相机的动态分辨率,Unity会缩放相机的所有目标。

Controlling the scaling 控制缩放
You can control the scale through the ScalableBufferManager. The ScalableBufferManager gives you control of the dynamic width and height scale for all render targets you have marked for the dynamic resolution system to scale.
您可以通过ScalableBufferManager控制缩放。ScalableBufferManager为动态分辨率系统标记的所有渲染目标提供动态宽度和高度的缩放控制。

As an example, assume your application is running at a desirable frame rate, but under some circumstances the GPU performance decreases, due to a combination of increased particles, post-effects and screen complexity. The Unity FrameTimingManager allows you to detect when the CPU or GPU performance start to decrease. So you can use the FrameTimingManager to calculate a new desired width and height scale to keep the frame rate within your desired range, and bring the scale down to that value to keep performance stable (either instantly or gradually over a set amount of frames). When the screen complexity reduces and the GPU is performing consistently, you may then raise the width and height scale back to a value that you’ve calculated the GPU can handle.
例如,假设您的应用程序以理想的帧速率运行,但是在某些情况下,GPU性能会下降,这是由于粒子增加、后期效果和屏幕复杂性的共同作用。Unity FrameTimingManager允许您检测CPU或GPU性能何时开始下降。因此,您可以使用FrameTimingManager来计算一个新的期望宽度和高度比例,以将帧速率保持在您希望的范围内,并将比例降至该值,以保持性能稳定(在设置的帧数量上可以立即进行,也可以逐步进行)。当屏幕复杂度降低且与GPU执行一致时,您可以将宽度和高度缩放到计算过的GPU可以处理的值上。

Example
This example script demonstrates basic use of the API. Add it to a Camera in your Scene, and check Allow Dynamic Resolution in the Camera settings. You also need to open the Player settings (menu: Edit > Project Settings, then select the Player category) and check the Enable Frame Timing Stats checkbox.
这个示例脚本演示了API的基本用法。将其添加到场景中的相机中,并检查相机设置是否允许动态分辨率。您还需要打开Player设置(菜单:Edit > Project Settings,,然后选择Player类别)并选中Enable Frame Timing Stats复选框。

Clicking the mouse, or tapping the screen with one finger, lowers the height and width resolution by the amount in the scaleWidthIncrement and scaleHeightIncrement variables respectively. Tapping with two fingers raises the resolutions by the same increment.
单击鼠标或用手指点击屏幕,分别降低scaleWidthIncrement变量和scaleHeightIncrement变量的高度和宽度分辨率。用两个手指敲击屏幕,分辨率也会以同样的增量提高分辨率。

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;public class DynamicResolutionTest : MonoBehaviour
{public Text screenText;FrameTiming[] frameTimings = new FrameTiming[3];public float maxResolutionWidthScale = 1.0f;public float maxResolutionHeightScale = 1.0f;public float minResolutionWidthScale = 0.5f;public float minResolutionHeightScale = 0.5f;public float scaleWidthIncrement = 0.1f;public float scaleHeightIncrement = 0.1f;float m_widthScale = 1.0f;float m_heightScale = 1.0f;// Variables for dynamic resolution algorithm that persist across framesuint m_frameCount = 0;const uint kNumFrameTimings = 2;double m_gpuFrameTime;double m_cpuFrameTime;// Use this for initializationvoid Start(){int rezWidth = (int)Mathf.Ceil(ScalableBufferManager.widthScaleFactor * Screen.currentResolution.width);int rezHeight = (int)Mathf.Ceil(ScalableBufferManager.heightScaleFactor * Screen.currentResolution.height);screenText.text = string.Format("Scale: {0:F3}x{1:F3}\nResolution: {2}x{3}\n",m_widthScale,m_heightScale,rezWidth,rezHeight);}// Update is called once per framevoid Update(){float oldWidthScale = m_widthScale;float oldHeightScale = m_heightScale;// One finger lowers the resolutionif (Input.GetButtonDown("Fire1")){m_heightScale = Mathf.Max(minResolutionHeightScale, m_heightScale - scaleHeightIncrement);m_widthScale = Mathf.Max(minResolutionWidthScale, m_widthScale - scaleWidthIncrement);}// Two fingers raises the resolutionif (Input.GetButtonDown("Fire2")){m_heightScale = Mathf.Min(maxResolutionHeightScale, m_heightScale + scaleHeightIncrement);m_widthScale = Mathf.Min(maxResolutionWidthScale, m_widthScale + scaleWidthIncrement);}if (m_widthScale != oldWidthScale || m_heightScale != oldHeightScale){ScalableBufferManager.ResizeBuffers(m_widthScale, m_heightScale);}DetermineResolution();int rezWidth = (int)Mathf.Ceil(ScalableBufferManager.widthScaleFactor * Screen.currentResolution.width);int rezHeight = (int)Mathf.Ceil(ScalableBufferManager.heightScaleFactor * Screen.currentResolution.height);screenText.text = string.Format("Scale: {0:F3}x{1:F3}\nResolution: {2}x{3}\nScaleFactor: {4:F3}x{5:F3}\nGPU: {6:F3} CPU: {7:F3}",m_widthScale,m_heightScale,rezWidth,rezHeight,ScalableBufferManager.widthScaleFactor,ScalableBufferManager.heightScaleFactor,m_gpuFrameTime,m_cpuFrameTime);}// Estimate the next frame time and update the resolution scale if necessary.private void DetermineResolution(){++m_frameCount;if (m_frameCount <= kNumFrameTimings){return;}FrameTimingManager.CaptureFrameTimings();FrameTimingManager.GetLatestTimings(kNumFrameTimings, frameTimings);if (frameTimings.Length < kNumFrameTimings){Debug.LogFormat("Skipping frame {0}, didn't get enough frame timings.",m_frameCount);return;}m_gpuFrameTime = (double)frameTimings[0].gpuFrameTime;m_cpuFrameTime = (double)frameTimings[0].cpuFrameTime;}
}

Dynamic resolution 动态分辨率 相机系列6相关推荐

  1. ​多大分辨率图像做分类更适合?浙大华为国科大等提出Dynamic Resolution Network,降低计算量还提性能!...

    关注公众号,发现CV技术之美 ▊ 写在前面 为了获得更高的精度,深卷积神经网络(CNN)通常具有复杂的设计,具有许多卷积层和可学习的参数.为了减轻在移动设备上部署网络的成本,最近的工作开始研究在预定义 ...

  2. 类脑传感器:动态视觉相机(Dynamic Vision Sensor)和动态音频传感器(Dynamic Audio Sensor)

    动态视觉相机 一点点发展史 动态视觉相机 Dynamic Vision Sensor(DVS),有时候也称作事件相机(Event camera)或者硅视网膜(Silicon Retina). 提到DV ...

  3. 【深度相机系列四】深度相机分类之结构光法

    说明:文中所举例的产品比较早,读者把重点放在学习原理上就好. 一.结构光法:为解决双目匹配问题而生 上一篇<[深度相机系列三]深度相机分类之双目立体视觉法>中提到基于双目立体视觉的深度相机 ...

  4. Dynamic Resolution Network

    Abstract 由于准确性的原因,深度卷积神经网络(CNN)通常具有复杂的设计,有许多可学习的参数.为了减轻在移动设备上部署它们的昂贵成本,最近的工作为挖掘预先定义的架构中的冗余做了巨大的努力.然而 ...

  5. xcode新版本single view_动态数组函数系列1|概况-跟以往Excel版本完全不一样玩法的函数...

    早就听说在Office2019和Office365版本中增加了动态数组函数(Dynamic arrays),早前一直处于内测阶段,只对部分预览用户开放.昨天试了一下,我用的版本已经更新可用了.当前我使 ...

  6. 相机成像原理_【科研进展】动态虚拟相机:探索三维视觉成像新方法

    由于微信公众号试行乱序推送,您可能没办法准时收到"爱光学"的文章.为了让您第一时间看到"爱光学"的新鲜推送, 请您: 1. 将"爱光学"点亮 ...

  7. C++Dynamic Array动态数组(附完整源码)

    Dynamic Array动态数组 Dynamic Array动态数组算法的完整源码(定义,实现,main函数测试) Dynamic Array动态数组算法的完整源码(定义,实现,main函数测试) ...

  8. filter函数的用法_动态数组函数系列5| 筛选函数FILTER,单条件多条件动态筛选

    FILTER函数是筛选函数,就是在源数据中按照我们的条件筛选出我们想要的数据.除了常规的数据筛选,还可以进行多条件的"且"或者"或"的筛选. 下面我们来看看这个 ...

  9. 借助 OpenGL* ES 2.0 实现动态分辨率渲染

    作者:omar-a-rodrigue 下载 借助 OpenGL* ES 2.0 实现动态分辨率渲染[PDF 677KB] 代码样本: dynamic-resolution.zip[ZIP 4MB] 像 ...

  10. JDK Dynamic Proxy_JDK动态代理

    为什么80%的码农都做不了架构师?>>> JDK Dynamic Proxy_JDK动态代理 更详细的在http://my.oschina.net/xinxingegeya/blog ...

最新文章

  1. Sublime Text 3 (含:配置 C# 编译环境)
  2. http访问不到服务器_HTTP及会话技术解析:大魏Java记4
  3. 解题报告-Leecode 563. 二叉树的坡度——Leecode每日一题系列
  4. jboss8日志级别设置_罐中研讨会:设置JBoss BPM Suite全日研讨会
  5. 项响琴C语言书籍在线浏览,电子琴 c语言程序
  6. css链接,列表,表格
  7. oracle掉电后ora 00600,ORA-00600: 内部错误代码, 参数: [kcratr1_lastbwr](转)
  8. OpenSearch自定义分词服务
  9. 使用commons-compress操作zip文件(压缩和解压缩)
  10. 智能手机屏幕尺寸和分辨率一览表
  11. 小说php 站点源码下载,PTCMS小说站源码
  12. 成本要素****没有被分配到成本组件结构01中的成本组件
  13. Chrome打不开网页及设置的解决方法
  14. APP手机测试-理论
  15. 微信移动学习平台小程序 后台基于php+mysql
  16. MyBatis(3)
  17. python替换图片背景色,适用于制作证件照
  18. 阿里开源流控框架 - Sentinel入门介绍
  19. 处在“风口”的永太科技
  20. VTK学习笔记(二)-----读入序列图像进行三维体渲染

热门文章

  1. Visual Studio Code配置Salesforce Apex开发环境
  2. 怎么尽可能将pdf文件压缩到最小
  3. PPT幻灯片母版在制作时的应用
  4. pandas合并多个数据表
  5. EcmaScript 2022中的新特性
  6. mysql order by注入_sql注入之order by注入
  7. java 磁力下载工具_它可能是现在最好用的磁力下载工具
  8. html可以用搜狗浏览器打开网页,搜狗浏览器网页不小心关了怎么办?搜狗浏览器恢复页面三种方法...
  9. getinfo怎么用php,PHP SplObjectStorage getinfo()用法及代码示例
  10. 2021鹏业安装算量软件常见问题整理(五)