Ok experts, lets see if you can help with this then, here’s my code:
[codebox]device RGBColour reflectiveShade(ShadeRec& sr)
{
RGBColour L;
L = specularShade(sr); // direct illumination
float3 wo, wi;
RGBColour fr;
wo = -sr.ray.d;
Ray reflected_ray[3];
fr = reflectiveF(sr, wo, wi);
reflected_ray[0].o = sr.hitPoint;
reflected_ray[0].d = wi;
RGBColour temp;
temp.r = 0; temp.g = 0; temp.b = 0;
for(int i = 0; i < vp.maxDepth -1; i++)
{
sr = hitObjects(reflected_ray[i]);
if (sr.hitAnObject)
{
sr.ray = reflected_ray[i];
wo = -sr.ray.d;
fr = reflectiveF(sr, wo, wi);
reflected_ray[i+1].o = sr.hitPoint;
reflected_ray[i+1].d = wi;
}
else
{
reflected_ray[i+1].d.x = 0.0f;
}
}
for(int i = 0; i < vp.maxDepth; i++)
{
if(reflected_ray[i].d.x != 0.0f)
{
sr = hitObjects(reflected_ray[i]);
if (sr.hitAnObject)
{
sr.ray = reflected_ray[i];
temp = specularShade(sr); // direct illumination
wo = -sr.ray.d;
fr = reflectiveF(sr, wo, wi);
temp += max_to_one(fr * temp * (dot(sr.normal, wi)));
L += max_to_one(fr * temp * (dot(sr.normal, wi)));
}
}
}
return (L);
}[/codebox]
I’m trying to store rays on a “stack” with an array of Rays being placed in local memory for each thread. But it seems each thread is using the same memory space for the ray array and its buggering up the values - this doesn’t happen in the emuDebug mode, so it obviously a race condition. How do I get the ray array to stay local to the thread and not global to all threads? Anyone got any tips/ advice?