본문 바로가기
개발/Unity

Unity) 옵션 설정-자동 품질(퀄리티 : Auto Qulity Setting)

by 테샤르 2024. 1. 22.

옵션 설정-자동 품질(퀄리티 : Auto Qulity Setting)

 

자동 품질을 설정하기 위해서 방법을 강구하다가 발견한 코드이다.

해당 코드를 최신화 해서 간략하게 정리한다.

 

퀄리티에 대한 설정은 좀더 다양하게 가능하다.

해당 코드는 참고용 코드로 생각하면 된다.

 

FPS, 메모리 사이즈/ 프로세스 카운트를 통해서 간략하게 퀄리티에 대한 설정을 하는 코드이다.

 

3D 게임에서는 퀄리티 옵션에 대해서 추가로 더욱 다양하게 설정이 가능하다.

LOD, 오클루전 컬링, 카메라 설정변경 등등이 가능하다.

 

 

반응형

 

< 코드 >

eQualityLevel AutoChooseQualityLevel()
{
    Assert.IsTrue(QualitySettings.names.Length == Enum.GetNames(typeof(eQualityLevel)).Length, "eQualityLevel을 새로운 품질 수준으로 업데이트하십시오.");

    int shaderLevel = SystemInfo.graphicsShaderLevel;
    int vram = SystemInfo.graphicsMemorySize;
    int cpus = SystemInfo.processorCount;

    int fillrate;
    if (shaderLevel < 10)
        fillrate = 1000;
    else if (shaderLevel < 20)
        fillrate = 1300;
    else if (shaderLevel < 30)
        fillrate = 2000;
    else
        fillrate = 3000;

    fillrate *= (cpus >= 6) ? 3 : (cpus >= 3) ? 2 : 1;
    fillrate *= (vram >= 512) ? 2 : (vram <= 128) ? 0.5f : 1;

    int resx = Screen.width;
    int resy = Screen.height;
    float target_fps = 30.0f;
    float fillneed = (resx * resy + 400f * 300f) * (target_fps / 1000000.0f);

    // 각 품질 수준에 대한 상대적인 채우기 속도 요구 사항과 일치하도록 levelmult의 값을 변경하십시오.
    float[] levelmult = { 5.0f, 30.0f, 80.0f, 130.0f, 200.0f, 320.0f };

    const int max_quality = (int)eQualityLevel.Fantastic;
    int level = 0;
    while (level < max_quality && fillrate > fillneed * levelmult[level + 1])
        ++level;

    eQualityLevel quality = (eQualityLevel)level;

     Debug.Log($"{resx}x{resy} need {fillneed} has {fillrate} = {quality} level");

    return quality;
}

 

Unity SystemInfo.graphicsShaderLevel : [링크]

 

Unity - Scripting API: SystemInfo.graphicsShaderLevel

This is approximate "shader capability" level of the graphics device, expressed in DirectX shader model terms. Possible values are: 50 Shader Model 5.0 (DX11.0) 46 OpenGL 4.1 capabilities (Shader Model 4.0 + tessellation) 45 Metal / OpenGL ES 3.1 capabilit

docs.unity3d.com

Unity SystemInfo.graphicsMemorySize : [링크]

 

SystemInfo-graphicsMemorySize - Unity 스크립팅 API

Amount of video memory present (Read Only).

docs.unity3d.com

 

Unity SystemInfo.processorCount : [링크]

 

Unity - Scripting API: SystemInfo.processorCount

This is number of "logical processors" as reported by the operating system, also commonly called as "number of hardware threads". Note that some CPUs have different amounts of "physical cores" and "logical cores" (for example, many Intel CPUs have 4 physic

docs.unity3d.com

 

원본 링크 : [링크]

 

Automatic quality settings

a lot of apps that I see nowadays(Android) instead of having an options screen to select the graphical level, it just automatically does it, I know this is kind of a vast question, but how can I do...

stackoverflow.com

 

 

★☆☆☆☆

 

 

반응형

댓글