Trying to make terrain work with ocean

This commit is contained in:
Carlos Sanchez 2024-09-19 20:27:49 -04:00
parent a009fd3749
commit 96cc0a246c
3 changed files with 37 additions and 25 deletions

@ -1 +1 @@
Subproject commit 2edcfd6d8340abdd26670f4ac5d911de6e65d7be
Subproject commit 19cfe45a34725ad0846c46c1e9e4cc3214ef46b7

1
maze.c
View File

@ -1024,6 +1024,7 @@ int main() { // int argc, char *argv[]) {
render.autolightfix = 1;
render.rendersettings.ditherclose = DITHERSTART;
render.rendersettings.ditherfar = DITHEREND;
// render.rendersettings.flags &= ~H3DR_PCT;
// render.rendersettings.flags &= ~(H3DR_LIGHTING);
render.rendersettings.pctminsize = 100;
eprintf("Initialized renderer\n");

View File

@ -26,27 +26,30 @@
#define DEFAULTLOOK \
{ .x = 0, .y = 0, .z = -1 }
// { .x = 1.0, .y = 1.0, .z = 1.0 }
#define CHUNKSIZE 8 // How big each chunk is (x and y, square)
// How big each chunk is (x and y, square). MUST BE POWER OF 2 - 1
#define CHUNKSIZE 7
#define CHUNKSCALE 1.0 / CHUNKSIZE
#define VIEWDISTANCE 10
#define PLBOXEDGE (VIEWDISTANCE * 2 + 1)
#define MAXCHUNKPERFRAME 1
// These are initial values but there may be ways to change it
#define INIT_CAMPITCH MPI_2 * 1.6 // 1.575
#define INIT_CAMPITCH MPI_2 // MPI_2 * 1.6 // 1.575
#define INIT_NEARCLIP 0.01
#define INIT_FARCLIP 100.0
#define INIT_FOV 90.0
#define INIT_DITHERSTART 100
#define INIT_DITHEREND 100
#define INIT_LIGHTPITCH -MPI / 4.0
#define INIT_LIGHTPITCH MPI_2 * 1.75
#define INIT_LIGHTYAW 0
#define INIT_MINLIGHT 0.2
#define INIT_MINLIGHT 0.3
#define INIT_PLAYERHEIGHT 1.5
#define INIT_PLAYERHEIGHT 0.5
#define INIT_PLAYERSPEED \
{ .x = 0, .y = 0, .z = -1.5 }
#define RANDF() ((float)rand() / RAND_MAX)
// Some globals you can mess around with potentially
int fps = 60;
@ -65,25 +68,30 @@ void fastface(haloo3d_facei face, uint16_t tex, uint16_t v0, uint16_t v1,
void gen_terrain(struct vec3i pos, haloo3d_obj *model) {
eprintf("Generating terrain at %d,%d\n", pos.x, pos.z);
// Don't allow the model to have more than some amount of faces/vertices.
haloo3d_obj_resetfixed(model, CHUNKSIZE * CHUNKSIZE * 4,
CHUNKSIZE * CHUNKSIZE * 4);
// TODO: You need to change this to be a large plane that follows the player
// so you can use lighting on the islands but not on the water
// haloo3d_gen_paletteuv(0xF26F, model->vtexture[model->numvtextures++].v);
struct vec3 seacol = haloo3d_gen_paletteuv(0xF000 | (rand() & 0xFFF));
int seauv = haloo3d_obj_addvtexture(model, seacol);
// clang-format off
// REMEMBER: NEGATIVE Z IS FORWARD
int tl = haloo3d_obj_addvertex(model, (struct vec4){.x = 0, .y = 0, .z = 0, .w = 1});
int tr = haloo3d_obj_addvertex(model, (struct vec4){.x = CHUNKSIZE / 1.1, .y = 0, .z = 0, .w = 1});
int bl = haloo3d_obj_addvertex(model, (struct vec4){.x = 0, .y = 0, .z = CHUNKSIZE / 1.1, .w = 1});
int br = haloo3d_obj_addvertex(model, (struct vec4){.x = CHUNKSIZE / 1.1, .y = 0, .z = CHUNKSIZE / 1.1, .w = 1});
// clang-format on
haloo3d_obj_resetfixed(model, (CHUNKSIZE + 1) * (CHUNKSIZE + 1) * 4,
(CHUNKSIZE + 1) * (CHUNKSIZE + 1) * 4);
struct vec3 landcol = haloo3d_gen_paletteuv(0xF2F0);
int landuv = haloo3d_obj_addvtexture(model, landcol);
for (int z = 0; z <= CHUNKSIZE; z++) {
for (int x = 0; x <= CHUNKSIZE; x++) {
haloo3d_obj_addvertex(
model, (struct vec4){.x = x, .y = 2 * RANDF() - 1, .z = -z});
}
}
for (int i = 0; i < (CHUNKSIZE + 1) * CHUNKSIZE; i++) {
if ((i & CHUNKSIZE) == CHUNKSIZE) {
continue;
}
uint16_t bl = i;
uint16_t br = i + 1;
uint16_t tl = i + CHUNKSIZE + 1;
uint16_t tr = i + CHUNKSIZE + 2;
haloo3d_facei face;
fastface(face, seauv, bl, br, tl);
fastface(face, landuv, bl, br, tl);
haloo3d_obj_addface(model, face);
fastface(face, seauv, br, tr, tl);
fastface(face, landuv, br, tr, tl);
haloo3d_obj_addface(model, face);
}
haloo3d_obj_shrinktofit(model);
}
@ -399,6 +407,8 @@ ecs_eid setup_sea(tecs *ecs, render_context *ctx, ecs_placement *playerpos,
haloo3d_obj_resetfixed(model, 2, 4);
struct vec3 seacol = haloo3d_gen_paletteuv(0xF26F);
int seauv = haloo3d_obj_addvtexture(model, seacol);
// struct vec3 seacol2 = haloo3d_gen_paletteuv(0xF008);
// haloo3d_obj_addvtexture(model, seacol2);
// clang-format off
// REMEMBER: NEGATIVE Z IS FORWARD
int tl = haloo3d_obj_addvertex(model, (struct vec4){.x = -1, .y = 0, .z = -1, .w = 1});
@ -409,6 +419,7 @@ ecs_eid setup_sea(tecs *ecs, render_context *ctx, ecs_placement *playerpos,
haloo3d_facei face;
fastface(face, seauv, bl, br, tl);
haloo3d_obj_addface(model, face);
// model->faces[0][0].texi++;
fastface(face, seauv, br, tr, tl);
haloo3d_obj_addface(model, face);
ECS_SETCOMPONENT(ecs, seaid, ecs_object){