Colored terrain 1
This commit is contained in:
parent
7b03cd0aa6
commit
51addcae02
73
terrain.c
73
terrain.c
@ -67,8 +67,11 @@
|
|||||||
#define MAXCHUNKPERFRAME PLBOXEDGE
|
#define MAXCHUNKPERFRAME PLBOXEDGE
|
||||||
|
|
||||||
// Generation consts / things for looks
|
// Generation consts / things for looks
|
||||||
|
#define COLOREDTERRAIN // Some cost, not much
|
||||||
#define LANDHEIGHT 4.0
|
#define LANDHEIGHT 4.0
|
||||||
#define LANDCOL 0xF6D2 // 0xF4E1
|
#define LANDCOL 0xF6D2 // 0xF4E1
|
||||||
|
#define FLANDCOL 0xF260 // 0xF3A0 // 0xF4E1
|
||||||
|
#define UWLANDCOL 0xF026
|
||||||
#define SEACOL 0xF28D // 0xF26C
|
#define SEACOL 0xF28D // 0xF26C
|
||||||
#define SKYCOL 0xFA7F // 0xF77F
|
#define SKYCOL 0xFA7F // 0xF77F
|
||||||
#define CLOUDCOL 0xFFFF
|
#define CLOUDCOL 0xFFFF
|
||||||
@ -210,8 +213,16 @@ uint16_t gen_terrain(struct vec3i pos, haloo3d_obj *model, tecs *ecs,
|
|||||||
flowers[1] = haloo3d_easystore_getobj(storage, YELLOWFLOWERKEY);
|
flowers[1] = haloo3d_easystore_getobj(storage, YELLOWFLOWERKEY);
|
||||||
// Don't allow the model to have more than some amount of faces/vertices.
|
// Don't allow the model to have more than some amount of faces/vertices.
|
||||||
haloo3d_obj_resetfixed(model, H3D_OBJ_MAXFACES, H3D_OBJ_MAXVERTICES);
|
haloo3d_obj_resetfixed(model, H3D_OBJ_MAXFACES, H3D_OBJ_MAXVERTICES);
|
||||||
struct vec3 landcol = haloo3d_gen_paletteuv(LANDCOL); // 0xF2C0);
|
#define LCOLSTEP 8
|
||||||
int landuv = haloo3d_obj_addvtexture(model, landcol);
|
uint16_t landcols[(LCOLSTEP + 1) * 2];
|
||||||
|
for (int i = 0; i <= LCOLSTEP; i++) {
|
||||||
|
landcols[i] =
|
||||||
|
COMCOL(model, haloo3d_col_lerp(LANDCOL, FLANDCOL,
|
||||||
|
(float)i / LCOLSTEP)); // 0xF2C0);
|
||||||
|
landcols[i + LCOLSTEP + 1] =
|
||||||
|
COMCOL(model, haloo3d_col_lerp(LANDCOL, UWLANDCOL,
|
||||||
|
(float)i / LCOLSTEP)); // 0xF2C0);
|
||||||
|
}
|
||||||
fnl_state ns = fnlCreateState();
|
fnl_state ns = fnlCreateState();
|
||||||
ns.noise_type = FNL_NOISE_OPENSIMPLEX2;
|
ns.noise_type = FNL_NOISE_OPENSIMPLEX2;
|
||||||
ns.seed = gen_terrain_seed;
|
ns.seed = gen_terrain_seed;
|
||||||
@ -222,8 +233,8 @@ uint16_t gen_terrain(struct vec3i pos, haloo3d_obj *model, tecs *ecs,
|
|||||||
for (int z = 0; z < CHUNKVSIZE; z++) {
|
for (int z = 0; z < CHUNKVSIZE; z++) {
|
||||||
for (int x = 0; x < CHUNKVSIZE; x++) {
|
for (int x = 0; x < CHUNKVSIZE; x++) {
|
||||||
// clang-format off
|
// clang-format off
|
||||||
haloo3d_obj_addvertex(model,
|
haloo3d_obj_addvertex(model, (struct vec4){
|
||||||
(struct vec4){.x = x, .y = fnlGetNoise2D(&ns, noisex + x, noisey + z), .z = -z, .w = 1 });
|
.x = x, .y = fnlGetNoise2D(&ns, noisex + x, noisey + z), .z = -z, .w = 1 });
|
||||||
// clang-format on
|
// clang-format on
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -240,28 +251,64 @@ uint16_t gen_terrain(struct vec3i pos, haloo3d_obj *model, tecs *ecs,
|
|||||||
if ((i & CHUNKSIZE) == CHUNKSIZE) {
|
if ((i & CHUNKSIZE) == CHUNKSIZE) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// Change frequency for subthings
|
||||||
|
// ns.seed = 0;
|
||||||
|
ns.frequency = 0.01; // 0.02;
|
||||||
|
ns.fractal_type = FNL_FRACTAL_NONE;
|
||||||
uint16_t bl = i;
|
uint16_t bl = i;
|
||||||
uint16_t br = i + 1;
|
uint16_t br = i + 1;
|
||||||
uint16_t tl = i + CHUNKVSIZE;
|
uint16_t tl = i + CHUNKVSIZE;
|
||||||
uint16_t tr = i + CHUNKVSIZE + 1;
|
uint16_t tr = i + CHUNKVSIZE + 1;
|
||||||
faces[0] = fastface2(model, landuv, bl, br, tl);
|
// float lowy = MIN(model->vertices[bl].y, model->vertices[br].y);
|
||||||
faces[1] = fastface2(model, landuv, br, tr, tl);
|
// lowy = MIN(lowy, model->vertices[tl].y);
|
||||||
float lowy = 999;
|
// lowy = MIN(lowy, model->vertices[tr].y);
|
||||||
|
// float highy = MAX(model->vertices[bl].y, model->vertices[br].y);
|
||||||
|
// highy = MAX(highy, model->vertices[tl].y);
|
||||||
|
// highy = MAX(highy, model->vertices[tr].y);
|
||||||
|
// float nlayer = fnlGetNoise2D(&ns, noisex + model->vertices[bl].x,
|
||||||
|
// noisey + model->vertices[bl].z);
|
||||||
|
// // int landcol = nlayer > 0.0 ? 4 * fabs(lowy) : 0;
|
||||||
|
// int landcol;
|
||||||
|
// if (highy < 0) {
|
||||||
|
// landcol = LCOLSTEP + 1 + LCOLSTEP * fabs(highy);
|
||||||
|
// } else {
|
||||||
|
// landcol = LCOLSTEP * fabs(lowy) * (1 + nlayer) * 0.5;
|
||||||
|
// }
|
||||||
|
faces[0] = fastface2(model, landcols[0], bl, br, tl);
|
||||||
|
faces[1] = fastface2(model, landcols[0], br, tr, tl);
|
||||||
|
float lowys[2];
|
||||||
|
float highys[2];
|
||||||
for (int t = 0; t < 2; t++) {
|
for (int t = 0; t < 2; t++) {
|
||||||
|
lowys[t] = 999;
|
||||||
|
highys[t] = -999;
|
||||||
for (int v = 0; v < 3; v++) {
|
for (int v = 0; v < 3; v++) {
|
||||||
int ofs = t * 3;
|
int ofs = t * 3;
|
||||||
// NOTE: WE SWTICH Y AND Z TO MAKE THE EDGE FUNCTION WORK
|
// NOTE: WE SWTICH Y AND Z TO MAKE THE EDGE FUNCTION WORK
|
||||||
triedge[ofs + v].x = model->vertices[model->faces[faces[t]][v].posi].x;
|
triedge[ofs + v].x = model->vertices[model->faces[faces[t]][v].posi].x;
|
||||||
triedge[ofs + v].y = model->vertices[model->faces[faces[t]][v].posi].z;
|
triedge[ofs + v].y = model->vertices[model->faces[faces[t]][v].posi].z;
|
||||||
heights[ofs + v] = model->vertices[model->faces[faces[t]][v].posi].y;
|
heights[ofs + v] = model->vertices[model->faces[faces[t]][v].posi].y;
|
||||||
if (heights[ofs + v] < lowy)
|
if (heights[ofs + v] < lowys[t])
|
||||||
lowy = heights[ofs + v];
|
lowys[t] = heights[ofs + v];
|
||||||
|
if (heights[ofs + v] > highys[t])
|
||||||
|
highys[t] = heights[ofs + v];
|
||||||
}
|
}
|
||||||
|
#ifdef COLOREDTERRAIN
|
||||||
|
uint16_t tfvi = model->faces[faces[t]][0].posi;
|
||||||
|
float nlayer = fnlGetNoise2D(&ns, noisex + model->vertices[tfvi].x,
|
||||||
|
noisey + model->vertices[tfvi].z);
|
||||||
|
// int landcol = nlayer > 0.0 ? 4 * fabs(lowy) : 0;
|
||||||
|
int landcol;
|
||||||
|
if (highys[t] < 0) {
|
||||||
|
landcol = LCOLSTEP + 1 + LCOLSTEP * fabs(highys[t]);
|
||||||
|
} else {
|
||||||
|
landcol = LCOLSTEP * fabs(lowys[t]) * (1 + nlayer) * 0.5;
|
||||||
}
|
}
|
||||||
// Change frequency for subthings
|
for (int v = 0; v < 3; v++) {
|
||||||
// ns.seed = 0;
|
model->faces[faces[t]][v].texi = landcols[landcol];
|
||||||
ns.frequency = 0.02;
|
}
|
||||||
ns.fractal_type = FNL_FRACTAL_NONE;
|
#endif
|
||||||
|
}
|
||||||
|
float lowy = MIN(lowys[0], lowys[1]);
|
||||||
int treecount = 0;
|
int treecount = 0;
|
||||||
for (int t = 0; t < MAXTREEPERCELL; t++) {
|
for (int t = 0; t < MAXTREEPERCELL; t++) {
|
||||||
// We know that the first vec in the first triangle is bl, which is our
|
// We know that the first vec in the first triangle is bl, which is our
|
||||||
|
Loading…
Reference in New Issue
Block a user