diff --git a/programs/highPoly.c b/programs/highPoly.c index 1082423..32fde45 100644 --- a/programs/highPoly.c +++ b/programs/highPoly.c @@ -82,19 +82,21 @@ void drawPixel(S3L_PixelInfo *p) S3L_normalizeVec3(&normal); - uint8_t shading = - S3L_clamp((S3L_dotProductVec3(normal,toLight) + S3L_FRACTIONS_PER_UNIT) / 4,0,255); + S3L_Unit shading = + (S3L_dotProductVec3(normal,toLight) + S3L_FRACTIONS_PER_UNIT) / 2; + + shading = S3L_interpolate(shading,0,p->depth,32 * S3L_FRACTIONS_PER_UNIT); int index = (p->y * S3L_RESOLUTION_X + p->x) * 3; - frameBuffer[index] = shading; - frameBuffer[index + 1] = shading; - frameBuffer[index + 2] = shading; + frameBuffer[index] = S3L_clamp(S3L_interpolateByUnitFrom0(200,shading),0,255); + frameBuffer[index + 1] = S3L_clamp(S3L_interpolateByUnitFrom0(255,shading),0,255); + frameBuffer[index + 2] = S3L_clamp(S3L_interpolateByUnitFrom0(150,shading),0,255); } int main() { - S3L_setVec4(&toLight,10,10,10,0); + S3L_setVec4(&toLight,10,-10,-10,0); S3L_normalizeVec3(&toLight); diff --git a/small3dlib.h b/small3dlib.h index 38f7710..79e6ea6 100644 --- a/small3dlib.h +++ b/small3dlib.h @@ -982,7 +982,7 @@ void S3L_getIndexedTriangleValues( S3L_Vec4 *v1, S3L_Vec4 *v2) { - S3L_Index i0, i1; + uint32_t i0, i1; S3L_Unit *value; i0 = triangleIndex * 3; @@ -1046,7 +1046,7 @@ void S3L_computeModelNormals(S3L_Model3D model, S3L_Unit *dst, (model.triangles[j + 2] == i)) { S3L_Vec4 t0, t1, t2; - S3L_Index vIndex; + uint32_t vIndex; #define getVertex(n)\ vIndex = model.triangles[j + n] * 3;\ @@ -2437,7 +2437,7 @@ void _S3L_projectVertex( S3L_Vec4 *result, S3L_Unit focalLength) { - S3L_Index vertexIndex = model->triangles[triangleIndex * 3 + vertex] * 3; + uint32_t vertexIndex = model->triangles[triangleIndex * 3 + vertex] * 3; result->x = model->vertices[vertexIndex]; result->y = model->vertices[vertexIndex + 1];