clray
diff rt.cl @ 4:3c95d568d3c7
wow a ball
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 15 Jul 2010 07:37:05 +0300 |
parents | 88ac4eb2d18a |
children | 9f0ddb701882 |
line diff
1.1 --- a/rt.cl Tue Jul 13 03:38:29 2010 +0300 1.2 +++ b/rt.cl Thu Jul 15 07:37:05 2010 +0300 1.3 @@ -7,7 +7,8 @@ 1.4 struct Sphere { 1.5 float4 pos; 1.6 float radius; 1.7 - float4 color; 1.8 + float4 kd, ks; 1.9 + float spow, kr, kt; 1.10 }; 1.11 1.12 struct Light { 1.13 @@ -21,34 +22,44 @@ 1.14 struct SurfPoint { 1.15 float t; 1.16 float3 pos, norm; 1.17 + global const struct Sphere *obj; 1.18 }; 1.19 1.20 #define EPSILON 1e-6 1.21 1.22 -bool intersect(struct Ray ray, __global const struct Sphere *sph, struct SurfPoint *sp); 1.23 +float4 shade(struct Ray ray, struct SurfPoint sp); 1.24 +bool intersect(struct Ray ray, global const struct Sphere *sph, struct SurfPoint *sp); 1.25 1.26 -__kernel void render(__global float4 *fb, 1.27 - __global const struct RendInfo *rinf, 1.28 - __global const struct Sphere *sphlist, 1.29 - __global const struct Light *lights, 1.30 - __global const struct Ray *primrays) 1.31 + 1.32 +kernel void render(global float4 *fb, 1.33 + global const struct RendInfo *rinf, 1.34 + global const struct Sphere *sphlist, 1.35 + global const struct Light *lights, 1.36 + global const struct Ray *primrays) 1.37 { 1.38 int idx = get_global_id(0); 1.39 1.40 struct Ray ray = primrays[idx]; 1.41 - struct SurfPoint sp; 1.42 + struct SurfPoint sp, sp0; 1.43 1.44 - if(intersect(ray, sphlist, &sp)) { 1.45 - fb[idx] = (float4)(1, 0, 0, 1); 1.46 - } else { 1.47 - fb[idx] = (float4)(0, 0, 0, 1); 1.48 + sp0.t = FLT_MAX; 1.49 + 1.50 + for(int i=0; i<rinf->num_sph; i++) { 1.51 + if(intersect(ray, sphlist, &sp) && sp.t < sp0.t) { 1.52 + sp0 = sp; 1.53 + } 1.54 } 1.55 1.56 - fb[idx] = primrays[idx].dir * 0.5 + 0.5; 1.57 + fb[idx] = shade(ray, sp0); 1.58 +} 1.59 + 1.60 +float4 shade(struct Ray ray, struct SurfPoint sp) 1.61 +{ 1.62 + return sp.obj->kd; 1.63 } 1.64 1.65 bool intersect(struct Ray ray, 1.66 - __global const struct Sphere *sph, 1.67 + global const struct Sphere *sph, 1.68 struct SurfPoint *sp) 1.69 { 1.70 float3 dir = ray.dir.xyz;