Renderer.cu 890 Bytes
Newer Older
Nianchen Deng's avatar
Nianchen Deng committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#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<CudaArray<glm::vec4>> o_colors,
                      sptr<CudaArray<glm::vec4>> 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());
}