Skip to content

Commit

Permalink
?
Browse files Browse the repository at this point in the history
  • Loading branch information
yghannam committed Apr 16, 2013
1 parent 078f3be commit 1e4ee5e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
40 changes: 16 additions & 24 deletions TermProjectC/TermProjectC/kernels.cl
Original file line number Diff line number Diff line change
Expand Up @@ -269,37 +269,22 @@ __kernel void getPixelColor(
ray.d = worldRay.d;

Intersection intersection;


intersection
= intersect(true, ray, numShapes, shapeData);

if (false){//intersection.t < INFINITY){
= intersect(false, ray, numShapes, shapeData);

float3 Intensity = clamp(dot(intersection.N, normalize(lightDir)), 0.f, 1.f);
if (intersection.t < INFINITY)
{
//printf("reflect: %2.2f\n", intersection.reflect);

float3 Intensity = clamp(dot(intersection.N, normalize(lightDir)), 0.f, 1.f) + clamp(dot(intersection.N, normalize(-lightDir)), 0.f, 1.f);

uchar red = (uchar) round(255*Intensity.x);
uchar green = (uchar) round(255*Intensity.y);
uchar blue = (uchar) round(255*Intensity.z);
color = (uchar4)(red, green, blue, 255);

}
else
{
intersection
= intersect(false, ray, numShapes, shapeData);

if (intersection.t < INFINITY){

//printf("reflect: %2.2f\n", intersection.reflect);

float3 Intensity = clamp(dot(intersection.N, normalize(lightDir)), 0.f, 1.f) + clamp(dot(intersection.N, normalize(-lightDir)), 0.f, 1.f);


uchar red = (uchar) round(255*Intensity.x);
uchar green = (uchar) round(255*Intensity.y);
uchar blue = (uchar) round(255*Intensity.z);
color = (uchar4)(red, green, blue, 255);
}
}

raster[row * columns + col] = color;
}
Expand All @@ -319,6 +304,13 @@ __kernel void moveShapes(
else
shapeData[i].x -= 0.1;
}
else if(i > 0 && i%2 == 0)
{
if(shapeData[i].w == -1.f)
shapeData[i].y += 0.1;
else
shapeData[i].y -= 0.1;
}
else
{
if(shapeData[i].w == -1.f)
Expand All @@ -327,7 +319,7 @@ __kernel void moveShapes(
shapeData[i].x -= 0.1;
}

if(shapeData[i].x > 3.f || shapeData[i].x < -3.f)
if(shapeData[i].x > 3.f || shapeData[i].x < -3.f || shapeData[i].y > 3.f)
shapeData[i].w *= -1.f;
}
}
4 changes: 2 additions & 2 deletions TermProjectC/TermProjectC/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ void InitializeCL()
/*err = clEnqueueAcquireGLObjects(cQ, 1, &rbo_buf, 0, NULL, NULL);
CheckError(err, "Acquire GL Objects");*/

int numShapes = 2;
float shapeData[] = {1.5, 0.0, 0.0, 1.0, -1.5, 0.0, 0.0, 1.0};
int numShapes = 3;
float shapeData[] = {1.5, 0.0, 0.0, 1.0, -1.5, 0.0, 0.0, 1.0, 0, 1.5, 0.0, 1.0};
cl_mem shape_buf = clCreateBuffer(context, CL_MEM_READ_WRITE, numShapes*4*4, NULL, &err);
CheckError(err, "Create Shape Buffer");
pixel_buf = clCreateBuffer(context, CL_MEM_READ_WRITE, width*height*4, NULL, &err);
Expand Down

0 comments on commit 1e4ee5e

Please sign in to comment.