mirror of
https://git.coom.tech/drummyfish/small3dlib.git
synced 2024-11-23 20:59:58 +01:00
Use helper function in demos
This commit is contained in:
parent
c3ac9e96f7
commit
6f9e90dd60
4 changed files with 23 additions and 98 deletions
|
@ -111,7 +111,7 @@ void sampleTexture(uint8_t *texture, int32_t u, int32_t v, uint8_t *r, uint8_t *
|
|||
}
|
||||
|
||||
uint32_t previousTriangle = -1;
|
||||
S3L_Unit uv0[2], uv1[2], uv2[2];
|
||||
S3L_Vec4 uv0, uv1, uv2;
|
||||
|
||||
void drawPixel(S3L_PixelInfo *p)
|
||||
{
|
||||
|
@ -131,28 +131,7 @@ void drawPixel(S3L_PixelInfo *p)
|
|||
uvs = carUVs;
|
||||
}
|
||||
|
||||
int16_t index;
|
||||
|
||||
index = p->triangleIndex * 3;
|
||||
|
||||
int16_t i0 = uvIndices[index];
|
||||
int16_t i1 = uvIndices[index + 1];
|
||||
int16_t i2 = uvIndices[index + 2];
|
||||
|
||||
index = i0 * 2;
|
||||
|
||||
uv0[0] = uvs[index];
|
||||
uv0[1] = uvs[index + 1];
|
||||
|
||||
index = i1 * 2;
|
||||
|
||||
uv1[0] = uvs[index];
|
||||
uv1[1] = uvs[index + 1];
|
||||
|
||||
index = i2 * 2;
|
||||
|
||||
uv2[0] = uvs[index];
|
||||
uv2[1] = uvs[index + 1];
|
||||
S3L_getIndexedTriangleValues(p->triangleIndex,uvIndices,uvs,2,&uv0,&uv1,&uv2);
|
||||
|
||||
previousTriangle = p->triangleID;
|
||||
}
|
||||
|
@ -161,8 +140,8 @@ void drawPixel(S3L_PixelInfo *p)
|
|||
|
||||
S3L_Unit uv[2];
|
||||
|
||||
uv[0] = S3L_interpolateBarycentric(uv0[0],uv1[0],uv2[0],p->barycentric);
|
||||
uv[1] = S3L_interpolateBarycentric(uv0[1],uv1[1],uv2[1],p->barycentric);
|
||||
uv[0] = S3L_interpolateBarycentric(uv0.x,uv1.x,uv2.x,p->barycentric);
|
||||
uv[1] = S3L_interpolateBarycentric(uv0.y,uv1.y,uv2.y,p->barycentric);
|
||||
|
||||
sampleTexture(cityTexture,uv[0] / 2,uv[1] / 2,&r,&g,&b);
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ S3L_Vec4 toLightDirection;
|
|||
|
||||
S3L_Vec4 n0, n1, n2, v0, v1, v2;
|
||||
|
||||
S3L_Unit uv0[2], uv1[2], uv2[2];
|
||||
S3L_Vec4 uv0, uv1, uv2;
|
||||
|
||||
void sampleTexture(uint8_t *texture, int w, int h, float x, float y, uint8_t color[3])
|
||||
{
|
||||
|
@ -170,59 +170,25 @@ void drawPixel(S3L_PixelInfo *p)
|
|||
|
||||
if (p->triangleID != previousTriangle)
|
||||
{
|
||||
int index = scene.models[p->modelIndex].triangles[p->triangleIndex * 3] * 3;
|
||||
|
||||
n0.x = normals[index];
|
||||
v0.x = scene.models[p->modelIndex].vertices[index];
|
||||
index++;
|
||||
n0.y = normals[index];
|
||||
v0.y = scene.models[p->modelIndex].vertices[index];
|
||||
index++;
|
||||
n0.z = normals[index];
|
||||
v0.z = scene.models[p->modelIndex].vertices[index];
|
||||
S3L_getIndexedTriangleValues(
|
||||
p->triangleIndex,
|
||||
scene.models[p->modelIndex].triangles,
|
||||
normals,3,&n0,&n1,&n2);
|
||||
|
||||
index = scene.models[p->modelIndex].triangles[p->triangleIndex * 3 + 1] * 3;
|
||||
|
||||
n1.x = normals[index];
|
||||
v1.x = scene.models[p->modelIndex].vertices[index];
|
||||
index++;
|
||||
n1.y = normals[index];
|
||||
v1.y = scene.models[p->modelIndex].vertices[index];
|
||||
index++;
|
||||
n1.z = normals[index];
|
||||
v1.z = scene.models[p->modelIndex].vertices[index];
|
||||
|
||||
index = scene.models[p->modelIndex].triangles[p->triangleIndex * 3 + 2] * 3;
|
||||
|
||||
n2.x = normals[index];
|
||||
v2.x = scene.models[p->modelIndex].vertices[index];
|
||||
index++;
|
||||
n2.y = normals[index];
|
||||
v2.y = scene.models[p->modelIndex].vertices[index];
|
||||
index++;
|
||||
n2.z = normals[index];
|
||||
v2.z = scene.models[p->modelIndex].vertices[index];
|
||||
S3L_getIndexedTriangleValues(
|
||||
p->triangleIndex,
|
||||
scene.models[p->modelIndex].triangles,
|
||||
scene.models[p->modelIndex].vertices,3,&v0,&v1,&v2);
|
||||
|
||||
if (p->modelIndex != WATER_MODEL_INDEX &&
|
||||
p->modelIndex != ISLAND_MODEL_INDEX)
|
||||
{
|
||||
index = treeUVIndices[p->triangleIndex * 3] * 2;
|
||||
|
||||
uv0[0] = treeUVs[index];
|
||||
index++;
|
||||
uv0[1] = treeUVs[index];
|
||||
|
||||
index = treeUVIndices[p->triangleIndex * 3 + 1] * 2;
|
||||
|
||||
uv1[0] = treeUVs[index];
|
||||
index++;
|
||||
uv1[1] = treeUVs[index];
|
||||
|
||||
index = treeUVIndices[p->triangleIndex * 3 + 2] * 2;
|
||||
|
||||
uv2[0] = treeUVs[index];
|
||||
index++;
|
||||
uv2[1] = treeUVs[index];
|
||||
S3L_getIndexedTriangleValues(
|
||||
p->triangleIndex,
|
||||
scene.models[p->modelIndex].triangles,
|
||||
treeUVs,2,&uv0,&uv1,&uv2);
|
||||
}
|
||||
|
||||
previousTriangle = p->triangleID;
|
||||
|
@ -297,8 +263,8 @@ void drawPixel(S3L_PixelInfo *p)
|
|||
specularIntensity = 0.2;
|
||||
specularPower = 20.0;
|
||||
|
||||
u = S3L_interpolateBarycentric(uv0[0],uv1[0],uv2[0],p->barycentric) / ((float) S3L_FRACTIONS_PER_UNIT);
|
||||
v = S3L_interpolateBarycentric(uv0[1],uv1[1],uv2[1],p->barycentric) / ((float) S3L_FRACTIONS_PER_UNIT);
|
||||
u = S3L_interpolateBarycentric(uv0.x,uv1.x,uv2.x,p->barycentric) / ((float) S3L_FRACTIONS_PER_UNIT);
|
||||
v = S3L_interpolateBarycentric(uv0.y,uv1.y,uv2.y,p->barycentric) / ((float) S3L_FRACTIONS_PER_UNIT);
|
||||
}
|
||||
|
||||
S3L_normalizeVec3(&normal);
|
||||
|
|
|
@ -103,29 +103,7 @@ void drawPixel(S3L_PixelInfo *p)
|
|||
texture = level3Texture;
|
||||
}
|
||||
|
||||
int16_t index;
|
||||
|
||||
index = p->triangleIndex * 3;
|
||||
|
||||
int16_t i0 = uvIndices[index];
|
||||
int16_t i1 = uvIndices[index + 1];
|
||||
int16_t i2 = uvIndices[index + 2];
|
||||
|
||||
index = i0 * 2;
|
||||
|
||||
uv0.x = uvs[index];
|
||||
uv0.y = uvs[index + 1];
|
||||
|
||||
index = i1 * 2;
|
||||
|
||||
uv1.x = uvs[index];
|
||||
uv1.y = uvs[index + 1];
|
||||
|
||||
index = i2 * 2;
|
||||
|
||||
uv2.x = uvs[index];
|
||||
uv2.y = uvs[index + 1];
|
||||
|
||||
S3L_getIndexedTriangleValues(p->triangleIndex,uvIndices,uvs,2,&uv0,&uv1,&uv2);
|
||||
previousTriangle = p->triangleID;
|
||||
}
|
||||
|
||||
|
|
|
@ -521,7 +521,9 @@ void S3L_triangleNormal(S3L_Vec4 t0, S3L_Vec4 t1, S3L_Vec4 t2,
|
|||
for each triangle, each index pointing into 'values' array, which contains
|
||||
the values, each one consisting of 'numComponents' components (e.g. 2 for
|
||||
UV coordinates). The three values are retrieved into 'v0', 'v1' and 'v2'
|
||||
vectors (into x, y, z and w, depending on 'numComponents'). */
|
||||
vectors (into x, y, z and w, depending on 'numComponents'). This function is
|
||||
meant to be used per-triangle (typically from a cache), NOT per-pixel, as it
|
||||
is not as fast as possible! */
|
||||
|
||||
void S3L_getIndexedTriangleValues(
|
||||
S3L_Index triangleIndex,
|
||||
|
|
Loading…
Reference in a new issue