Whenever I pass my Ray struct as a pointer to be set by a function, I get a very long seemly random number half the time and the correct answer the other half.
typedef struct
{
float4 dir;
float4 pos;
}Ray;
float4 rayGetPoint(const Ray* ray,float t)
{
return ray->pos+ray->dir*t;
}
kernel void radiance(global float* image)
{
const float PI = 3.14159265359f;
Ray r = {{0.f,0.f,1.f,0.f},{0.f,0.f,-10.f,0.f}};
//float4 scale = {1.f,1.f,1.f,1.f};
//float4 rot = quatAxisAngle(PI/2.f,(float4)(1.f,0.f,0.f,0.f));
//float4 translate = {0.f,0.f,0.f,0.f};
float4 color = rayGetPoint(&r,5.f);
int i;
for(i=0;i<4;)
{
image[i++] = color.x;
image[i++] = color.y;
image[i++] = color.z;
image[i++] = color.w;
}
}
At first I was getting something like -2843472074729924.0000 0.0000 0.0000 0.0000. Then, the program started outputting 0.000 0.000 -5.000 0.0000 without any changes to the code. Does anyone have an explanation for this?