Global illumination aus und monitoring/loading bar implementiert
This commit is contained in:
+1
-1
@@ -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
@@ -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
@@ -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;
|
||||
|
||||
@@ -72,4 +72,10 @@ typedef struct {
|
||||
int nextPixelId;
|
||||
pthread_mutex_t mutexKey;
|
||||
int pixelCount;
|
||||
} RenderArgs;
|
||||
} RenderArgs;
|
||||
|
||||
typedef struct {
|
||||
int *nextPixelId;
|
||||
int pixelCount;
|
||||
pthread_mutex_t *mutexKey;
|
||||
} MonitorArgs;
|
||||
Reference in New Issue
Block a user