From now i cannot run my code and it’s debugging don’t give me enough information to contiune my development.
Can you reproduce that printf(“ok”) don’t show anithing when uncomment access to sphereColor data?
global void RayTracing_Image(long countPerThread, long long count, double t0, long* pixels, long width, long height, long sphereCount, double* xSphere, double* ySphere, double* zSphere, double* sphereRadius, long* sphereColor, double lx, double ly, double lz, double PI)
{
long threadIdx_ = threadIdx.x;
for (long i = 0; i < countPerThread; i++)
{
long long idx = threadIdx_ * countPerThread + i;
if (idx >= count) break;
double
x = ((long)idx % width - width / 2) / ((double)height / 2),
y = -((long)idx / width - height / 2) / ((double)height / 2),
z = 1;
double ox = 0, oy = 0, oz = 0;
double nx = 0, ny = 0, nz = 0;
long r = 0, g = 0, b = 0;
long reflectionCount = 0;
while (true)
{
double _distance = (double)(1 << 20);
long sphereIndex = -1;
for (long j = 0; j < sphereCount; j++)
{
double distance = intersect(ox, oy, oz, x, y, z, xSphere[j], ySphere[j], zSphere[j], sphereRadius[j], PI);
if (distance != -1 && distance < _distance)
{
sphereIndex = j;
_distance = distance;
}
}
if (sphereIndex != -1)
{
normalize(x, y, z, &x, &y, &z);
ox += x * _distance;
oy += y * _distance;
oz += z * _distance;
printf("ok");
/*r += (sphereColor[sphereIndex] & (255 << 16)) >> 16;
g += (sphereColor[sphereIndex] & (255 << 8)) >> 8;
b += (sphereColor[sphereIndex] & 255);*/
intersectionNormalDirection(ox, oy, oz, xSphere[sphereIndex], ySphere[sphereIndex], zSphere[sphereIndex], &nx, &ny, &nz);
reflectRay(x, y, z, nx, ny, nz, &x, &y, &z);
reflectionCount++;
}
else
{
if (reflectionCount > 0)
{
double luminosity = luminosityFactor(nx, ny, nz, lx, ly, lz, PI);
/* r = (long)(r * luminosity / reflectionCount);
g = (long)(g * luminosity / reflectionCount);
b = (long)(b * luminosity / reflectionCount);*/
pixels[idx] = 255 << 24 | (long)r << 16 | (long)g << 8 | (long)b;
}
else pixels[idx] = 255 << 24;
break;
}
}
}
}
However, that run correctly :
global void RayTracing_Image(long countPerThread, long long count, double t0, long* pixels, long width, long height, long sphereCount, double* xSphere, double* ySphere, double* zSphere, double* sphereRadius, long* sphereColor, double lx, double ly, double lz, double PI)
{
long threadIdx_ = threadIdx.x;
for (long i = 0; i < countPerThread; i++)
{
long long idx = threadIdx_ * countPerThread + i;
if (idx >= count) break;
double
x = ((long)idx % width - width / 2) / ((double)height / 2),
y = -((long)idx / width - height / 2) / ((double)height / 2),
z = 1;
double ox = 0, oy = 0, oz = 0;
double nx = 0, ny = 0, nz = 0;
long r = 0, g = 0, b = 0;
double _distance = (double)(1 << 20);
long sphereIndex = -1;
for (long j = 0; j < sphereCount; j++)
{
double distance = intersect(ox, oy, oz, x, y, z, xSphere[j], ySphere[j], zSphere[j], sphereRadius[j], PI);
if (distance != -1 && distance < _distance)
{
sphereIndex = j;
_distance = distance;
}
}
if (sphereIndex != -1)
{
normalize(x, y, z, &x, &y, &z);
ox += x * _distance;
oy += y * _distance;
oz += z * _distance;
r += (sphereColor[sphereIndex] & (255 << 16)) >> 16;
g += (sphereColor[sphereIndex] & (255 << 8)) >> 8;
b += (sphereColor[sphereIndex] & 255);
intersectionNormalDirection(ox, oy, oz, xSphere[sphereIndex], ySphere[sphereIndex], zSphere[sphereIndex], &nx, &ny, &nz);
reflectRay(x, y, z, nx, ny, nz, &x, &y, &z);
double luminosity = luminosityFactor(nx, ny, nz, lx, ly, lz, PI);
r = (long)(r * luminosity);
g = (long)(g * luminosity);
b = (long)(b * luminosity);
pixels[idx] = 255 << 24 | (long)r << 16 | (long)g << 8 | (long)b;
}
else pixels[idx] = 255 << 24;
}
}