Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
108 lines (88 loc) · 3.35 KB

File metadata and controls

108 lines (88 loc) · 3.35 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
103
104
105
106
107
108
using System;
using System.Numerics;
using R3D_cs;
using Raylib_cs;
using static Raylib_cs.Raylib;
namespace Examples;
public static class Lights
{
private const int NUM_LIGHTS = 128;
private const int GRID_SIZE = 100;
private static float Randf(float min, float max)
{
return min + (max - min) * Random.Shared.NextSingle();
}
public static int Main()
{
// Initialize window
InitWindow(800, 450, "[r3d] - Many lights example");
SetTargetFPS(60);
// Initialize R3D
R3D.Init(GetScreenWidth(), GetScreenHeight());
// Set ambient light
R3D.SetEnvironmentEx((ref env) =>
{
env.Background.Color = Color.Black;
env.Ambient.Color = new Color(10, 10, 10, 255);
});
// Create plane and cube meshes
var plane = R3D.GenMeshPlane(GRID_SIZE, GRID_SIZE, 1, 1);
var cube = R3D.GenMeshCube(0.5f, 0.5f, 0.5f);
var material = R3D.GetDefaultMaterial();
// Allocate transforms for all spheres
var instances = R3D.LoadInstanceBuffer(GRID_SIZE * GRID_SIZE, InstanceFlags.Position);
var positions = R3D.MapInstances<Vector3>(instances, InstanceFlags.Position);
for (int x = -GRID_SIZE / 2; x < GRID_SIZE / 2; x++)
for (int z = -GRID_SIZE / 2; z < GRID_SIZE / 2; z++)
positions[(z + GRID_SIZE / 2) * GRID_SIZE + x + GRID_SIZE / 2] = new Vector3(x + 0.5f, 0, z + 0.5f);
R3D.UnmapInstances(instances, InstanceFlags.Position);
// Create lights
var lights = new Light[NUM_LIGHTS];
for (var i = 0; i < NUM_LIGHTS; i++)
{
lights[i] = R3D.CreateLight(LightType.Omni);
R3D.SetLightPosition(lights[i], new Vector3(Randf(-GRID_SIZE / 2f, GRID_SIZE / 2f), Randf(1.0f, 5.0f), Randf(-GRID_SIZE / 2f, GRID_SIZE / 2f)));
R3D.SetLightColor(lights[i], ColorFromHSV(Randf(0.0f, 360.0f), 1.0f, 1.0f));
R3D.SetLightRange(lights[i], Randf(8.0f, 16.0f));
R3D.SetLightActive(lights[i], true);
//R3D.EnableShadow(lights[i]);
}
// Setup camera
var camera = new Camera3D
{
Position = new Vector3(0, 10, 10),
Target = Vector3.Zero,
Up = new Vector3(0, 1, 0),
FovY = 60
};
// Main loop
while (!WindowShouldClose())
{
UpdateCamera(ref camera, CameraMode.Orbital);
BeginDrawing();
ClearBackground(Color.RayWhite);
// Draw scene
R3D.Begin(camera);
R3D.DrawMesh(plane, material, new Vector3(0, -0.25f, 0), 1.0f);
R3D.DrawMeshInstanced(cube, material, instances, GRID_SIZE*GRID_SIZE);
R3D.End();
// Optionally show lights shapes
if (IsKeyDown(KeyboardKey.F))
{
BeginMode3D(camera);
for (var i = 0; i < NUM_LIGHTS; i++) R3D.DrawLightShape(lights[i]);
EndMode3D();
}
DrawFPS(10, 10);
DrawText("Press 'F' to show the lights", 10, GetScreenHeight() - 34, 24, Color.Black);
EndDrawing();
}
// Cleanup
R3D.UnloadInstanceBuffer(instances);
R3D.UnloadMesh(cube);
R3D.UnloadMesh(plane);
R3D.Close();
CloseWindow();
return 0;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.