222 lines
6.7 KiB
C#
222 lines
6.7 KiB
C#
using UnityEngine;
|
|
using UnityEngine.Rendering.Universal;
|
|
using X.Rendering.Feature;
|
|
|
|
[ExecuteAlways]
|
|
public class Test : MonoBehaviour
|
|
{
|
|
public Transform transform;
|
|
int vrs = 0;
|
|
|
|
static float[] resultions = new float[]
|
|
{
|
|
1.0f,
|
|
0.75f,
|
|
0.66f,
|
|
0.5f,
|
|
0.33f
|
|
};
|
|
static string[] dlssQualitys = new string[]
|
|
{
|
|
"MaximumPerformance",
|
|
"Balanced",
|
|
"MaximumQuality",
|
|
"UltraPerformance"
|
|
};
|
|
|
|
private int resultionIndex = 0;
|
|
private bool dlssOn = false;
|
|
private int dlssQuality;
|
|
|
|
private bool xessOn = false;
|
|
private bool hwssr = false;
|
|
|
|
private void Start()
|
|
{
|
|
RenderingPlugin.InitSupportFeatures();
|
|
}
|
|
|
|
public void OnClickVRS()
|
|
{
|
|
var asset = UniversalRenderPipeline.asset;
|
|
if (asset != null)
|
|
{
|
|
vrs++;
|
|
if (vrs > (int)RenderingPlugin.VRSPluginShadingRate.X1_PER_4X4_PIXELS)
|
|
{
|
|
vrs = 0;
|
|
}
|
|
|
|
asset.VRSRate = (RenderingPlugin.VRSPluginShadingRate)vrs;
|
|
Debug.Log("VRS RATE" + asset.VRSRate);
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
|
|
//transform?.Rotate(new Vector3(0, 0.1f, 0));
|
|
if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.R))
|
|
{
|
|
resultionIndex++;
|
|
resultionIndex = resultionIndex % resultions.Length;
|
|
UniversalRenderPipeline.asset.renderScale = resultions[resultionIndex];
|
|
}
|
|
|
|
if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.E))
|
|
{
|
|
dlssOn = !dlssOn;
|
|
var asset = UniversalRenderPipeline.asset;
|
|
DLSS dlss = null;
|
|
foreach (var item in asset.GetRenderer(0).rendererFeatures)
|
|
{
|
|
if (item is DLSS dl)
|
|
{
|
|
dlss = dl;
|
|
break;
|
|
}
|
|
}
|
|
if (dlssOn)
|
|
{
|
|
asset.superResolution = ESuperResolution.DLSS2;
|
|
dlss.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
|
|
SuperResolutionParamSets.Instance.Set<bool>("NeedJitter", false);
|
|
SuperResolutionParamSets.Instance.Set<float>("MipmapBias", 0);
|
|
asset.superResolution = ESuperResolution.None;
|
|
dlss.SetActive(false);
|
|
}
|
|
}
|
|
if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.Q))
|
|
{
|
|
dlssQuality++;
|
|
dlssQuality = dlssQuality % dlssQualitys.Length;
|
|
var asset = UniversalRenderPipeline.asset;
|
|
DLSS dlss = null;
|
|
foreach (var item in asset.GetRenderer(0).rendererFeatures)
|
|
{
|
|
if (item is DLSS dl)
|
|
{
|
|
dlss = dl;
|
|
break;
|
|
}
|
|
}
|
|
|
|
#if !UNITY_ANDROID && !UNITY_IPHONE && !UNITY_IOS && !UNITY_EDITOR_OSX && !UNITY_OPENHARMONY
|
|
dlss.quality = (UnityEngine.NVIDIA.DLSSQuality)dlssQuality;
|
|
#endif
|
|
}
|
|
|
|
if (Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.X))
|
|
{
|
|
xessOn = !xessOn;
|
|
var asset = UniversalRenderPipeline.asset;
|
|
XESS xess = null;
|
|
foreach (var item in asset.GetRenderer(0).rendererFeatures)
|
|
{
|
|
if (item is XESS xe)
|
|
{
|
|
xess = xe;
|
|
break;
|
|
}
|
|
}
|
|
if (xessOn)
|
|
{
|
|
asset.superResolution = ESuperResolution.XESS13;
|
|
xess.SetSR(ESuperResolution.XESS13);
|
|
}
|
|
else
|
|
{
|
|
SuperResolutionParamSets.Instance.Set<bool>("NeedJitter", false);
|
|
SuperResolutionParamSets.Instance.Set<float>("MipmapBias", 0);
|
|
asset.superResolution = ESuperResolution.None;
|
|
xess.SetSR(ESuperResolution.None);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
GUIStyle font;
|
|
|
|
private void Awake()
|
|
{
|
|
font = new GUIStyle();
|
|
font.normal.background = null;
|
|
font.normal.textColor = Color.green;
|
|
font.fontSize = 32;
|
|
}
|
|
|
|
private void OnGUI()
|
|
{
|
|
//if (GUI.Button(new Rect(100,10, 100, 50), "VRS"))
|
|
//{
|
|
// OnClickVRS();
|
|
//}
|
|
//if (GUI.Button(new Rect(100, 100, 100, 50), "FG"))
|
|
//{
|
|
// X.Rendering.Feature.FG.UseFG = !X.Rendering.Feature.FG.UseFG;
|
|
//}
|
|
|
|
//if (GUI.Button(new Rect(100, 200, 100, 50), "MetalSR"))
|
|
// // if (Input.GetKeyDown(KeyCode.P))
|
|
//{
|
|
// var asset = UniversalRenderPipeline.asset;
|
|
// asset.superResolution = ESuperResolution.METAL_FX_SPATIAL_SR;
|
|
// asset.UpdateSSSettings();
|
|
//}
|
|
#if !UNITY_ANDROID && !UNITY_IPHONE && !UNITY_IOS && !UNITY_EDITOR_OSX && !UNITY_OPENHARMONY
|
|
|
|
GUI.Label(new Rect(50, 100, 300, 100), $"ctrl + r resultion:{resultions[resultionIndex]}", font);
|
|
GUI.Label(new Rect(50, 150, 300, 100), $"ctrl + e dlss:{(dlssOn ? "On" : "Off")}", font);
|
|
GUI.Label(new Rect(50, 200, 300, 100), $"ctrl + q quality:{dlssQualitys[dlssQuality]}", font);
|
|
#endif
|
|
#if UNITY_EDITOR_WIN || UNITY_OPENHARMONY
|
|
if (GUI.Button(new Rect(50, 100, 300, 50), $"resultion:{resultions[resultionIndex]}"))
|
|
{
|
|
resultionIndex++;
|
|
resultionIndex = resultionIndex % resultions.Length;
|
|
UniversalRenderPipeline.asset.renderScale = resultions[resultionIndex];
|
|
}
|
|
if (GUI.Button(new Rect(50, 150, 300, 50), $"HWSpatialUpScale:{(hwssr ? "On" : "Off")}"))
|
|
{
|
|
hwssr = !hwssr;
|
|
var asset = UniversalRenderPipeline.asset;
|
|
HuaweiSR hwsr = null;
|
|
foreach (var item in asset.GetRenderer(0).rendererFeatures)
|
|
{
|
|
if (item is HuaweiSR sr)
|
|
{
|
|
hwsr = sr;
|
|
break;
|
|
}
|
|
}
|
|
if (hwssr)
|
|
{
|
|
asset.superResolution = ESuperResolution.HW_SPATIAL_SR;
|
|
hwsr.SetSR(ESuperResolution.HW_SPATIAL_SR);
|
|
}
|
|
else
|
|
{
|
|
SuperResolutionParamSets.Instance.Set<bool>("NeedJitter", false);
|
|
SuperResolutionParamSets.Instance.Set<float>("MipmapBias", 0);
|
|
asset.superResolution = ESuperResolution.None;
|
|
hwsr.SetSR(ESuperResolution.None);
|
|
}
|
|
|
|
}
|
|
#endif
|
|
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
|
|
GUI.Label(new Rect(50, 250, 300, 100), $"shift + x xess:{(xessOn ? "On" : "Off")}", font);
|
|
#endif
|
|
}
|
|
|
|
public static void TestBatchMode()
|
|
{
|
|
Debug.Log("TestBatchMode");
|
|
}
|
|
}
|
|
|