versuch reflexionen einzubauen. man sieht sie zwar, aber der rest ist auch noch beleuchtet
This commit is contained in:
+2
-2
@@ -84,8 +84,8 @@ void exampleSphere( int width, int height, int channels, unsigned char *image) {
|
||||
free(lightRay);
|
||||
|
||||
image[step] = (int)(pixelColor.r * 255.0);
|
||||
image[step+1] = 0;
|
||||
image[step+2] = 0;
|
||||
image[step+1] = (int)(pixelColor.g * 255.0);
|
||||
image[step+2] = (int)(pixelColor.b * 255.0);
|
||||
if (channels == 4) {
|
||||
image[step+3] = 255;
|
||||
}
|
||||
|
||||
+19
-3
@@ -8,9 +8,14 @@ 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 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) {
|
||||
@@ -24,12 +29,23 @@ RGBA raytraceSphere(sphere **objectList, ray *lightray) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (nearestSphere != nullptr) {
|
||||
vec3 sphereNormal = vec3Normalize(vec3Subtract(nearestCollisionPoint, nearestSphere->origin));
|
||||
pixel.r = -vec3Product(sphereNormal, lightray->direction);
|
||||
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)
|
||||
{
|
||||
//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