#include "Renderer.h" #include "../utils/cuda.h" /// Dispatch (n_rays, -) __global__ void cu_render(glm::vec4 *o_colors, glm::vec4 *layeredColors, uint samples, uint nRays) { glm::uvec3 idx3 = IDX3; uint rayIdx = idx3.x; if (rayIdx >= nRays) return; glm::vec4 outColor; for (int si = samples - 1; si >= 0; --si) { glm::vec4 c = layeredColors[rayIdx * samples + si]; outColor = outColor * (1 - c.a) + c * c.a; } outColor.a = 1.0f; o_colors[idx3.x] = outColor; } Renderer::Renderer() {} void Renderer::render(sptr> o_colors, sptr> layeredColors) { dim3 blkSize(1024); dim3 grdSize(ceilDiv(o_colors->n(), blkSize.x)); CU_INVOKE(cu_render) (*o_colors, *layeredColors, layeredColors->n() / o_colors->n(), o_colors->n()); CHECK_EX(cudaGetLastError()); }