forked from StereoKit/StereoKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemoRenderScaling.cs
More file actions
83 lines (67 loc) · 2.54 KB
/
Copy pathDemoRenderScaling.cs
File metadata and controls
83 lines (67 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// SPDX-License-Identifier: MIT
// The authors below grant copyright rights under the MIT license:
// Copyright (c) 2019-2023 Nick Klingensmith
// Copyright (c) 2023 Qualcomm Technologies, Inc.
using StereoKit;
using System;
class DemoRenderScaling : ITest
{
string title = "Render Scaling";
string description = "Sometimes you need to boost the number of pixels your app renders, to reduce jaggies! Renderer.Scaling and Renderer.Multisample let you increase the size of the draw surface, and multisample each pixel.\n\nThis is powerful stuff, so use it sparingly!";
Pose windowPose = Demo.contentPose.Pose;
float multisample;
float scaling;
float viewScaling;
public void Initialize()
{
multisample = Renderer.Multisample;
scaling = Renderer.Scaling;
viewScaling = Renderer.ViewportScaling;
}
public void Shutdown() { }
public void Step()
{
UI.WindowBegin("Render Scaling Settings", ref windowPose, new Vec2(0.3f,0));
// The scaling settings are still XR only, but MSAA works everywhere.
bool xr = Backend.XRType == BackendXRType.OpenXR;
if (!xr)
UI.Label("Scaling settings are only available in XR");
UI.PushEnabled(xr);
UI.Label("Swapchain scaling");
UI.Label($"{scaling:0.00}", V.XY(0.04f,0));
UI.SameLine();
UI.HSlider("scaling", ref scaling, 0.1f, 2, 0.05f);
UI.PopEnabled();
UI.HSeparator();
UI.Label("MSAA");
UI.Label($"{(int)multisample}", V.XY(0.04f, 0));
UI.SameLine();
UI.HSlider("msaa", ref multisample, 1, 8, 1);
if (xr && Input.Key(Key.Right).IsJustActive()) scaling = Math.Min(scaling + 0.1f, 2);
if (xr && Input.Key(Key.Left ).IsJustActive()) scaling = Math.Max(scaling - 0.1f, 0.1f);
if (Input.Key(Key.Up ).IsJustActive()) multisample = Math.Min(multisample + 1, 8);
if (Input.Key(Key.Down ).IsJustActive()) multisample = Math.Max(multisample - 1, 1);
if (UI.Button("Confirm") || Input.Key(Key.Space).IsJustActive())
{
// Read back what we set, since MSAA gets clamped to whatever the
// GPU actually supports.
Renderer.Multisample = (int)multisample;
multisample = Renderer.Multisample;
if (xr)
{
Renderer.Scaling = scaling;
scaling = Renderer.Scaling;
}
}
UI.HSeparator();
UI.PushEnabled(xr);
UI.Label("Viewport Scaling");
UI.Label($"{viewScaling:0.00}", V.XY(0.04f, 0));
UI.SameLine();
if (UI.HSlider("viewscaling", ref viewScaling, 0.1f, 1, 0))
Renderer.ViewportScaling = viewScaling;
UI.PopEnabled();
UI.WindowEnd();
Demo.ShowSummary(title, description, new Bounds(V.XY0(0, -0.16f), V.XYZ(.34f, .42f, 0.1f)));
}
}