weirdes farb artefakte auf den kugeln wenn ein licht zu nah dran ist

This commit is contained in:
any
2026-07-30 18:12:19 +02:00
parent 82ab538095
commit 2ebc5f03bb
7 changed files with 31 additions and 4 deletions
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 739 KiB

+5
View File
@@ -1,5 +1,6 @@
#include "structs.h"
#include "math.h"
#include "helper.h"
vec3 collisionPointSphere(ray *lightray, sphere *object)
{
@@ -21,6 +22,10 @@ vec3 collisionPointSphere(ray *lightray, sphere *object)
collisionPoint.x = S * lightray->direction.x + lightray->origin.x;
collisionPoint.y = S * lightray->direction.y + lightray->origin.y;
collisionPoint.z = S * lightray->direction.z + lightray->origin.z;
if (!epsilonCheck(lightray->origin, collisionPoint)) {
return (vec3){-10000000, -10000000, -10000000};
}
return collisionPoint;
}
double S = (-b)/(2*a);
+8 -3
View File
@@ -36,10 +36,11 @@ void exampleSphere( int width, int height, int channels, unsigned char **image)
cam1.screenDistance = 1;
cam1.width = 1.920;
cam1.height = 1.080;
vec3 sphereOrigin = (vec3){0,-2,5};
vec3 sphereOrigin = (vec3){0,-1.5,5};
double sphereRadius = 1.0;
int objectCount = 7;
sphere obj1 = (sphere){sphereOrigin, sphereRadius,(RGBA){1,0.5,1,1},0};
sphere **objectList = (sphere **) calloc(5+1, sizeof(sphere*));;
sphere **objectList = (sphere **) calloc(objectCount+1, sizeof(sphere*));;
objectList[0] = &obj1;
sphere obj2 = (sphere){vec3Add(sphereOrigin, (vec3){3,0,0}), sphereRadius, (RGBA){1,1,0.5,1},0};
objectList[1] = &obj2;
@@ -49,7 +50,11 @@ void exampleSphere( int width, int height, int channels, unsigned char **image)
objectList[3] = &obj4;
sphere light1 = (sphere){(vec3){1,1,4.5}, sphereRadius, (RGBA){1,1,1,1},1};
objectList[4] = &light1;
int objectCount = 5;
sphere obj5 = (sphere){(vec3){0, -6, 6.5}, 5, (RGBA){1,0.2,0.6,1},0};
objectList[5] = &obj5;
sphere light2 = (sphere){(vec3){1,-2,4}, sphereRadius, (RGBA){1,1,1,1},1};
objectList[6] = &light2;
displaySzene(objectList, objectCount, cam1, width, height, channels, image);
+10
View File
@@ -6,6 +6,8 @@
#include <stdlib.h>
#include <math.h>
#include "structs.h"
#include "vectorOp.h"
#define EPSILON 1e-8
vec3 randUnitVector() {
double x1,x2,lengthSquared;
@@ -22,3 +24,11 @@ vec3 randUnitVector() {
1.0 - 2.0 * lengthSquared};
}
int epsilonCheck(vec3 p1, vec3 p2) { //if distance is to small, the test fails (return 0)
vec3 distanceVector = vec3Subtract(p1, p2);
double sumVector = fabs(distanceVector.x) + fabs(distanceVector.y) + fabs(distanceVector.z);
if (sumVector <= EPSILON) {
return 0;
}
return 1;
}
+2
View File
@@ -2,3 +2,5 @@
#include "structs.h"
vec3 randUnitVector();
int epsilonCheck(vec3, vec3);
+6 -1
View File
@@ -4,6 +4,8 @@
#include "vectorOp.h"
#define MAXSPHERES 100
#include "helper.h"
#include <math.h>
#define epsilon 1e-8
RGBA raytraceSphere(sphere **objectList, ray *lightray) {
RGBA pixel = (RGBA){0,0,0,0};
@@ -12,7 +14,7 @@ RGBA raytraceSphere(sphere **objectList, ray *lightray) {
//vec3 *spheresNormalList = (vec3 *)calloc( lightBounces + 1,sizeof(vec3) );
int hitLightIndex = -1;
vec3 sphereNormal;
int raysPerPixel = 2000;
int raysPerPixel = 20;
ray originalRay = *lightray;
for (int k = 0; k < raysPerPixel; k++) {
@@ -46,6 +48,9 @@ RGBA raytraceSphere(sphere **objectList, ray *lightray) {
spheresNormalList[j] = sphereNormal;
//diffus:
lightray->direction = vec3Add(sphereNormal, randUnitVector());
if (fabs(lightray->direction.x ) <= epsilon || fabs(lightray->direction.y ) <= epsilon || fabs(lightray->direction.z) <= epsilon) {
lightray->direction = sphereNormal;
}
//reflektion:
//lightray->direction = vec3Add(lightray->direction, vec3Scale(sphereNormal, 2));
lightray->origin = nearestCollisionPoint;
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 739 KiB

After

Width:  |  Height:  |  Size: 1.0 MiB