NON WORKING
absoluter clutter beim versuch quads zu implementieren. refactor absolut noetig
This commit is contained in:
+68
-17
@@ -7,7 +7,7 @@
|
||||
#include <math.h>
|
||||
#define epsilon 1e-8
|
||||
|
||||
RGBA raytraceSphere(sphere **objectList, ray *lightray) {
|
||||
RGBA raytraceSphere(sphere **sphereList, int sphereCount, quad **quadList, int quadCount, ray *lightray) {
|
||||
RGBA pixel = (RGBA){0,0,0,0};
|
||||
#define lightBounces 3
|
||||
//sphere **spheresHitList = (sphere **)calloc( (lightBounces + 1),sizeof(sphere*) );
|
||||
@@ -19,45 +19,96 @@ RGBA raytraceSphere(sphere **objectList, ray *lightray) {
|
||||
|
||||
for (int k = 0; k < raysPerPixel; k++) {
|
||||
sphere *spheresHitList[lightBounces + 1] = {0};
|
||||
quad *quadHitList[lightBounces + 1] = {0};
|
||||
vec3 spheresNormalList[lightBounces + 1] = {0};
|
||||
*lightray = originalRay;
|
||||
RGBA tempPixel = (RGBA){1,1,1,1};
|
||||
sphere *nearestSphere = nullptr;
|
||||
quad *nearestQuad = nullptr;
|
||||
vec3 nearestCollisionPoint = {10000,10000,10000};
|
||||
RGBA objectColorList[lightBounces + 1] = {0};
|
||||
|
||||
|
||||
for (int j = 0; j <= lightBounces; j++) {
|
||||
nearestSphere = nullptr;
|
||||
double nearestSphereDistance = 10000000;
|
||||
nearestQuad = nullptr;
|
||||
double nearestQuadDistance = 10000000;
|
||||
nearestCollisionPoint = (vec3){10000,10000,10000};
|
||||
for (int i = 0; i < 100 && objectList[i] != nullptr; i++) {
|
||||
vec3 collisionPoint = collisionPointSphere(lightray, objectList[i]);
|
||||
|
||||
for (int i = 0; i < sphereCount; i++) {
|
||||
vec3 collisionPoint = collisionPointSphere(lightray, sphereList[i]);
|
||||
double collisionPointDistance = 1000000;
|
||||
if (collisionPoint.x == -10000000) {
|
||||
|
||||
}
|
||||
else{
|
||||
if (vec3Length(vec3Subtract(collisionPoint, lightray->origin)) < vec3Length(vec3Subtract(nearestCollisionPoint, lightray->origin))) {
|
||||
collisionPointDistance = vec3Length(vec3Subtract(collisionPoint, lightray->origin));
|
||||
if (collisionPointDistance < vec3Length(vec3Subtract(nearestCollisionPoint, lightray->origin))) {
|
||||
nearestCollisionPoint = collisionPoint;
|
||||
nearestSphere = objectList[i];
|
||||
nearestSphere = sphereList[i];
|
||||
nearestSphereDistance = collisionPointDistance;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < quadCount; i++) {
|
||||
vec3 collisionPoint = collisionQuad(lightray, quadList[i]);
|
||||
double collisionPointDistance = 1000000;
|
||||
if (collisionPoint.x == -10000000) {
|
||||
|
||||
if (nearestSphere != nullptr) {
|
||||
spheresHitList[j] = nearestSphere;
|
||||
sphereNormal = vec3Scale(vec3Subtract(nearestCollisionPoint, nearestSphere->origin), 1/(nearestSphere->radius));////////////////////////////// optimize, schreibe divide vector funktion
|
||||
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;
|
||||
else{
|
||||
collisionPointDistance = vec3Length(vec3Subtract(collisionPoint, lightray->origin));
|
||||
if (collisionPointDistance < vec3Length(vec3Subtract(nearestCollisionPoint, lightray->origin))) {
|
||||
nearestCollisionPoint = collisionPoint;
|
||||
nearestQuad = quadList[i];
|
||||
nearestQuadDistance = collisionPointDistance;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (nearestQuadDistance > nearestSphereDistance) {
|
||||
if (nearestSphere != nullptr) {
|
||||
objectColorList[j] = nearestSphere->color;
|
||||
spheresHitList[j] = nearestSphere;
|
||||
sphereNormal = vec3Scale(vec3Subtract(nearestCollisionPoint, nearestSphere->origin), 1/(nearestSphere->radius));////////////////////////////// optimize, schreibe divide vector funktion
|
||||
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;
|
||||
}
|
||||
else {
|
||||
sphereNormal = (vec3){1,1,1};
|
||||
}
|
||||
}
|
||||
else {
|
||||
sphereNormal = (vec3){1,1,1};
|
||||
|
||||
if (nearestQuad != nullptr) {
|
||||
objectColorList[j] = nearestQuad->color;
|
||||
quadHitList[j] = nearestQuad;
|
||||
//diffus:
|
||||
lightray->direction = vec3Add(nearestQuad->normal, randUnitVector());
|
||||
if (fabs(lightray->direction.x ) <= epsilon || fabs(lightray->direction.y ) <= epsilon || fabs(lightray->direction.z) <= epsilon) {
|
||||
lightray->direction = nearestQuad->normal;
|
||||
}
|
||||
//reflektion:
|
||||
//lightray->direction = vec3Add(lightray->direction, vec3Scale(sphereNormal, 2));
|
||||
lightray->origin = nearestCollisionPoint;
|
||||
}
|
||||
else {
|
||||
//sphereNormal = (vec3){1,1,1};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
int firstLightHitIndex = -1;
|
||||
|
||||
Reference in New Issue
Block a user