versuch reflexionen einzubauen. man sieht sie zwar, aber der rest ist auch noch beleuchtet
This commit is contained in:
+29
-13
@@ -8,28 +8,44 @@ RGBA raytraceSphere(sphere **objectList, ray *lightray) {
|
||||
RGBA pixel = (RGBA){0,0,0,1};
|
||||
const int lightBounces = 1;
|
||||
sphere **spheresHitList = (sphere **)calloc( (lightBounces + 1),sizeof(sphere*) );
|
||||
int hitLightIndex = -1;
|
||||
vec3 sphereNormal;
|
||||
|
||||
sphere *nearestSphere = nullptr;
|
||||
vec3 nearestCollisionPoint = {10000,10000,10000};
|
||||
for (int i = 0; i < 100 && objectList[i] != nullptr; i++) {
|
||||
vec3 collisionPoint = collisionPointSphere(lightray, objectList[i]);
|
||||
if (collisionPoint.x == -10000000) {
|
||||
for (int j = 0; j <= lightBounces; j++) {
|
||||
nearestSphere = nullptr;
|
||||
nearestCollisionPoint = (vec3){10000,10000,10000};
|
||||
for (int i = 0; i < 100 && objectList[i] != nullptr; i++) {
|
||||
vec3 collisionPoint = collisionPointSphere(lightray, objectList[i]);
|
||||
if (collisionPoint.x == -10000000) {
|
||||
|
||||
}
|
||||
else{
|
||||
if (vec3Length(collisionPoint)< vec3Length(nearestCollisionPoint)) {
|
||||
nearestCollisionPoint = collisionPoint;
|
||||
nearestSphere = objectList[i];
|
||||
}
|
||||
else{
|
||||
if (vec3Length(collisionPoint)< vec3Length(nearestCollisionPoint)) {
|
||||
nearestCollisionPoint = collisionPoint;
|
||||
nearestSphere = objectList[i];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (nearestSphere != nullptr) {
|
||||
sphereNormal = vec3Normalize(vec3Subtract(nearestCollisionPoint, nearestSphere->origin));////////////////////////////// optimize divide by sphere radius instead
|
||||
lightray->direction = vec3Add(lightray->direction, vec3Scale(sphereNormal, 2));
|
||||
lightray->origin = nearestCollisionPoint;
|
||||
}
|
||||
else {
|
||||
sphereNormal = (vec3){0,0,0};
|
||||
}
|
||||
}
|
||||
if (nearestSphere != nullptr) {
|
||||
vec3 sphereNormal = vec3Normalize(vec3Subtract(nearestCollisionPoint, nearestSphere->origin));
|
||||
pixel.r = -vec3Product(sphereNormal, lightray->direction);
|
||||
|
||||
if (nearestSphere != nullptr)
|
||||
{
|
||||
//pixel.r = -vec3Product(sphereNormal, lightray->direction);
|
||||
pixel = (RGBA){1 - 0.5 *( sphereNormal.x + 1), 1 - 0.5 * (sphereNormal.y +1), 1 -0.5* (sphereNormal.z + 1),1};
|
||||
}
|
||||
|
||||
|
||||
free(spheresHitList);
|
||||
return pixel;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user