Browse Source

Implemented rudimentary baked lighting through vertex colors and gouraud shading.

tess_experiment
Nico de Poel 3 years ago
parent
commit
08008af2a0
  1. BIN
      test.ps1bsp
  2. 22
      world.c

BIN
test.ps1bsp

22
world.c

@ -58,14 +58,20 @@ void world_draw(const world_t *world)
unsigned short *faceVertIndex = &world->faceVertIndices[face->firstVertexIndex];
for (int vertIdx = 0; vertIdx < face->numVertices; ++vertIdx, ++faceVertIndex)
{
vecs[vertIdx] = *((SVECTOR*)&world->vertices[*faceVertIndex]);
const ps1bsp_vertex_t *vert = &world->vertices[*faceVertIndex];
vecs[vertIdx] = *((SVECTOR*)vert);
vecs[vertIdx].pad = vert->baseLight;
}
// Draw the face as a triangle fan
for (int vertIdx = 1; vertIdx < face->numVertices - 1; ++vertIdx)
{
const SVECTOR *v0 = &vecs[0];
const SVECTOR *v1 = &vecs[vertIdx];
const SVECTOR *v2 = &vecs[vertIdx + 1];
// Naively draw the triangle with GTE, nothing special or optimized about this
gte_ldv3(&vecs[0], &vecs[vertIdx], &vecs[vertIdx + 1]);
gte_ldv3(v0, v1, v2);
gte_rtpt(); // Rotation, translation, perspective projection
// Normal clipping for backface culling
@ -82,17 +88,17 @@ void world_draw(const world_t *world)
continue;
// Draw a flat-shaded untextured colored triangle
POLY_F3 *poly = (POLY_F3*)mem_prim(sizeof(POLY_F3));
POLY_G3 *poly = (POLY_G3*)mem_prim(sizeof(POLY_G3));
if (poly == NULL)
break;
setPolyF3(poly);
setPolyG3(poly);
gte_stsxy3_f3(poly);
gte_stsxy3_g3(poly);
poly->r0 = col->r;
poly->g0 = col->g;
poly->b0 = col->b;
poly->r0 = poly->g0 = poly->b0 = (uint8_t)v0->pad;
poly->r1 = poly->g1 = poly->b1 = (uint8_t)v1->pad;
poly->r2 = poly->g2 = poly->b2 = (uint8_t)v2->pad;
addPrim(curOT + depth, poly);
}

Loading…
Cancel
Save