Skip to content

Commit

Permalink
[WIP] ISPC tutorials -> CPP tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
freibold committed Nov 29, 2024
1 parent 9863326 commit 1968231
Show file tree
Hide file tree
Showing 47 changed files with 185 additions and 93 deletions.
6 changes: 3 additions & 3 deletions tutorials/curve_geometry/curve_geometry_device.ispc
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export void device_init (uniform int8* uniform cfg)

/* commit changes to scene */
rtcCommitScene (data.g_scene);
data.g_traversable = rtcGetSceneTraversable(data.g_scene);
}

/* task that renders a single screen tile */
Expand All @@ -156,7 +157,7 @@ void renderPixelStandard(const uniform TutorialData& data,
uniform RTCIntersectArguments iargs;
rtcInitIntersectArguments(&iargs);
iargs.feature_mask = (uniform RTCFeatureFlags) (FEATURE_MASK);
rtcIntersectV(data.g_scene,RTCRayHit_(ray),&iargs);
rtcTraversableIntersectV(data.g_traversable,RTCRayHit_(ray),&iargs);
RayStats_addRay(stats);

/* shade pixels */
Expand Down Expand Up @@ -188,7 +189,7 @@ void renderPixelStandard(const uniform TutorialData& data,
uniform RTCOccludedArguments sargs;
rtcInitOccludedArguments(&sargs);
sargs.feature_mask = (uniform RTCFeatureFlags) (FEATURE_MASK);
rtcOccludedV(data.g_scene,RTCRay_(shadow),&sargs);
rtcTraversableOccludedV(data.g_traversable,RTCRay_(shadow),&sargs);
RayStats_addShadowRay(stats);

/* add light contribution */
Expand Down Expand Up @@ -286,6 +287,5 @@ export void device_render (uniform int* uniform pixels,
/* called by the C++ code for cleanup */
export void device_cleanup ()
{
rtcReleaseScene (data.g_scene); data.g_scene = NULL;
TutorialData_Destructor(&data);
}
2 changes: 2 additions & 0 deletions tutorials/curve_geometry/curve_geometry_device.isph
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ uniform int8 static_hair_flags_linear[NUM_CURVES] = {
struct TutorialData
{
RTCScene g_scene;
RTCTraversable g_traversable;
Vec4f* hair_vertices;
Vec3fa* hair_normals;
Vec3fa* hair_vertex_colors;
Expand All @@ -79,6 +80,7 @@ struct TutorialData
inline void TutorialData_Constructor(uniform TutorialData* uniform This)
{
This->g_scene = NULL;
This->g_traversable = NULL;
This->hair_vertices = uniform new uniform Vec4f[NUM_VERTICES];
This->hair_normals = uniform new uniform Vec3fa[NUM_VERTICES];
This->hair_vertex_colors = uniform new uniform Vec3fa[NUM_VERTICES];
Expand Down
5 changes: 3 additions & 2 deletions tutorials/dynamic_scene/dynamic_scene_device.ispc
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void renderPixelStandard(const uniform TutorialData& data,
rtcInitIntersectArguments(&iargs);
iargs.feature_mask = (uniform RTCFeatureFlags) (FEATURE_MASK);

rtcIntersectV(data.g_scene,RTCRayHit_(ray),&iargs);
rtcTraversableIntersectV(data.g_traversable,RTCRayHit_(ray),&iargs);
RayStats_addRay(stats);

/* shade pixels */
Expand All @@ -181,7 +181,7 @@ void renderPixelStandard(const uniform TutorialData& data,
uniform RTCOccludedArguments sargs;
rtcInitOccludedArguments(&sargs);
sargs.feature_mask = (uniform RTCFeatureFlags) (FEATURE_MASK);
rtcOccludedV(data.g_scene,RTCRay_(shadow),&sargs);
rtcTraversableOccludedV(data.g_traversable,RTCRay_(shadow),&sargs);
RayStats_addShadowRay(stats);

/* add light contribution */
Expand Down Expand Up @@ -309,6 +309,7 @@ export void device_render (uniform int* uniform pixels,

/* commit changes to scene */
rtcCommitScene (data.g_scene);
data.g_traversable = rtcGetSceneTraversable(data.g_scene);
}

/* called by the C++ code for cleanup */
Expand Down
2 changes: 2 additions & 0 deletions tutorials/dynamic_scene/dynamic_scene_device.isph
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct TutorialData

/* scene data */
RTCScene g_scene;
RTCTraversable g_traversable;

uniform Vec3fa* uniform position;
uniform Vec3fa* uniform colors;
Expand All @@ -28,6 +29,7 @@ void TutorialData_Constructor(uniform TutorialData* uniform This)
This->numPhi = NUM_PHI;
This->numTheta = NUM_THETA;
This->g_scene = NULL;
This->g_traversable = NULL;
This->position = uniform new uniform Vec3fa[NUM_SPHERES];
This->colors = uniform new uniform Vec3fa[NUM_SPHERES+1];
This->radius = uniform new uniform float[NUM_SPHERES];
Expand Down
2 changes: 2 additions & 0 deletions tutorials/grid_geometry/grid_geometry_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ void createGridGeometry (GridMesh& gmesh)
}

/* create normal debug geometry */
#if 0
gmesh.geomNormals = rtcNewGeometry (g_device, RTC_GEOMETRY_TYPE_ROUND_BEZIER_CURVE);
Vec3ff *nvertices = (Vec3ff *) rtcSetNewGeometryBuffer(gmesh.geomNormals,RTC_BUFFER_TYPE_VERTEX,0,RTC_FORMAT_FLOAT4,sizeof(Vec3ff),4*numVertices);
int* curves = (int *) rtcSetNewGeometryBuffer(gmesh.geomNormals,RTC_BUFFER_TYPE_INDEX,0,RTC_FORMAT_UINT ,sizeof(int) ,numVertices);
Expand Down Expand Up @@ -497,6 +498,7 @@ void createGridGeometry (GridMesh& gmesh)
}
h+=sphere_faces[f];
}
#endif

/* we do not need this temporary data anymore */
rtcReleaseGeometry(geomSubdiv);
Expand Down
4 changes: 2 additions & 2 deletions tutorials/grid_geometry/grid_geometry_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ struct TutorialData

void TutorialData_Constructor(TutorialData* This)
{
This->g_scene = nullptr;
This->g_traversable = nullptr;
This->g_scene = nullptr;
This->g_traversable = nullptr;
This->gmesh.geom = nullptr;
This->gmesh.geomNormals = nullptr;
This->gmesh.egrids = nullptr;
Expand Down
5 changes: 3 additions & 2 deletions tutorials/grid_geometry/grid_geometry_device.ispc
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ export void device_init (uniform int8* uniform cfg)

/* commit changes to scene */
rtcCommitScene (data.g_scene);
data.g_traversable = rtcGetSceneTraversable(data.g_scene);
}

Vec3f mylerp(float f, const Vec3f& a, const Vec3f& b) { // FIXME: use lerp, need to make ISPC lerp and C++ lerp compatible first
Expand All @@ -567,7 +568,7 @@ void renderPixelStandard(const uniform TutorialData& data,
uniform RTCIntersectArguments iargs;
rtcInitIntersectArguments(&iargs);
iargs.feature_mask = (uniform RTCFeatureFlags) (FEATURE_MASK);
rtcIntersectV(data.g_scene,RTCRayHit_(ray),&iargs);
rtcTraversableIntersectV(data.g_traversable,RTCRayHit_(ray),&iargs);
RayStats_addRay(stats);

/* shade pixels */
Expand Down Expand Up @@ -608,7 +609,7 @@ void renderPixelStandard(const uniform TutorialData& data,
uniform RTCOccludedArguments sargs;
rtcInitOccludedArguments(&sargs);
sargs.feature_mask = (uniform RTCFeatureFlags) (FEATURE_MASK);
rtcOccludedV(data.g_scene,RTCRay_(shadow),&sargs);
rtcTraversableOccludedV(data.g_traversable,RTCRay_(shadow),&sargs);
RayStats_addShadowRay(stats);

/* add light contribution */
Expand Down
4 changes: 3 additions & 1 deletion tutorials/grid_geometry/grid_geometry_device.isph
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ struct TutorialData
{
/* scene data */
RTCScene g_scene;
RTCTraversable g_traversable;

uniform GridMesh gmesh;
};

void TutorialData_Constructor(uniform TutorialData* uniform This)
{
This->g_scene = NULL;
This->g_scene = NULL;
This->g_traversable = NULL;
This->gmesh.geom = NULL;
This->gmesh.geomNormals = NULL;
This->gmesh.egrids = NULL;
Expand Down
2 changes: 1 addition & 1 deletion tutorials/hair_geometry/hair_geometry_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ Vec3fa occluded(RTCTraversable traversable, RayQueryContext* context, Ray& ray)
args.filter = occlusionFilter;

rtcTraversableOccluded1(traversable,RTCRay_(ray),&args);
context->userRayExt = NULL;
context->userRayExt = nullptr;

if (ray.tfar < 0) return Vec3fa(0.0f);
else return transparency;
Expand Down
9 changes: 5 additions & 4 deletions tutorials/hair_geometry/hair_geometry_device.ispc
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ RTC_SYCL_INDIRECTLY_CALLABLE unmasked void occlusionFilter(const RTCFilterFuncti
valid_i[programIndex] = 0;
}

Vec3f occluded(RTCScene scene, uniform RayQueryContext* uniform context, Ray& ray)
Vec3f occluded(RTCTraversable traversable, uniform RayQueryContext* uniform context, Ray& ray)
{
Vec3f transparency = make_Vec3f(1.0f);
context->userRayExt = &transparency;
Expand All @@ -247,7 +247,7 @@ Vec3f occluded(RTCScene scene, uniform RayQueryContext* uniform context, Ray& ra
args.feature_mask = (uniform RTCFeatureFlags) (FEATURE_MASK);
args.filter = occlusionFilter;

rtcOccludedV(scene,RTCRay_(ray),&args);
rtcTraversableOccludedV(traversable,RTCRay_(ray),&args);
context->userRayExt = NULL;

if (ray.tfar < 0) return make_Vec3f(0.0f);
Expand Down Expand Up @@ -286,7 +286,7 @@ Vec3f renderPixel(const uniform TutorialData& data, float x, float y, const unif
return color;

/* intersect ray with scene and gather all hits */
rtcIntersectV(data.scene,RTCRayHit_(ray),&args);
rtcTraversableIntersectV(data.traversable,RTCRayHit_(ray),&args);
RayStats_addRay(stats);

/* exit if we hit environment */
Expand Down Expand Up @@ -326,7 +326,7 @@ Vec3f renderPixel(const uniform TutorialData& data, float x, float y, const unif

/* sample directional light */
Ray shadow = make_Ray(ray.org + ray.tfar*ray.dir, neg(make_Vec3f(data.dirlight_direction)), eps, inf, time);
Vec3f T = occluded(data.scene,&context,shadow);
Vec3f T = occluded(data.traversable,&context,shadow);
RayStats_addShadowRay(stats);
Vec3f c = AnisotropicBlinn__eval(&brdf,neg(ray.dir),neg(make_Vec3f(data.dirlight_direction)));
color = color + weight*c*T*make_Vec3f(data.dirlight_intensity);
Expand Down Expand Up @@ -416,6 +416,7 @@ export void device_init (uniform int8* uniform cfg)

/* create scene */
g_scene = data.scene = convertScene(data.ispc_scene);
data.traversable = rtcGetSceneTraversable(data.scene);
}

export void renderFrameStandard (uniform int* uniform pixels,
Expand Down
2 changes: 2 additions & 0 deletions tutorials/hair_geometry/hair_geometry_device.isph
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extern uniform Vec3fa g_ambient_intensity;
struct TutorialData
{
RTCScene scene;
RTCTraversable traversable;
uniform ISPCScene* uniform ispc_scene;
uniform Vec3f dirlight_direction;
uniform Vec3f dirlight_intensity;
Expand Down Expand Up @@ -47,6 +48,7 @@ namespace embree {
void TutorialData_Constructor(uniform TutorialData* uniform This)
{
This->scene = NULL;
This->traversable = NULL;
This->ispc_scene = g_ispc_scene;
This->dirlight_direction = make_Vec3f(g_dirlight_direction);
This->dirlight_intensity = make_Vec3f(g_dirlight_intensity);
Expand Down
7 changes: 4 additions & 3 deletions tutorials/instanced_geometry/instanced_geometry_device.ispc
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ Vec3f renderPixel(const uniform TutorialData& data, float x, float y, const unif
rtcInitIntersectArguments(&iargs);
iargs.feature_mask = (uniform RTCFeatureFlags) (FEATURE_MASK);

rtcIntersectV(data.g_scene,RTCRayHit_(ray),&iargs);
rtcTraversableIntersectV(data.g_traversable,RTCRayHit_(ray),&iargs);
RayStats_addRay(stats);

/* shade pixels */
Expand All @@ -186,7 +186,7 @@ Vec3f renderPixel(const uniform TutorialData& data, float x, float y, const unif
if (ray.instID[0] != RTC_INVALID_GEOMETRY_ID)
{
AffineSpace3f xfm;
rtcGetGeometryTransformFromScene(data.g_scene,ray.instID[0],0.0f,RTC_FORMAT_FLOAT3X4_COLUMN_MAJOR,&xfm);
rtcGetGeometryTransformFromTraversable(data.g_traversable,ray.instID[0],0.0f,RTC_FORMAT_FLOAT3X4_COLUMN_MAJOR,&xfm);
Ns = xfmNormal(xfm,Ns);
//Ns = xfmVector(data.normal_xfm[ray.instID[0]],Ns);
}
Expand All @@ -207,7 +207,7 @@ Vec3f renderPixel(const uniform TutorialData& data, float x, float y, const unif
rtcInitOccludedArguments(&sargs);
sargs.feature_mask = (uniform RTCFeatureFlags) (FEATURE_MASK);

rtcOccludedV(data.g_scene,RTCRay_(shadow),&sargs);
rtcTraversableOccludedV(data.g_traversable,RTCRay_(shadow),&sargs);
RayStats_addShadowRay(stats);

/* add light contribution */
Expand Down Expand Up @@ -341,6 +341,7 @@ export void device_render (uniform int* uniform pixels,
rtcCommitGeometry(g_instance2);
rtcCommitGeometry(g_instance3);
rtcCommitScene (data.g_scene);
data.g_traversable = rtcGetSceneTraversable(data.g_scene);
}

/* called by the C++ code for cleanup */
Expand Down
2 changes: 2 additions & 0 deletions tutorials/instanced_geometry/instanced_geometry_device.isph
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct TutorialData
/* scene data */
RTCScene g_scene;
RTCScene g_scene1;
RTCTraversable g_traversable;

uniform AffineSpace3f* uniform instance_xfm;
uniform LinearSpace3f* uniform normal_xfm;
Expand All @@ -31,6 +32,7 @@ void TutorialData_Constructor(uniform TutorialData* uniform This)
{
This->g_scene = NULL;
This->g_scene1 = NULL;
This->g_traversable = NULL;
This->instance_xfm = uniform new uniform AffineSpace3f[4];
This->normal_xfm = uniform new uniform LinearSpace3f[4];
This->colors = uniform new uniform Vec3f[4*4];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ extern "C" void device_init (char* cfg)

/* commit changes to scene */
rtcCommitScene (data.g_scene);

data.g_traversable = rtcGetSceneTraversable(data.g_scene);
}

Expand Down
5 changes: 3 additions & 2 deletions tutorials/intersection_filter/intersection_filter_device.ispc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void renderPixelStandard(const uniform TutorialData& data,
#if USE_ARGUMENT_CALLBACKS
iargs.filter = intersectionFilter;
#endif
rtcIntersectV(data.g_scene,RTCRayHit_(primary),&iargs);
rtcTraversableIntersectV(data.g_traversable,RTCRayHit_(primary),&iargs);
RayStats_addRay(stats);

/* shade pixels */
Expand All @@ -101,7 +101,7 @@ void renderPixelStandard(const uniform TutorialData& data,
#if USE_ARGUMENT_CALLBACKS
sargs.filter = occlusionFilter;
#endif
rtcOccludedV(data.g_scene,RTCRay_(shadow),&sargs);
rtcTraversableOccludedV(data.g_traversable,RTCRay_(shadow),&sargs);
RayStats_addShadowRay(stats);

/* add light contribution */
Expand Down Expand Up @@ -378,6 +378,7 @@ export void device_init (uniform int8* uniform cfg)

/* commit changes to scene */
rtcCommitScene (data.g_scene);
data.g_traversable = rtcGetSceneTraversable(data.g_scene);
}

/* task that renders a single screen tile */
Expand Down
2 changes: 2 additions & 0 deletions tutorials/intersection_filter/intersection_filter_device.isph
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
struct TutorialData
{
RTCScene g_scene;
RTCTraversable g_traversable;
uniform Vec3f* uniform colors;

RTCFilterFunctionN intersectionFilter;
Expand All @@ -15,6 +16,7 @@ struct TutorialData
inline void TutorialData_Constructor(uniform TutorialData* uniform This)
{
This->g_scene = NULL;
This->g_traversable = NULL;
This->colors = NULL;
This->intersectionFilter = NULL;
This->occlusionFilter = NULL;
Expand Down
6 changes: 6 additions & 0 deletions tutorials/ispc2cpp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,15 @@ sed -i.backup 's/RTCRay1/RTCRay/g' $2
sed -i.backup 's/rtcIntersectV/rtcIntersect1/g' $2
sed -i.backup 's/rtcOccludedV/rtcOccluded1/g' $2

sed -i.backup 's/rtcTraversableIntersectV/rtcTraversableIntersect1/g' $2
sed -i.backup 's/rtcTraversableOccludedV/rtcTraversableOccluded1/g' $2

sed -i.backup 's/rtcForwardIntersectV/rtcForwardIntersect1/g' $2
sed -i.backup 's/rtcForwardOccludedV/rtcForwardOccluded1/g' $2

sed -i.backup 's/rtcTraversableForwardIntersectV/rtcTraversableForwardIntersect1/g' $2
sed -i.backup 's/rtcTraversableForwardOccludedV/rtcTraversableForwardOccluded1/g' $2

sed -i.backup 's/rtcInterpolateV/rtcInterpolate/g' $2

sed -i.backup 's/Texture_FLOAT32/Texture::FLOAT32/g' $2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ export void device_init (uniform int8* uniform cfg)

/* commit changes to scene */
rtcCommitScene (g_scene);
data.g_traversable = rtcGetSceneTraversable(data.g_scene);
}

/* task that renders a single screen tile */
Expand All @@ -625,7 +626,7 @@ Vec3f renderPixel(const uniform TutorialData& data, float x, float y, const unif
iargs.intersect = sphereIntersectFuncN;
#endif

rtcIntersectV(data.g_scene,RTCRayHit_(ray),&iargs);
rtcTraversableIntersectV(data.g_traversable,RTCRayHit_(ray),&iargs);
RayStats_addRay(stats);

/* shade pixels */
Expand Down Expand Up @@ -662,7 +663,7 @@ Vec3f renderPixel(const uniform TutorialData& data, float x, float y, const unif
#if USE_ARGUMENT_CALLBACKS
sargs.occluded = sphereOccludedFuncN;
#endif
rtcOccludedV(data.g_scene,RTCRay_(shadow),&sargs);
rtcTraversableOccludedV(data.g_traversable,RTCRay_(shadow),&sargs);
RayStats_addShadowRay(stats);

/* add light contribution */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct TutorialData
uniform int frameID;

RTCScene g_scene;
RTCTraversable g_traversable;
uniform Vec3f* uniform face_colors;
uniform float g_time;

Expand Down Expand Up @@ -59,6 +60,7 @@ inline void TutorialData_Constructor(uniform TutorialData* uniform This)
{
This->frameID = 50;
This->g_scene = NULL;
This->g_traversable = NULL;
This->face_colors = uniform new uniform Vec3f[12];
This->g_time = 0;
This->g_accu = NULL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace embree {
#define FEATURE_MASK \
RTC_FEATURE_FLAG_TRIANGLE | \
RTC_FEATURE_FLAG_INSTANCE

RTCScene g_scene = nullptr;
TutorialData g_data;
extern "C" bool g_changed;
Expand Down
Loading

0 comments on commit 1968231

Please sign in to comment.