diff --git a/Collision.c b/Collision.c index 9a06e50..ea0968f 100644 --- a/Collision.c +++ b/Collision.c @@ -44,7 +44,7 @@ vec3 collisionPlane(ray *lightray, plane *object) { if (vec3Product(lightray->direction, object->normal) >= 0) return (vec3){-10000000, -10000000, -10000000}; r = vec3Product(object->normal, vec3Subtract(object->origin, lightray->origin)) * 1/(vec3Product(lightray->direction, object->normal)); - if (r <= 1e-6) return (vec3){-10000000, -10000000, -10000000}; + if (r <= 1e-9) return (vec3){-10000000, -10000000, -10000000}; collisionPoint = vec3Add(lightray->origin, vec3Scale(lightray->direction, r)); return collisionPoint; diff --git a/interface.c b/interface.c index 80fe812..d441eda 100644 --- a/interface.c +++ b/interface.c @@ -1,6 +1,14 @@ // // Created by ary on 29.07.2026. // +#include +#ifdef _WIN32 + #include + #define SLEEP_SECONDS(s) Sleep((s) * 1000) +#else + #include + #define SLEEP_SECONDS(s) sleep(s) +#endif #include "interface.h" #include "examples.h" @@ -61,6 +69,21 @@ void *workerLoop(void *arg) { return NULL; } +void* monitorProgress(void *arg) { + MonitorArgs *args = (MonitorArgs*)arg; + + while (1){ + pthread_mutex_lock(args->mutexKey); + int pixelId = *args->nextPixelId; + pthread_mutex_unlock(args->mutexKey); + if (pixelId >= args->pixelCount) break; + double progress = 100.0 * pixelId / args->pixelCount; + printf("progress: %lf%%\n", progress); + SLEEP_SECONDS(1); + } + return NULL; +} + void displaySzene(object objectList[], int objectCount, camera cam1, int width, int height, int channels, unsigned char **image) { const vec3 worldUp = (vec3){0, 1, 0}; vec3 screenX = vec3Cross(worldUp, cam1.direction); @@ -87,6 +110,8 @@ void displaySzene(object objectList[], int objectCount, camera cam1, int width, for (int i = 0; i < WORKTHREADSIZE; i++) { pthread_create(&(threadIdList[i]), NULL, workerLoop, args); } + pthread_t monitorThread; + pthread_create(&monitorThread, NULL, monitorProgress, (void*)(&(MonitorArgs){&args->nextPixelId, args->pixelCount, &args->mutexKey})); //renderPixel(i, objectList, objectCount, width, channels, &screenTopLeft, &vecPixelStepX, &vecPixelStepY, &cam1, image); @@ -94,6 +119,7 @@ void displaySzene(object objectList[], int objectCount, camera cam1, int width, for (int i = 0; i < WORKTHREADSIZE; i++) { pthread_join(threadIdList[i], NULL); } + pthread_join(monitorThread, NULL); pthread_mutex_destroy(&args->mutexKey); free(threadIdList); free(args); diff --git a/raytrace.c b/raytrace.c index c2395c4..d51ba3a 100644 --- a/raytrace.c +++ b/raytrace.c @@ -31,8 +31,8 @@ RGBA getRayColor(RGBA colorList[], bool isLightList[]) { //return rayColor; firstLightHitIndex = lightBounces - 1; isLightList[firstLightHitIndex] = 1; - colorList[firstLightHitIndex] = (RGBA){GLOBALILLUMINATION,GLOBALILLUMINATION,GLOBALILLUMINATION,1}; - //colorList[firstLightHitIndex] = (RGBA){0,0,0,1}; + //colorList[firstLightHitIndex] = (RGBA){GLOBALILLUMINATION,GLOBALILLUMINATION,GLOBALILLUMINATION,1}; + colorList[firstLightHitIndex] = (RGBA){0,0,0,1}; } //pixel.r += spheresHitList[firstLightHitIndex]->color.r; //pixel.g += spheresHitList[firstLightHitIndex]->color.g; diff --git a/structs.h b/structs.h index 81d4310..f454517 100644 --- a/structs.h +++ b/structs.h @@ -72,4 +72,10 @@ typedef struct { int nextPixelId; pthread_mutex_t mutexKey; int pixelCount; -} RenderArgs; \ No newline at end of file +} RenderArgs; + +typedef struct { + int *nextPixelId; + int pixelCount; + pthread_mutex_t *mutexKey; +} MonitorArgs; \ No newline at end of file diff --git a/test.png b/test.png index 998e51c..ecfeca5 100644 Binary files a/test.png and b/test.png differ