mirror of
https://git.coom.tech/drummyfish/small3dlib.git
synced 2024-12-22 01:26:17 +01:00
Add triangleID to PixelInfo
This commit is contained in:
parent
8c4649640f
commit
a7657c0951
4 changed files with 14 additions and 12 deletions
|
@ -75,12 +75,11 @@ void sampleTexture(uint8_t *texture, int32_t u, int32_t v, uint8_t *r, uint8_t *
|
|||
}
|
||||
|
||||
int16_t previousTriangle = -1;
|
||||
int16_t previousModel = -1;
|
||||
S3L_Unit uv0[2], uv1[2], uv2[2];
|
||||
|
||||
void drawPixel(S3L_PixelInfo *p)
|
||||
{
|
||||
if (p->triangleIndex != previousTriangle || p->modelIndex != previousModel)
|
||||
if (p->triangleID != previousTriangle)
|
||||
{
|
||||
S3L_Index *uvIndices;
|
||||
S3L_Unit *uvs;
|
||||
|
@ -119,8 +118,7 @@ void drawPixel(S3L_PixelInfo *p)
|
|||
uv2[0] = uvs[index];
|
||||
uv2[1] = uvs[index + 1];
|
||||
|
||||
previousTriangle = p->triangleIndex;
|
||||
previousModel = p->modelIndex;
|
||||
previousTriangle = p->triangleID;
|
||||
}
|
||||
|
||||
uint8_t r,g,b;
|
||||
|
|
|
@ -85,7 +85,6 @@ S3L_Model3D models[MODELS_TOTAL];
|
|||
S3L_Scene scene;
|
||||
|
||||
int previousTriangle = -1;
|
||||
int previousModel = -1;
|
||||
|
||||
S3L_Vec4 toLightDirection;
|
||||
|
||||
|
@ -169,7 +168,7 @@ void drawPixel(S3L_PixelInfo *p)
|
|||
normals = waterNormals; break;
|
||||
}
|
||||
|
||||
if (p->triangleIndex != previousTriangle || p->modelIndex != previousModel)
|
||||
if (p->triangleID != previousTriangle)
|
||||
{
|
||||
int index = scene.models[p->modelIndex].triangles[p->triangleIndex * 3] * 3;
|
||||
|
||||
|
@ -226,8 +225,7 @@ void drawPixel(S3L_PixelInfo *p)
|
|||
uv2[1] = treeUVs[index];
|
||||
}
|
||||
|
||||
previousTriangle = p->triangleIndex;
|
||||
previousModel = p->modelIndex;
|
||||
previousTriangle = p->triangleID;
|
||||
}
|
||||
|
||||
S3L_correctBarycentricCoords(p->barycentric);
|
||||
|
|
|
@ -158,7 +158,7 @@ S3L_Vec4 n0, n1, n2, nt;
|
|||
|
||||
void drawPixel(S3L_PixelInfo *p)
|
||||
{
|
||||
if (p->triangleIndex != previousTriangle)
|
||||
if (p->triangleID != previousTriangle)
|
||||
{
|
||||
int16_t index;
|
||||
|
||||
|
@ -253,7 +253,7 @@ void drawPixel(S3L_PixelInfo *p)
|
|||
l2 = 256 + S3L_clamp(S3L_dotProductVec3(n2,toLight),-511,511) / 2;
|
||||
}
|
||||
|
||||
previousTriangle = p->triangleIndex;
|
||||
previousTriangle = p->triangleID;
|
||||
}
|
||||
|
||||
if (wire)
|
||||
|
|
10
small3dlib.h
10
small3dlib.h
|
@ -472,8 +472,11 @@ typedef struct
|
|||
for the price of some performance). The sum of
|
||||
the three coordinates will always be exactly
|
||||
S3L_FRACTIONS_PER_UNIT. */
|
||||
S3L_Index triangleIndex; ///< Triangle index.
|
||||
S3L_Index modelIndex;
|
||||
S3L_Index modelIndex; ///< Model index within the scene.
|
||||
S3L_Index triangleIndex; ///< Triangle index within the model.
|
||||
uint32_t triangleID; /**< Unique ID of the triangle withing the whole
|
||||
scene. This can be used e.g. by a cache to
|
||||
quickly find out if a triangle has changed. */
|
||||
S3L_Unit depth; ///< Depth (only if depth is turned on).
|
||||
S3L_Unit previousZ; /**< Z-buffer value (not necessarily world depth in
|
||||
S3L_Units!) that was in the z-buffer on the
|
||||
|
@ -1444,7 +1447,9 @@ void S3L_initPixelInfo(S3L_PixelInfo *p) // TODO: maybe non-pointer for p
|
|||
p->barycentric[0] = S3L_FRACTIONS_PER_UNIT;
|
||||
p->barycentric[1] = 0;
|
||||
p->barycentric[2] = 0;
|
||||
p->modelIndex = 0;
|
||||
p->triangleIndex = 0;
|
||||
p->triangleID = 0;
|
||||
p->depth = 0;
|
||||
p->previousZ = 0;
|
||||
}
|
||||
|
@ -1631,6 +1636,7 @@ void S3L_drawTriangle(
|
|||
S3L_initPixelInfo(&p);
|
||||
p.modelIndex = modelIndex;
|
||||
p.triangleIndex = triangleIndex;
|
||||
p.triangleID = modelIndex << 16 | triangleIndex;
|
||||
|
||||
#if !S3L_STRICT_NEAR_CULLING
|
||||
point0.z = point0.z >= S3L_NEAR ? point0.z : S3L_NEAR;
|
||||
|
|
Loading…
Reference in a new issue