updated embree, fixed cmakefiles, still some bugs in the tutorial example

This commit is contained in:
Daniele Panozzo
2015-02-04 22:48:31 +01:00
parent a60ebfa801
commit 17c9429d26
744 changed files with 93222 additions and 82688 deletions
+95 -53
View File
@@ -1,5 +1,5 @@
// ======================================================================== //
// Copyright 2009-2013 Intel Corporation //
// Copyright 2009-2014 Intel Corporation //
// //
// Licensed under the Apache License, Version 2.0 (the "License"); //
// you may not use this file except in compliance with the License. //
@@ -16,13 +16,35 @@
#include "../common/tutorial/tutorial_device.h"
/* render function to use */
renderPixelFunc renderPixel;
/* error reporting function */
void error_handler(const RTCError code, const int8* str)
{
printf("Embree: ");
switch (code) {
case RTC_UNKNOWN_ERROR : printf("RTC_UNKNOWN_ERROR"); break;
case RTC_INVALID_ARGUMENT : printf("RTC_INVALID_ARGUMENT"); break;
case RTC_INVALID_OPERATION: printf("RTC_INVALID_OPERATION"); break;
case RTC_OUT_OF_MEMORY : printf("RTC_OUT_OF_MEMORY"); break;
case RTC_UNSUPPORTED_CPU : printf("RTC_UNSUPPORTED_CPU"); break;
default : printf("invalid error code"); break;
}
if (str) {
printf(" (");
while (*str) putchar(*str++);
printf(")\n");
}
abort();
}
const int numPhi = 5;
const int numTheta = 2*numPhi;
unsigned int createTriangulatedSphere (RTCScene scene, Vec3f p, float r)
unsigned int createTriangulatedSphere (RTCScene scene, const Vec3fa& p, float r)
{
/* create triangle mesh */
unsigned int mesh = rtcNewTriangleMesh (scene, RTC_GEOMETRY_STATIC, 2*numTheta*(numPhi-1), numTheta*(numPhi+1));
@@ -108,7 +130,14 @@ unsigned int g_instance1 = -1;
unsigned int g_instance2 = -1;
unsigned int g_instance3 = -1;
Vec3f colors[4][4];
Vec3fa colors[4][4];
/* rtcCommitThread called by all ISPC worker threads to enable parallel build */
#if defined(PARALLEL_COMMIT)
task void parallelCommit(RTCScene scene) {
rtcCommitThread (scene,threadIndex,threadCount);
}
#endif
/* called by the C++ code for initialization */
extern "C" void device_init (int8* cfg)
@@ -116,16 +145,24 @@ extern "C" void device_init (int8* cfg)
/* initialize ray tracing core */
rtcInit(cfg);
/* set error handler */
rtcSetErrorFunction(error_handler);
/* create scene */
g_scene = rtcNewScene(RTC_SCENE_DYNAMIC,RTC_INTERSECT1);
/* create scene with 4 triangulated spheres */
g_scene1 = rtcNewScene(RTC_SCENE_STATIC,RTC_INTERSECT1);
createTriangulatedSphere(g_scene1,Vec3f( 0, 0,+1),0.5);
createTriangulatedSphere(g_scene1,Vec3f(+1, 0, 0),0.5);
createTriangulatedSphere(g_scene1,Vec3f( 0, 0,-1),0.5);
createTriangulatedSphere(g_scene1,Vec3f(-1, 0, 0),0.5);
rtcCommit(g_scene1);
createTriangulatedSphere(g_scene1,Vec3fa( 0, 0,+1),0.5);
createTriangulatedSphere(g_scene1,Vec3fa(+1, 0, 0),0.5);
createTriangulatedSphere(g_scene1,Vec3fa( 0, 0,-1),0.5);
createTriangulatedSphere(g_scene1,Vec3fa(-1, 0, 0),0.5);
#if !defined(PARALLEL_COMMIT)
rtcCommit (g_scene1);
#else
launch[ getNumHWThreads() ] parallelCommit(g_scene1);
#endif
/* instantiate geometry */
g_instance0 = rtcNewInstance(g_scene,g_scene1);
@@ -135,37 +172,37 @@ extern "C" void device_init (int8* cfg)
createGroundPlane(g_scene);
/* set all colors */
colors[0][0] = Vec3f(0.25,0,0);
colors[0][1] = Vec3f(0.50,0,0);
colors[0][2] = Vec3f(0.75,0,0);
colors[0][3] = Vec3f(1.00,0,0);
colors[0][0] = Vec3fa(0.25,0,0);
colors[0][1] = Vec3fa(0.50,0,0);
colors[0][2] = Vec3fa(0.75,0,0);
colors[0][3] = Vec3fa(1.00,0,0);
colors[1][0] = Vec3f(0,0.25,0);
colors[1][1] = Vec3f(0,0.50,0);
colors[1][2] = Vec3f(0,0.75,0);
colors[1][3] = Vec3f(0,1.00,0);
colors[1][0] = Vec3fa(0,0.25,0);
colors[1][1] = Vec3fa(0,0.50,0);
colors[1][2] = Vec3fa(0,0.75,0);
colors[1][3] = Vec3fa(0,1.00,0);
colors[2][0] = Vec3f(0,0,0.25);
colors[2][1] = Vec3f(0,0,0.50);
colors[2][2] = Vec3f(0,0,0.75);
colors[2][3] = Vec3f(0,0,1.00);
colors[2][0] = Vec3fa(0,0,0.25);
colors[2][1] = Vec3fa(0,0,0.50);
colors[2][2] = Vec3fa(0,0,0.75);
colors[2][3] = Vec3fa(0,0,1.00);
colors[3][0] = Vec3f(0.25,0.25,0);
colors[3][1] = Vec3f(0.50,0.50,0);
colors[3][2] = Vec3f(0.75,0.75,0);
colors[3][3] = Vec3f(1.00,1.00,0);
colors[3][0] = Vec3fa(0.25,0.25,0);
colors[3][1] = Vec3fa(0.50,0.50,0);
colors[3][2] = Vec3fa(0.75,0.75,0);
colors[3][3] = Vec3fa(1.00,1.00,0);
/* set start render mode */
renderPixel = renderPixelStandard;
}
/* task that renders a single screen tile */
Vec3fa renderPixelStandard(int x, int y, const Vec3fa& vx, const Vec3fa& vy, const Vec3fa& vz, const Vec3fa& p)
Vec3fa renderPixelStandard(float x, float y, const Vec3fa& vx, const Vec3fa& vy, const Vec3fa& vz, const Vec3fa& p)
{
/* initialize ray */
RTCRay ray;
ray.org = p;
ray.dir = normalize(add(mul(x,vx), mul(y,vy), vz));
ray.dir = normalize(x*vx + y*vy + vz);
ray.tnear = 0.0f;
ray.tfar = inf;
ray.geomID = RTC_INVALID_GEOMETRY_ID;
@@ -178,18 +215,18 @@ Vec3fa renderPixelStandard(int x, int y, const Vec3fa& vx, const Vec3fa& vy, con
rtcIntersect(g_scene,ray);
/* shade pixels */
Vec3f color = Vec3f(0.0f);
Vec3fa color = Vec3fa(0.0f);
if (ray.geomID != RTC_INVALID_GEOMETRY_ID)
{
Vec3f diffuse = Vec3f(1,1,1);
Vec3fa diffuse = Vec3fa(1,1,1);
if (ray.instID != -1)
diffuse = colors[ray.instID][ray.geomID];
color = add(color,mul(diffuse,0.5));
Vec3f lightDir = normalize(Vec3f(-1,-1,-1));
color = color + diffuse*0.5; // FIXME: +=
Vec3fa lightDir = normalize(Vec3fa(-1,-1,-1));
/* initialize shadow ray */
RTCRay shadow;
shadow.org = add(ray.org,mul(ray.tfar,ray.dir));
shadow.org = ray.org + ray.tfar*ray.dir;
shadow.dir = neg(lightDir);
shadow.tnear = 0.001f;
shadow.tfar = inf;
@@ -203,7 +240,7 @@ Vec3fa renderPixelStandard(int x, int y, const Vec3fa& vx, const Vec3fa& vy, con
/* add light contribution */
if (shadow.geomID)
color = add(color,mul(diffuse,clamp(-dot(lightDir,normalize(ray.Ng)),0.0f,1.0f)));
color = color + diffuse*clamp(-dot(lightDir,normalize(ray.Ng)),0.0f,1.0f); // FIXME: +=
}
return color;
}
@@ -213,10 +250,10 @@ void renderTile(int taskIndex, int* pixels,
const int width,
const int height,
const float time,
const Vec3f& vx,
const Vec3f& vy,
const Vec3f& vz,
const Vec3f& p,
const Vec3fa& vx,
const Vec3fa& vy,
const Vec3fa& vz,
const Vec3fa& p,
const int numTilesX,
const int numTilesY)
{
@@ -230,7 +267,7 @@ void renderTile(int taskIndex, int* pixels,
for (int y = y0; y<y1; y++) for (int x = x0; x<x1; x++)
{
/* calculate pixel color */
Vec3f color = renderPixel(x,y,vx,vy,vz,p);
Vec3fa color = renderPixel(x,y,vx,vy,vz,p);
/* write color to framebuffer */
unsigned int r = (unsigned int) (255.0f * clamp(color.x,0.0f,1.0f));
@@ -245,35 +282,40 @@ extern "C" void device_render (int* pixels,
const int width,
const int height,
const float time,
const Vec3f& vx,
const Vec3f& vy,
const Vec3f& vz,
const Vec3f& p)
const Vec3fa& vx,
const Vec3fa& vy,
const Vec3fa& vz,
const Vec3fa& p)
{
/* create identity matrix */
AffineSpace3f xfm;
xfm.l.vx = Vec3f(1,0,0);
xfm.l.vy = Vec3f(0,1,0);
xfm.l.vz = Vec3f(0,0,1);
xfm.p = Vec3f(0,0,0);
xfm.l.vx = Vec3fa(1,0,0);
xfm.l.vy = Vec3fa(0,1,0);
xfm.l.vz = Vec3fa(0,0,1);
xfm.p = Vec3fa(0,0,0);
float t = 0.7f*time;
/* move instances */
xfm.p = mul(2.0f,Vec3f(+cos(t),0.0f,+sin(t)));
rtcSetTransform(g_scene,g_instance0,RTC_MATRIX_COLUMN_MAJOR_ALIGNED16,(float*)&xfm);
xfm.p = mul(2.0f,Vec3f(-cos(t),0.0f,-sin(t)));
rtcSetTransform(g_scene,g_instance1,RTC_MATRIX_COLUMN_MAJOR_ALIGNED16,(float*)&xfm);
xfm.p = mul(2.0f,Vec3f(-sin(t),0.0f,+cos(t)));
rtcSetTransform(g_scene,g_instance2,RTC_MATRIX_COLUMN_MAJOR_ALIGNED16,(float*)&xfm);
xfm.p = mul(2.0f,Vec3f(+sin(t),0.0f,-cos(t)));
rtcSetTransform(g_scene,g_instance3,RTC_MATRIX_COLUMN_MAJOR_ALIGNED16,(float*)&xfm);
xfm.p = 2.0f*Vec3fa(+cos(t),0.0f,+sin(t));
rtcSetTransform(g_scene,g_instance0,RTC_MATRIX_COLUMN_MAJOR,(float*)&xfm);
xfm.p = 2.0f*Vec3fa(-cos(t),0.0f,-sin(t));
rtcSetTransform(g_scene,g_instance1,RTC_MATRIX_COLUMN_MAJOR,(float*)&xfm);
xfm.p = 2.0f*Vec3fa(-sin(t),0.0f,+cos(t));
rtcSetTransform(g_scene,g_instance2,RTC_MATRIX_COLUMN_MAJOR,(float*)&xfm);
xfm.p = 2.0f*Vec3fa(+sin(t),0.0f,-cos(t));
rtcSetTransform(g_scene,g_instance3,RTC_MATRIX_COLUMN_MAJOR,(float*)&xfm);
/* update scene */
rtcUpdate(g_scene,g_instance0);
rtcUpdate(g_scene,g_instance1);
rtcUpdate(g_scene,g_instance2);
rtcUpdate(g_scene,g_instance3);
#if !defined(PARALLEL_COMMIT)
rtcCommit (g_scene);
#else
launch[ getNumHWThreads() ] parallelCommit(g_scene);
#endif
/* render all pixels */
const int numTilesX = (width +TILE_SIZE_X-1)/TILE_SIZE_X;