1
0
Fork 0

Pridany trasovanie tiena

master
Dušan Poizl 9 years ago
parent 0bc917fb7c
commit ff83197bf1
  1. 26
      intersect_kernel.cl
  2. 2888
      mesh.obj

@ -1,3 +1,5 @@
#pragma OPENCL EXTENSION cl_amd_printf : enable
typedef struct
{
float3 min, max;
@ -122,16 +124,32 @@ __kernel void aabb_traverse(__global float3 *vertexs, __global uint3 *faces, __w
int2 gid = (int2)(get_global_id(0), get_global_id(1));
int2 gsize = (int2)(get_global_size(0), get_global_size(1));
float3 view = (float3)(convert_float2(gid), 0.5f);
float3 view = (float3)(convert_float2(gid), -1.5f);
view.xy /= convert_float2(gsize);
view.xy -= (float2)(0.5f);
float3 lightPos = (float3)(xy, 3);
Ray ray;
ray.origin = (float3)(xy, -4);
ray.origin = (float3)(0, 0, 6);
ray.dir = view;
float min_t = traverseAABB(ray, vertexs, faces, nodes);
float t = traverseAABB(ray, vertexs, faces, nodes);
float s = INFINITY;
float3 hit;
if(isfinite(t))
{
Ray shadowRay;
hit = t*ray.dir+ray.origin;
shadowRay.origin = lightPos;
shadowRay.dir = hit - lightPos;
s = traverseAABB(shadowRay, vertexs, faces, nodes);
}
if(isfinite(min_t))write_imagef(output, gid, (float4)(1, 1, 1, 1));
if(s>0.99999f && s<1.00001f)write_imagef(output, gid, (float4)(0, 1, 0, 1));
else if(isfinite(t))write_imagef(output, gid, (float4)(1, 0, 0, 1));
else write_imagef(output, gid, (float4)(0, 0, 0, 1));
}

2888
mesh.obj

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save