Add Framwork for Assignment 3
This commit is contained in:
parent
a2d7f5c414
commit
c864d2a42f
14 changed files with 50048 additions and 48111 deletions
|
|
@ -185,14 +185,8 @@ void Application::deviceRender(const ISPCCamera& camera) {
|
|||
}
|
||||
|
||||
/* create accumulator */
|
||||
if (data.accu_width != width || data.accu_height != height) {
|
||||
alignedUSMFree(data.accu);
|
||||
data.accu = (Vec3ff *) alignedUSMMalloc((width * height) * sizeof(Vec3ff), 16,
|
||||
EMBREE_USM_SHARED_DEVICE_READ_WRITE);
|
||||
data.accu_width = width;
|
||||
data.accu_height = height;
|
||||
for (unsigned int i = 0; i < width * height; i++)
|
||||
data.accu[i] = Vec3ff(0.0f);
|
||||
if (data.film.width != width || data.film.height != height) {
|
||||
data.film.init(width, height);
|
||||
}
|
||||
|
||||
/* reset accumulator */
|
||||
|
|
@ -208,13 +202,14 @@ void Application::deviceRender(const ISPCCamera& camera) {
|
|||
g_accu_p = camera.xfm.p;
|
||||
|
||||
if (camera_changed) {
|
||||
data.accu_count = 0;
|
||||
for (unsigned int i = 0; i < width * height; i++)
|
||||
data.accu[i] = Vec3ff(0.0f);
|
||||
resetRender();
|
||||
} else
|
||||
data.accu_count++;
|
||||
|
||||
data.frame_count++;
|
||||
}
|
||||
|
||||
|
||||
void Application::renderInteractive() {
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
glfwPollEvents();
|
||||
|
|
@ -243,6 +238,8 @@ void Application::displayFunc() {
|
|||
/* render image using ISPC */
|
||||
initRayStats();
|
||||
render((int *) pixels, width, height, time, ispccamera);
|
||||
data.film.writeToFramebuffer(pixels);
|
||||
|
||||
double dt0 = getSeconds() - t0;
|
||||
if (ispccamera.render_time != 0.0) dt0 = ispccamera.render_time;
|
||||
avg_render_time.add(dt0);
|
||||
|
|
@ -270,6 +267,10 @@ void Application::displayFunc() {
|
|||
ImGui::Checkbox("Accumulate", &g_accumulate);
|
||||
ImGui::InputInt("SPP", &data.spp);
|
||||
|
||||
if (ImGui::Button("Reset")) {
|
||||
resetRender();
|
||||
};
|
||||
|
||||
double render_dt = avg_render_time.get();
|
||||
double render_fps = render_dt != 0.0 ? 1.0f / render_dt : 0.0;
|
||||
ImGui::Text("Render: %3.2f fps", render_fps);
|
||||
|
|
@ -332,27 +333,22 @@ void Application::renderTile(int taskIndex, int threadIndex, int* pixels, const
|
|||
|
||||
for (unsigned int y = y0; y < y1; y++)
|
||||
for(unsigned int x = x0; x < x1; x++) {
|
||||
RandomSampler sampler;
|
||||
RandomSamplerWrapper sampler;
|
||||
Vec3fa L = Vec3fa(0.0f);
|
||||
|
||||
for (int i=0; i<data.spp; i++)
|
||||
{
|
||||
RandomSampler_init(sampler, x, y, data.accu_count*data.spp+i);
|
||||
sampler.init(x, y, (data.frame_count) * data.spp + i);
|
||||
|
||||
/* calculate pixel color */
|
||||
float fx = x + RandomSampler_get1D(sampler);
|
||||
float fy = y + RandomSampler_get1D(sampler);
|
||||
/* calculate pixel color */
|
||||
float fx = x + sampler.get1D();
|
||||
float fy = y + sampler.get1D();
|
||||
L = L + renderPixel(fx,fy,camera,g_stats[threadIndex],sampler);
|
||||
}
|
||||
L = L/(float)data.spp;
|
||||
|
||||
/* write color to framebuffer */
|
||||
Vec3ff accu_color = data.accu[y*width+x] + Vec3ff(L.x,L.y,L.z,1.0f); data.accu[y*width+x] = accu_color;
|
||||
float f = rcp(max(0.001f,accu_color.w));
|
||||
unsigned int r = (unsigned int) (255.01f * clamp(accu_color.x*f,0.0f,1.0f));
|
||||
unsigned int g = (unsigned int) (255.01f * clamp(accu_color.y*f,0.0f,1.0f));
|
||||
unsigned int b = (unsigned int) (255.01f * clamp(accu_color.z*f,0.0f,1.0f));
|
||||
pixels[y*width+x] = (b << 16) + (g << 8) + r;
|
||||
data.film.addSplat(x, y, L);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue