Clear water

This commit is contained in:
Carlos Sanchez 2024-09-19 22:33:53 -04:00
parent 300bdb3e31
commit ccc017c647
3 changed files with 36 additions and 25 deletions

@ -1 +1 @@
Subproject commit 19cfe45a34725ad0846c46c1e9e4cc3214ef46b7
Subproject commit 46a3dd12d7f3f7d2a204fe4c5efa3cb5336bb187

View File

@ -36,25 +36,26 @@
#define INIT_NEARCLIP 0.01
#define INIT_FARCLIP 100.0
#define MAXCHUNKPERFRAME 1
#define MAXCHUNKPERFRAME 5
// Generation consts / things for looks
#define LANDCOL 0xF4E1
#define SEACOL 0xF26C
#define LANDCOL 0xF6D2 // 0xF4E1
#define SEACOL 0xF28D // 0xF26C
#define LANDHEIGHT 4.0
#define SKYCOL 0xF77F
#define SKYCOL 0xF97F // 0xF77F
#define SEATRANS 0.75
#define INIT_LIGHTPITCH MPI_2 * 1.65
#define INIT_LIGHTYAW MPI_2 * 0.65
#define INIT_MINLIGHT 0.2
#define INIT_DITHERSTART 3
#define INIT_DITHEREND 10
#define INIT_DITHERSTART 3.5
#define INIT_DITHEREND VIEWDISTANCE - 0.5
// Player things
#define INIT_FOV 90.0
#define INIT_CAMPITCH MPI_2 * 1.2 // MPI_2 * 1.6 // 1.575
#define INIT_CAMPITCH MPI_2 * 1.3 // MPI_2 * 1.6 // 1.575
#define INIT_PLAYERHEIGHT 0.65
#define INIT_PLAYERSPEED \
{ .x = 0, .y = 0, .z = -9.5 }
{ .x = 0, .y = 0, .z = -4.5 }
#define RANDF() ((float)rand() / RAND_MAX)
@ -136,6 +137,7 @@ void gen_chunk(render_context *ctx, tecs *ecs, struct vec3i pos) {
// TODO: an easy place for optimization (if it's even needed)
// eprintf("TEX: %p\n", haloo3d_easystore_gettex(&ecs->storage, PALETTEKEY));
ECS_SETCOMPONENT(ecs, id, ecs_object){
.flatdither = 0,
.texture = haloo3d_easystore_gettex(&ecs->storage, PALETTEKEY),
.scale = {.x = CHUNKSCALE, .y = CHUNKSCALE * LANDHEIGHT, .z = CHUNKSCALE},
.lighting = &ecs->chunklight,
@ -257,9 +259,16 @@ void sys_renderobject(ecs_placement *p, ecs_object *o, tecs **ecs) {
// Apply scale such that it looks like it was applied first (this prevents
// scaling applying skew to a rotated object)
haloo3d_mat4_prescalev(modelm, o->scale.v);
haloo3d_trirender rsettings;
// We might be rendering into multiple contexts in a multiplayer game (or
// just different angles or something)
for (int ctx = 0; ctx < o->contextcount; ctx++) {
memcpy(&rsettings, &o->context[ctx]->rendersettings,
sizeof(haloo3d_trirender));
rsettings.texture = o->texture;
if (o->flatdither > 0) {
rsettings.ditherflat = o->flatdither;
}
mat4_multiply(finalmatrix, o->context[ctx]->precalc_screen, modelm);
haloo3d_precalc_verts(o->model, finalmatrix, precalc_verts);
// --**-- Next, setup some rendering invariants --**--
@ -267,7 +276,6 @@ void sys_renderobject(ecs_placement *p, ecs_object *o, tecs **ecs) {
// The compiler is complaining about lighting being used unitialized, even
// though it's not. Just shut it up
vec3(lighting.v, 0, 0, 0);
o->context[ctx]->rendersettings.texture = o->texture;
if (o->lighting) {
if (o->lighting->autolightfix) {
// Lighting doesn't rotate with the model unless you do it yourself.
@ -279,16 +287,15 @@ void sys_renderobject(ecs_placement *p, ecs_object *o, tecs **ecs) {
// same rotation matrix used on the model
haloo3d_my_lookat(modelm, ltmp.v, p->lookvec.v, p->up.v);
// We actually want the inverse. Apparently to speed things up, the
// transpose works for rotation matrices(?) but I don't trust that this
// lookat does that
// mat4_inverse(modelm, modelm);
// transpose works for rotation matrices(?) but I don't trust that
// this lookat does that mat4_inverse(modelm, modelm);
mat4_transpose(modelm, modelm);
// We HAVE to have a vec4 (oof)
vec4(ltmp.v, o->lighting->dir.x, o->lighting->dir.y, o->lighting->dir.z,
1);
haloo3d_vec4_multmat_into(&ltmp, modelm, &lout);
// No need to fix W, should all be good (no perspective divide). But we
// DO need to pull out that result
// No need to fix W, should all be good (no perspective divide). But
// we DO need to pull out that result
vec3(lighting.v, lout.x, lout.y, lout.z);
vec3_normalize(lighting.v, lighting.v);
} else {
@ -304,15 +311,16 @@ void sys_renderobject(ecs_placement *p, ecs_object *o, tecs **ecs) {
o->model->vtexture, face);
int tris = haloo3d_facef_clip(face, outfaces);
if (tris > 0) {
uint8_t oflags = o->context[ctx]->rendersettings.flags;
uint8_t oflags = rsettings.flags;
if (o->lighting) {
haloo3d_obj_facef(o->model, o->model->faces[facei], baseface);
o->context[ctx]->rendersettings.intensity =
rsettings.intensity =
haloo3d_calc_light(lighting.v, o->lighting->minlight, baseface);
} else {
o->context[ctx]->rendersettings.intensity = H3DVF(1.0);
rsettings.intensity = H3DVF(1.0);
}
// if ((r->_objstate[object - r->objects] & H3D_EASYOBJSTATE_NOTRANS)) {
// if ((r->_objstate[object - r->objects] & H3D_EASYOBJSTATE_NOTRANS))
// {
// r->rendersettings.flags &= ~H3DR_TRANSPARENCY;
// }
for (int ti = 0; ti < tris; ti++) {
@ -325,10 +333,9 @@ void sys_renderobject(ecs_placement *p, ecs_object *o, tecs **ecs) {
haloo3d_facef_viewport_into_fast(outfaces[ti],
o->context[ctx]->precalc_halfwidth,
o->context[ctx]->precalc_halfheight);
haloo3d_triangle(&o->context[ctx]->window,
&o->context[ctx]->rendersettings, outfaces[ti]);
haloo3d_triangle(&o->context[ctx]->window, &rsettings, outfaces[ti]);
}
o->context[ctx]->rendersettings.flags = oflags;
rsettings.flags = oflags;
}
}
}
@ -443,10 +450,11 @@ ecs_eid setup_sea(tecs *ecs, render_context *ctx, ecs_placement *playerpos,
fastface(face, seauv, br, tr, tl);
haloo3d_obj_addface(model, face);
ECS_SETCOMPONENT(ecs, seaid, ecs_object){
.flatdither = SEATRANS,
.texture = haloo3d_easystore_gettex(&ecs->storage, PALETTEKEY),
.scale = {.x = VIEWDISTANCE * 0.5,
.y = VIEWDISTANCE * 0.5,
.z = VIEWDISTANCE * 0.5},
.scale = {.x = VIEWDISTANCE * 1.5,
.y = VIEWDISTANCE * 1.5,
.z = VIEWDISTANCE * 1.5},
.lighting = NULL,
.model = model,
.cullbackface = 1,
@ -493,6 +501,8 @@ int main() { // int argc, char **argv) {
context.farclip = INIT_FARCLIP;
context.fov = INIT_FOV;
haloo3d_trirender_init(&context.rendersettings);
// context.rendersettings.flags &= ~H3DR_DITHERPIX;
// context.rendersettings.flags |= H3DR_DITHERTRI;
context.rendersettings.ditherclose = INIT_DITHERSTART;
context.rendersettings.ditherfar = INIT_DITHEREND;
haloo3d_fb_init(&context.window, WIDTH, HEIGHT);

View File

@ -53,6 +53,7 @@ typedef struct {
haloo3d_fb *texture;
uint8_t cullbackface; // Whether to cull backfaces (you probably should)
uint8_t contextcount; // How many contexts we render into
float flatdither; // A flat dither amount. Set to -1 to disable
} ecs_object;
// Some placement within the world. Doesn't imply anything other than a