-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProbe.cs
More file actions
102 lines (80 loc) · 2.91 KB
/
Probe.cs
File metadata and controls
102 lines (80 loc) · 2.91 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
94
95
96
97
98
99
100
101
102
using System;
using System.Numerics;
using R3D_cs;
using Raylib_cs;
using static Raylib_cs.Raylib;
using CubemapLayout = R3D_cs.CubemapLayout;
namespace Examples;
public static class Probe
{
public static int Main()
{
// Initialize window
InitWindow(800, 450, "[r3d] - Probe example");
SetTargetFPS(60);
// Initialize R3D
R3D.Init(GetScreenWidth(), GetScreenHeight());
var cubemap = R3D.LoadCubemap("resources/panorama/indoor.hdr", CubemapLayout.AutoDetect);
var ambientMap = R3D.GenAmbientMap(cubemap, AmbientFlags.Illumination | AmbientFlags.Reflection);
R3D.SetEnvironmentEx((ref env) =>
{
// Setup environment sky
env.Background.SkyBlur = 0.3f;
env.Background.Sky = cubemap;
// Setup environment ambient
env.Ambient.Map = ambientMap;
env.Ambient.Energy = 0.2f;
// Setup tonemapping
env.Tonemap.Mode = Tonemap.Filmic;
});
// Create meshes
var plane = R3D.GenMeshPlane(30, 30, 1, 1);
var sphere = R3D.GenMeshSphere(0.5f, 64, 64);
var material = R3D.GetDefaultMaterial();
// Create light
var light = R3D.CreateLight(LightType.Spot);
R3D.LightLookAt(light, new Vector3(0, 10, 5), Vector3.Zero);
R3D.SetLightActive(light, true);
R3D.EnableShadow(light);
// Create probe
var probe = R3D.CreateProbe(ProbeFlags.Illumination | ProbeFlags.Reflection);
R3D.SetProbePosition(probe, new Vector3(0, 1, 0));
R3D.SetProbeShadows(probe, true);
R3D.SetProbeFalloff(probe, 0.5f);
R3D.SetProbeActive(probe, true);
// Setup camera
var camera = new Camera3D
{
Position = new Vector3(0, 3.0f, 6.0f),
Target = new Vector3(0, 0.5f, 0),
Up = new Vector3(0, 1, 0),
FovY = 60
};
// Main loop
while (!WindowShouldClose())
{
UpdateCamera(ref camera, CameraMode.Orbital);
BeginDrawing();
ClearBackground(Color.RayWhite);
R3D.Begin(camera);
material.Orm.Roughness = 0.5f;
material.Orm.Metalness = 0.0f;
R3D.DrawMesh(plane, material, Vector3.Zero, 1.0f);
for (int i = -1; i <= 1; i++) {
material.Orm.Roughness = MathF.Abs(i) * 0.4f;
material.Orm.Metalness = 1.0f - MathF.Abs(i);
R3D.DrawMesh(sphere, material, new Vector3(i * 3.0f, 1.0f, 0), 2.0f);
}
R3D.End();
EndDrawing();
}
// Cleanup
R3D.UnloadAmbientMap(ambientMap);
R3D.UnloadCubemap(cubemap);
R3D.UnloadMesh(sphere);
R3D.UnloadMesh(plane);
R3D.Close();
CloseWindow();
return 0;
}
}