1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/small3dlib.git synced 2024-11-24 21:09:57 +01:00
This commit is contained in:
Miloslav Číž 2019-06-07 12:19:36 +02:00
parent 3866947c88
commit 550b91491d

View file

@ -96,14 +96,35 @@ void drawPixel(S3L_PixelInfo *p)
{ {
if (p->triangleIndex != previousTriangle) if (p->triangleIndex != previousTriangle)
{ {
int16_t index = p->triangleIndex * 3; int16_t index;
if (mode == 0)
{
index = p->triangleIndex * 3;
int16_t i0 = uvIndices[index]; int16_t i0 = uvIndices[index];
int16_t i1 = uvIndices[index + 1]; int16_t i1 = uvIndices[index + 1];
int16_t i2 = uvIndices[index + 2]; int16_t i2 = uvIndices[index + 2];
if (mode == 3) 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];
}
else if (mode == 3)
{ {
index = p->triangleIndex * 3;
S3L_Vec4 v0, v1, v2; S3L_Vec4 v0, v1, v2;
S3L_Index v = model.triangles[index] * 3; S3L_Index v = model.triangles[index] * 3;
@ -137,21 +158,8 @@ void drawPixel(S3L_PixelInfo *p)
nt.z = S3L_clamp(128 + nt.z / 4,0,255); nt.z = S3L_clamp(128 + nt.z / 4,0,255);
} }
index = i0 * 2; if (light || mode == 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];
index = scene.models[p->modelIndex].triangles[p->triangleIndex * 3] * 3; index = scene.models[p->modelIndex].triangles[p->triangleIndex * 3] * 3;
n0.x = normals[index]; n0.x = normals[index];
@ -179,6 +187,7 @@ void drawPixel(S3L_PixelInfo *p)
l0 = 256 + S3L_clamp(S3L_dotProductVec3(n0,toLight),-511,511) / 2; l0 = 256 + S3L_clamp(S3L_dotProductVec3(n0,toLight),-511,511) / 2;
l1 = 256 + S3L_clamp(S3L_dotProductVec3(n1,toLight),-511,511) / 2; l1 = 256 + S3L_clamp(S3L_dotProductVec3(n1,toLight),-511,511) / 2;
l2 = 256 + S3L_clamp(S3L_dotProductVec3(n2,toLight),-511,511) / 2; l2 = 256 + S3L_clamp(S3L_dotProductVec3(n2,toLight),-511,511) / 2;
}
previousTriangle = p->triangleIndex; previousTriangle = p->triangleIndex;
} }