forked from StereoKit/StereoKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemoPBR.cs
More file actions
93 lines (77 loc) · 3.23 KB
/
Copy pathDemoPBR.cs
File metadata and controls
93 lines (77 loc) · 3.23 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
84
85
86
87
88
89
90
91
92
93
// 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;
class DemoPBR : ITest
{
string title = "PBR Shaders";
string description = "Shaders!";
const int materialGrid = 6;
Material[] pbrMaterials;
Model pbrModel;
Mesh sphereMesh;
Material selectionMat;
Tex oldSkyTex;
SphericalHarmonics oldSkyLight;
Pose modelPose = Pose.Identity;
public void Initialize()
{
oldSkyTex = Renderer.SkyTex;
oldSkyLight = Renderer.SkyLight;
sphereMesh = Mesh.GenerateSphere(1, 7);
Renderer.SkyTex = Tex.FromCubemap(@"old_depot.hdr");
Renderer.SkyTex.OnLoaded += t => Renderer.SkyLight = t.CubemapLighting;
selectionMat = new Material("interactable.hlsl");
selectionMat.Transparency = Transparency.Add;
selectionMat.DepthTest = DepthTest.Equal;
pbrModel = Model.FromFile("DamagedHelmet.gltf");
pbrMaterials = new Material[materialGrid*materialGrid];
for (int y = 0; y < materialGrid; y++) {
for (int x = 0; x < materialGrid; x++) {
int i = x + y * materialGrid;
pbrMaterials[i] = new Material(Default.ShaderPbr);
pbrMaterials[i][MatParamName.ColorTint ] = Color.HSV(0.3f, 0.8f, 0.8f);
pbrMaterials[i][MatParamName.MetallicAmount ] = x/(float)(materialGrid-1);
pbrMaterials[i][MatParamName.RoughnessAmount] = y/(float)(materialGrid-1);
} }
/// :CodeSample: Material.GetAllParamInfo Material.GetParamInfo Material.ParamCount MatParamInfo MatParamInfo.name MatParamInfo.type
/// ### Listing parameters in a Material
// Iterate using a foreach
Log.Info("Builtin PBR Materials contain these parameters:");
foreach (MatParamInfo info in Material.PBR.GetAllParamInfo())
Log.Info($"- {info.type,8}: {info.name}");
// Or with a normal for loop
Log.Info("Builtin Unlit Materials contain these parameters:");
for (int i=0; i<Material.Unlit.ParamCount; i+=1)
{
MatParamInfo info = Material.Unlit.GetParamInfo(i);
Log.Info($"- {info.type,8}: {info.name}");
}
/// :End:
}
public void Shutdown()
{
Renderer.SkyTex = oldSkyTex;
Renderer.SkyLight = oldSkyLight;
}
public void Step()
{
Tests.Screenshot("PBRBalls.jpg", 1024, 1024, new Vec3(0, 0, -0.1f), new Vec3(0, 0, -1));
Hierarchy.Push(Matrix.T(0,0,-1));
if (!Tests.IsTesting) {
UI.HandleBegin("Model", ref modelPose, pbrModel.Bounds * .2f, allowedGestures: UIGesture.PinchGrip);
pbrModel.Draw(Matrix.TRS(Vec3.Zero, Quat.FromAngles(0, 180, 0), 0.2f));
pbrModel.Draw(selectionMat, Matrix.TRS(Vec3.Zero, Quat.FromAngles(0, 180, 0), 0.2f), new Color(1,1,1,1));
UI.HandleEnd();
}
for (int y = 0; y < materialGrid; y++) {
for (int x = 0; x < materialGrid; x++) {
Renderer.Add(sphereMesh, pbrMaterials[x+y*materialGrid], Matrix.TS(new Vec3(x-materialGrid/2.0f + 0.5f,y-materialGrid/2.0f + 0.5f,-1)/4.0f, 0.2f));
} }
Text.Add("Metallic -->", Matrix.TRS(new Vec3(0, materialGrid/8.0f+0.2f, -0.25f), Quat.FromAngles(0,180, 0 ), 4));
Text.Add("Roughness -->", Matrix.TRS(new Vec3(materialGrid/-8.0f-0.2f, 0, -0.25f), Quat.FromAngles(0,180,-90), 4));
Hierarchy.Pop();
Demo.ShowSummary(title, description, new Bounds(V.XYZ(0.1f, .2f, 0.65f), V.XYZ(2.0f, 2.0f, .2f)));
}
}