--- a/src/raytracer.cc Mon May 05 15:31:14 2008 +0200
+++ b/src/raytracer.cc Tue May 06 09:39:58 2008 +0200
@@ -30,8 +30,6 @@
#include <assert.h>
#include "raytracer.h"
-int pyrit_verbosity = 2;
-
// Hammersley spherical point distribution
// http://www.cse.cuhk.edu.hk/~ttwong/papers/udpoint/udpoints.html
Vector Raytracer::SphereDistribute(int i, int n, Float extent, const Vector &normal)
@@ -40,15 +38,15 @@
int kk;
t = 0;
- for (p=0.5, kk=i; kk; p*=0.5, kk>>=1)
+ for (p=0.5f, kk=i; kk; p*=0.5f, kk>>=1)
if (kk & 1)
t += p;
- t = 1.0 + (t - 1.0)*extent;
+ t = 1.0f + (t - 1.0f)*extent;
- phi = (i + 0.5) / n;
- phirad = phi * 2.0 * M_PI;
+ phi = (i + 0.5f) / n;
+ phirad = phi * 2.0f * PI;
- st = sqrt(1.0 - t*t);
+ st = sqrt(1.0f - t*t);
Float x, y, z, xx, yy, zz, q;
x = st * cos(phirad);
@@ -105,7 +103,7 @@
continue;
}
- const Vector R = L - 2.0 * L_dot_N * N;
+ const Vector R = L - 2.0f * L_dot_N * N;
const Float R_dot_V = dot(R, V);
// diffuse
@@ -205,7 +203,7 @@
// reflection
if (refl > 0.01)
{
- Vector newdir = ray.dir + 2.0 * cos_i * normal;
+ Vector newdir = ray.dir + 2.0f * cos_i * normal;
Ray newray = Ray(P, newdir);
refl_col = raytrace(newray, depth + 1, shape);
}
@@ -222,9 +220,9 @@
}
else
{
- n1 = 1.0;
+ n1 = 1.0f;
n2 = shape->material->refract_index;
- n = 1.0 / n2;
+ n = 1.0f / n2;
}
const Float sin2_t = n*n * (1 - cos_i*cos_i);
if (sin2_t >= 1.0)
@@ -236,14 +234,14 @@
else
{
const Float cos_t = sqrtf(1 - sin2_t);
- const Float Rdiv = 1.0/(n1*cos_i + n2*cos_t);
+ const Float Rdiv = 1.0f / (n1*cos_i + n2*cos_t);
const Float Rper = (n1*cos_i - n2*cos_t)*Rdiv;
const Float Rpar = (n2*cos_i - n1*cos_t)*Rdiv;
const Float R = (Rper*Rper + Rpar*Rpar)/2;
refl += R*trans;
trans = (1-R)*trans;
Vector newdir = n * ray.dir + (n*cos_i - cos_t) * normal;
- Ray newray = Ray(P + 0.001*newdir, newdir);
+ Ray newray = Ray(P + 0.001f*newdir, newdir);
trans_col = raytrace(newray, depth + 1, NULL);
}
}
@@ -323,7 +321,10 @@
VectorPacket normal;
for (int i = 0; i < 4; i++)
if (nearest_shapes[i] != NULL)
- normal.setVector(i, nearest_shapes[i]->normal(P.getVector(i)));
+ {
+ const Vector Pvecti = P.getVector(i);
+ normal.setVector(i, nearest_shapes[i]->normal(Pvecti));
+ }
// make shapes double sided
mfloat4 from_inside = mcmpgt(dot(normal, rays.dir), mZero);
@@ -350,6 +351,11 @@
}
#endif
+#ifdef MSVC
+__declspec(noreturn)
+#else
+__attribute__((noreturn))
+#endif
void *Raytracer::raytrace_worker(void *d)
{
static const int my_queue_size = 256;
@@ -405,11 +411,11 @@
if (can_use_packets)
{
// packet ray tracing
- assert((my_count % 4) == 0);
- for (int i = 0; i < my_count; i+=4)
+ assert((my_count & 3) == 0);
+ for (int i = 0; i < (my_count >> 2); i++)
{
- rt->camera->makeRayPacket(my_queue + i, rays);
- rt->raytracePacket(rays, my_colours + i);
+ rt->camera->makeRayPacket(my_queue + (i<<2), rays);
+ rt->raytracePacket(rays, my_colours + (i<<2));
}
}
else
@@ -429,7 +435,6 @@
rt->sampler->saveSample(my_queue[i], my_colours[i]);
pthread_mutex_unlock(&rt->sampler_mutex);
}
- return NULL;
}
void Raytracer::render()