Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Dynamic scaling isn't working

Discussion in 'General Graphics' started by newjerseyrunner, Mar 5, 2020.

  1. newjerseyrunner

    newjerseyrunner

    Joined:
    Jul 20, 2017
    Posts:
    966
    I created an empty scene, added a text ui object so that I could see debugging info. then attached my script to the camera itself. The camera is flagged to allow dynamic resolution, but no matter what I do, the internal scale factor always remains at one.

    I thought maybe it was because I was running it in the editor, but a build of the scene yields the same results. I've tested it on both Mac and Windows with nothing to show. Am I doing something wrong?


    Code (CSharp):
    1.  
    2. using System;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using UnityEngine;
    6. using UnityEngine.UI;
    7.  
    8. public class DynamicResolutionTest : MonoBehaviour {
    9.     public Text screenText;
    10.  
    11.     public float maxResolutionWidthScale = 1.0f;
    12.     public float maxResolutionHeightScale = 1.0f;
    13.     public float minResolutionWidthScale = 0.5f;
    14.     public float minResolutionHeightScale = 0.5f;
    15.     public float scaleWidthIncrement = 0.1f;
    16.     public float scaleHeightIncrement = 0.1f;
    17.    
    18.    
    19.     public float decreaseDeltaTimeThreshold = 0.04f;
    20.     public float increaseDeltaTimeThreshold = 0.025f;
    21.    
    22.  
    23.     float m_widthScale = 1.0f;
    24.     float m_heightScale = 1.0f;
    25.  
    26.  
    27.     void Update(){
    28.         float oldWidthScale = m_widthScale;
    29.         float oldHeightScale = m_heightScale;
    30.  
    31.         if (Input.GetKeyDown(KeyCode.DownArrow)){
    32.         //if (Time.deltaTime > decreaseDeltaTimeThreshold){
    33.             m_widthScale -= scaleWidthIncrement;
    34.             if (m_widthScale < minResolutionWidthScale){
    35.                 m_widthScale = minResolutionWidthScale;
    36.                 m_heightScale -= scaleHeightIncrement;
    37.                 if (m_heightScale < minResolutionHeightScale) m_heightScale = minResolutionHeightScale;
    38.             }
    39.         } else if (Input.GetKeyDown(KeyCode.UpArrow)){
    40.         //} else if (Time.deltaTime < increaseDeltaTimeThreshold){
    41.             m_heightScale += scaleHeightIncrement;
    42.             if (m_heightScale > maxResolutionHeightScale){
    43.                 m_heightScale = maxResolutionHeightScale;
    44.                 m_widthScale += scaleWidthIncrement;
    45.                 if (m_widthScale > maxResolutionWidthScale) m_widthScale = maxResolutionWidthScale;
    46.             }
    47.         }
    48.        
    49.         if (m_widthScale != oldWidthScale || m_heightScale != oldHeightScale){
    50.             ScalableBufferManager.ResizeBuffers(m_widthScale, m_heightScale);
    51.         }
    52.        
    53.         int rezWidth = (int)Mathf.Ceil(ScalableBufferManager.widthScaleFactor * (float)Screen.currentResolution.width);
    54.         int rezHeight = (int)Mathf.Ceil(ScalableBufferManager.heightScaleFactor * (float)Screen.currentResolution.height);
    55.         screenText.text = string.Format("Scale: {0:F3}x{1:F3}\nResolution: {2}x{3}\nBuffer Scale: {4:F3}x{5:F3}",
    56.             m_widthScale,
    57.             m_heightScale,
    58.             rezWidth,
    59.             rezHeight,
    60.             ScalableBufferManager.widthScaleFactor,
    61.             ScalableBufferManager.heightScaleFactor);
    62.     }
    63.  
    64. }
     
    Milo_del_mal likes this.
  2. bajja

    bajja

    Joined:
    Feb 3, 2013
    Posts:
    5
    Same - cameras set to allow dynamic res, and the following in an update function:

    Code (CSharp):
    1.  
    2. ScalableBufferManager.ResizeBuffers(0.25f, 0.25f);
    3. Debug.Log(ScalableBufferManager.widthScaleFactor);
    4.  
    Outputs "1" to the log, so cameras are unaffected, and calling ResizeBuffers every frame with a fixed number doesn't change the internal config either.. This is on PC, 2020.1.0f1. It's frustrating that it's just failing silently.
     
  3. bajja

    bajja

    Joined:
    Feb 3, 2013
    Posts:
    5
    Whoops - it turns out to be DX12 only - you need to change APIs.
     
    wang37921, Stardog and Squize like this.
  4. wang37921

    wang37921

    Joined:
    Aug 1, 2014
    Posts:
    100
    great working,in unity, edit menu => project settings=> other settings=> toggle off auto graphics API for Windows=>add Direct3D12 and let Direct3D12 be the first one