diff options
Diffstat (limited to 'src/cl')
-rw-r--r-- | src/cl/spirt.cl | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/src/cl/spirt.cl b/src/cl/spirt.cl index 12022bb..26bdf00 100644 --- a/src/cl/spirt.cl +++ b/src/cl/spirt.cl @@ -13,21 +13,51 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#define RAY_ORIG(RAYS, INDEX) (RAYS[INDEX]) +#define RAY_DIR(RAYS, INDEX) (RAYS[INDEX + 1]) + +__kernel void +gen_rays(__global float3 *const rays, float3 camera_centre, + float3 pixel_delta_u, float3 pixel_delta_v, float3 corner00) +{ + size_t idx, w, i, j; + + w = get_global_size(0); + + i = get_global_id(0); + j = get_global_id(1); + + idx = (w * j + i) * 2; + + RAY_ORIG(rays, idx) = camera_centre; + RAY_DIR(rays, idx) = corner00 + + ((i * pixel_delta_u) + (j * pixel_delta_v)) - + camera_centre; +} + __kernel void -hello(__global unsigned char *const canvas) +ray_colour(__global uchar *const canvas, __global float3 *const rays) { - size_t idx, w, h, i, j; + size_t canvas_idx, ray_idx, w, i, j; + float3 unit_direction, colour; + float a; w = get_global_size(0); - h = get_global_size(1); i = get_global_id(0); j = get_global_id(1); - idx = (w * j + i) * 4; + canvas_idx = (w * j + i) * 4; + ray_idx = (w * j + i) * 2; + + unit_direction = normalize(RAY_DIR(rays, ray_idx)); + a = 0.5f * (unit_direction.y + 1.0f); + + colour = (1.0f - a) * (float3)(1.0f) + a * (float3)(0.5f, 0.7f, 1.0f); + colour = 256.0f * clamp(sqrt(colour), 0.0f, 0.999f); - canvas[idx] = (unsigned char)((255 * i) / (w - 1)); - canvas[idx + 1] = (unsigned char)((255 * j) / (h - 1)); - canvas[idx + 2] = 63; - canvas[idx + 3] = 255; + canvas[canvas_idx] = colour.x; + canvas[canvas_idx + 1] = colour.y; + canvas[canvas_idx + 2] = colour.z; + canvas[canvas_idx + 3] = 255; } |