Unity性能优化-降低功耗,发热量,耗电量之OnDemandRendering篇

公司游戏项目,手机运行严重发烫,耗电量飞快。在暂时无法做其他美术性和技术性优化的情况下,我写了这个公司内部文档,并做了个实验,今天干脆公布出来,希望对大家有用。

--官方文档:

Unity - Scripting API: OnDemandRendering

--Youtube讲解:

https://www.youtube.com/watch?v=RYgWn6jbteY

youtube上的极端实验结果:

好,现在我们来做一下实验,看把渲染帧率从60,动态降低到12左右,手机耗电量会降低多少,温度是否能降低。

第一次测试:

我们把如下代码挂到场景中任意一个游戏体,设置渲染帧率60的情况下:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering; 


public class Change_Frame : MonoBehaviour
{

    // 目标帧率
    public int FrameRate = 60;


    // Start is called before the first frame update
    void Start()
    {
        //QualitySettings.vSyncCount = 0;
        Application.targetFrameRate = FrameRate;
        // 降低帧率
        // If there isn't any input then we can go back to 12 FPS (every 5 frames).
        // OnDemandRendering.renderFrameInterval = 5;
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

开始测试,手机电量为78%,测试开始时间,8:27,如下:

 结束测试,手机电量为72%,测试结束时间,8:42,如下:

 第一次测试结论:

测试时长:15分钟,耗电量6%,手机明显发热,略烫手,肯定是40度以上。

第二次测试:

我们把代码改一下,其实就是取消OnDemandRendering.renderFrameInterval = 5; 的注释,把渲染帧率设置为12:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering; 


public class Change_Frame : MonoBehaviour
{

    // 目标帧率
    public int FrameRate = 60;


    // Start is called before the first frame update
    void Start()
    {
        //QualitySettings.vSyncCount = 0;
        Application.targetFrameRate = FrameRate;
        // 降低帧率
        // If there isn't any input then we can go back to 12 FPS (every 5 frames).
        OnDemandRendering.renderFrameInterval = 5;
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

开始测试,手机电量为71%,测试开始时间,9:00,如下:

结束测试,手机电量为72%,测试结束时间,8:42,如下:

 第二次测试结论:

测试时长:15分钟,耗电量3%,手机不怎么发热,感觉在室温左右,总之肯定低于36度。

 结论:

使用OnDemandRendering可以动态调整渲染帧率。 渲染帧率的下降,无疑会对耗电量、功耗、发热量产生积极影响。

多说一句,其实Adaptive Performance方案,我个人理解,也是通过:感知硬件状况,比如温度、功耗等等,然后通过调节渲染帧率、调节LOD水平,去达到一个动态的功能和功耗的平衡。就是三星那个项目,有着非常可观的性能和较低的功耗。

猜你喜欢

转载自blog.csdn.net/chenggong2dm/article/details/125106939