Hi
I have a simple ray sphere intersect function that works fine in c but when i try to run it in an opencl kernel, it doesnt work. Having a seriously hard time because i cant debug the kernel and see the problem. Am i making a simple error in my conversion to opencl?
C Code
float hitSphere(vector3 center, float radius, ray r)
{
vector3 oc = subtract_Vecs(&r.origin, ¢er);
float a = dot(&r.direction, &r.direction);
float b = 2 * dot(&oc, &r.direction);
float c = dot(&oc, &oc) - radius*radius;
float d = b*b - 4 * a*c;
if (d < 0)
return -1.0;
else
return (-b - sqrt(d)) / (2.0*a);
}
OpenCL
float hitSphere(float3 center, float radius, struct Ray r)
{
float3 oc = r.origin - center;
float a = dot(r.dir, r.dir);
float b = 2 * dot(oc, r.dir);
float c = dot(oc, oc) - (radius*radius);
float d = b*b - 4 * a*c;
if(d<0)
return -1.0;
else
return (-b - sqrt(d)/(2.0*a));
}
Thanks for any help