Global illumination aus und monitoring/loading bar implementiert

This commit is contained in:
any
2026-08-29 00:31:13 +02:00
parent 20ab33de33
commit 7052745a90
5 changed files with 36 additions and 4 deletions
+1 -1
View File
@@ -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;
+26
View File
@@ -1,6 +1,14 @@
//
// Created by ary on 29.07.2026.
//
#include <stdio.h>
#ifdef _WIN32
#include <windows.h>
#define SLEEP_SECONDS(s) Sleep((s) * 1000)
#else
#include <unistd.h>
#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);
+2 -2
View File
@@ -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;
+6
View File
@@ -73,3 +73,9 @@ typedef struct {
pthread_mutex_t mutexKey;
int pixelCount;
} RenderArgs;
typedef struct {
int *nextPixelId;
int pixelCount;
pthread_mutex_t *mutexKey;
} MonitorArgs;
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.4 MiB