Update shaders_mesh_instancing.c
This commit is contained in:
parent
03815ec4fe
commit
8a55c60e47
1 changed files with 9 additions and 8 deletions
|
@ -27,6 +27,8 @@
|
||||||
#define GLSL_VERSION 100
|
#define GLSL_VERSION 100
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define MAX_INSTANCES 10000
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Program main entry point
|
// Program main entry point
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
|
@ -56,15 +58,14 @@ int main(void)
|
||||||
camera.fovy = 45.0f;
|
camera.fovy = 45.0f;
|
||||||
camera.projection = CAMERA_PERSPECTIVE;
|
camera.projection = CAMERA_PERSPECTIVE;
|
||||||
|
|
||||||
const int instances = 10000; // Number of instances to display
|
|
||||||
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
|
Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
|
||||||
|
|
||||||
Matrix *rotations = RL_MALLOC(instances*sizeof(Matrix)); // Rotation state of instances
|
Matrix *rotations = RL_MALLOC(MAX_INSTANCES*sizeof(Matrix)); // Rotation state of instances
|
||||||
Matrix *rotationsInc = RL_MALLOC(instances*sizeof(Matrix)); // Per-frame rotation animation of instances
|
Matrix *rotationsInc = RL_MALLOC(MAX_INSTANCES*sizeof(Matrix)); // Per-frame rotation animation of instances
|
||||||
Matrix *translations = RL_MALLOC(instances*sizeof(Matrix)); // Locations of instances
|
Matrix *translations = RL_MALLOC(MAX_INSTANCES*sizeof(Matrix)); // Locations of instances
|
||||||
|
|
||||||
// Scatter random cubes around
|
// Scatter random cubes around
|
||||||
for (int i = 0; i < instances; i++)
|
for (int i = 0; i < MAX_INSTANCES; i++)
|
||||||
{
|
{
|
||||||
x = GetRandomValue(-50, 50);
|
x = GetRandomValue(-50, 50);
|
||||||
y = GetRandomValue(-50, 50);
|
y = GetRandomValue(-50, 50);
|
||||||
|
@ -81,7 +82,7 @@ int main(void)
|
||||||
rotations[i] = MatrixIdentity();
|
rotations[i] = MatrixIdentity();
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix *transforms = RL_MALLOC(instances*sizeof(Matrix)); // Pre-multiplied transformations passed to rlgl
|
Matrix *transforms = RL_MALLOC(MAX_INSTANCES*sizeof(Matrix)); // Pre-multiplied transformations passed to rlgl
|
||||||
|
|
||||||
Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/base_lighting_instanced.vs", GLSL_VERSION),
|
Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/base_lighting_instanced.vs", GLSL_VERSION),
|
||||||
TextFormat("resources/shaders/glsl%i/lighting.fs", GLSL_VERSION));
|
TextFormat("resources/shaders/glsl%i/lighting.fs", GLSL_VERSION));
|
||||||
|
@ -146,7 +147,7 @@ int main(void)
|
||||||
SetShaderValue(shader, shader.locs[SHADER_LOC_VECTOR_VIEW], cameraPos, SHADER_UNIFORM_VEC3);
|
SetShaderValue(shader, shader.locs[SHADER_LOC_VECTOR_VIEW], cameraPos, SHADER_UNIFORM_VEC3);
|
||||||
|
|
||||||
// Apply per-instance transformations
|
// Apply per-instance transformations
|
||||||
for (int i = 0; i < instances; i++)
|
for (int i = 0; i < MAX_INSTANCES; i++)
|
||||||
{
|
{
|
||||||
rotations[i] = MatrixMultiply(rotations[i], rotationsInc[i]);
|
rotations[i] = MatrixMultiply(rotations[i], rotationsInc[i]);
|
||||||
transforms[i] = MatrixMultiply(rotations[i], translations[i]);
|
transforms[i] = MatrixMultiply(rotations[i], translations[i]);
|
||||||
|
@ -174,7 +175,7 @@ int main(void)
|
||||||
|
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
//DrawMesh(cube, material, MatrixIdentity());
|
//DrawMesh(cube, material, MatrixIdentity());
|
||||||
DrawMeshInstanced(cube, material, transforms, instances);
|
DrawMeshInstanced(cube, material, transforms, MAX_INSTANCES);
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
DrawText("A CUBE OF DANCING CUBES!", 490, 10, 20, MAROON);
|
DrawText("A CUBE OF DANCING CUBES!", 490, 10, 20, MAROON);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue