weirdes farb artefakte auf den kugeln wenn ein licht zu nah dran ist
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 739 KiB |
@@ -1,5 +1,6 @@
|
|||||||
#include "structs.h"
|
#include "structs.h"
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
|
#include "helper.h"
|
||||||
|
|
||||||
vec3 collisionPointSphere(ray *lightray, sphere *object)
|
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.x = S * lightray->direction.x + lightray->origin.x;
|
||||||
collisionPoint.y = S * lightray->direction.y + lightray->origin.y;
|
collisionPoint.y = S * lightray->direction.y + lightray->origin.y;
|
||||||
collisionPoint.z = S * lightray->direction.z + lightray->origin.z;
|
collisionPoint.z = S * lightray->direction.z + lightray->origin.z;
|
||||||
|
if (!epsilonCheck(lightray->origin, collisionPoint)) {
|
||||||
|
return (vec3){-10000000, -10000000, -10000000};
|
||||||
|
}
|
||||||
|
|
||||||
return collisionPoint;
|
return collisionPoint;
|
||||||
}
|
}
|
||||||
double S = (-b)/(2*a);
|
double S = (-b)/(2*a);
|
||||||
|
|||||||
+8
-3
@@ -36,10 +36,11 @@ void exampleSphere( int width, int height, int channels, unsigned char **image)
|
|||||||
cam1.screenDistance = 1;
|
cam1.screenDistance = 1;
|
||||||
cam1.width = 1.920;
|
cam1.width = 1.920;
|
||||||
cam1.height = 1.080;
|
cam1.height = 1.080;
|
||||||
vec3 sphereOrigin = (vec3){0,-2,5};
|
vec3 sphereOrigin = (vec3){0,-1.5,5};
|
||||||
double sphereRadius = 1.0;
|
double sphereRadius = 1.0;
|
||||||
|
int objectCount = 7;
|
||||||
sphere obj1 = (sphere){sphereOrigin, sphereRadius,(RGBA){1,0.5,1,1},0};
|
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;
|
objectList[0] = &obj1;
|
||||||
sphere obj2 = (sphere){vec3Add(sphereOrigin, (vec3){3,0,0}), sphereRadius, (RGBA){1,1,0.5,1},0};
|
sphere obj2 = (sphere){vec3Add(sphereOrigin, (vec3){3,0,0}), sphereRadius, (RGBA){1,1,0.5,1},0};
|
||||||
objectList[1] = &obj2;
|
objectList[1] = &obj2;
|
||||||
@@ -49,7 +50,11 @@ void exampleSphere( int width, int height, int channels, unsigned char **image)
|
|||||||
objectList[3] = &obj4;
|
objectList[3] = &obj4;
|
||||||
sphere light1 = (sphere){(vec3){1,1,4.5}, sphereRadius, (RGBA){1,1,1,1},1};
|
sphere light1 = (sphere){(vec3){1,1,4.5}, sphereRadius, (RGBA){1,1,1,1},1};
|
||||||
objectList[4] = &light1;
|
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);
|
displaySzene(objectList, objectCount, cam1, width, height, channels, image);
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "structs.h"
|
#include "structs.h"
|
||||||
|
#include "vectorOp.h"
|
||||||
|
#define EPSILON 1e-8
|
||||||
|
|
||||||
vec3 randUnitVector() {
|
vec3 randUnitVector() {
|
||||||
double x1,x2,lengthSquared;
|
double x1,x2,lengthSquared;
|
||||||
@@ -22,3 +24,11 @@ vec3 randUnitVector() {
|
|||||||
1.0 - 2.0 * lengthSquared};
|
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,3 +2,5 @@
|
|||||||
#include "structs.h"
|
#include "structs.h"
|
||||||
|
|
||||||
vec3 randUnitVector();
|
vec3 randUnitVector();
|
||||||
|
|
||||||
|
int epsilonCheck(vec3, vec3);
|
||||||
|
|||||||
+6
-1
@@ -4,6 +4,8 @@
|
|||||||
#include "vectorOp.h"
|
#include "vectorOp.h"
|
||||||
#define MAXSPHERES 100
|
#define MAXSPHERES 100
|
||||||
#include "helper.h"
|
#include "helper.h"
|
||||||
|
#include <math.h>
|
||||||
|
#define epsilon 1e-8
|
||||||
|
|
||||||
RGBA raytraceSphere(sphere **objectList, ray *lightray) {
|
RGBA raytraceSphere(sphere **objectList, ray *lightray) {
|
||||||
RGBA pixel = (RGBA){0,0,0,0};
|
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) );
|
//vec3 *spheresNormalList = (vec3 *)calloc( lightBounces + 1,sizeof(vec3) );
|
||||||
int hitLightIndex = -1;
|
int hitLightIndex = -1;
|
||||||
vec3 sphereNormal;
|
vec3 sphereNormal;
|
||||||
int raysPerPixel = 2000;
|
int raysPerPixel = 20;
|
||||||
ray originalRay = *lightray;
|
ray originalRay = *lightray;
|
||||||
|
|
||||||
for (int k = 0; k < raysPerPixel; k++) {
|
for (int k = 0; k < raysPerPixel; k++) {
|
||||||
@@ -46,6 +48,9 @@ RGBA raytraceSphere(sphere **objectList, ray *lightray) {
|
|||||||
spheresNormalList[j] = sphereNormal;
|
spheresNormalList[j] = sphereNormal;
|
||||||
//diffus:
|
//diffus:
|
||||||
lightray->direction = vec3Add(sphereNormal, randUnitVector());
|
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:
|
//reflektion:
|
||||||
//lightray->direction = vec3Add(lightray->direction, vec3Scale(sphereNormal, 2));
|
//lightray->direction = vec3Add(lightray->direction, vec3Scale(sphereNormal, 2));
|
||||||
lightray->origin = nearestCollisionPoint;
|
lightray->origin = nearestCollisionPoint;
|
||||||
|
|||||||
Reference in New Issue
Block a user