Skip to content
This repository has been archived by the owner on Nov 26, 2022. It is now read-only.

Commit

Permalink
Fix off by one error in tile rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
raywan committed May 23, 2019
1 parent b7d2e0f commit c39b286
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 8 deletions.
5 changes: 3 additions & 2 deletions TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ Build:
[x] build.bat for Windows
[x] Create Windows entry point i.e. win32_main.cpp


Uncategorized:
[ ] Fix off by one error in tile compositing @BUG
[ ] Tile size independent multithreaded rendering
Height and width are must be multiples of the tile size currently
[ ] Add transform to Mesh
[ ] Use memory arena for allocations
[ ] Render suzanne
[ ] Render Cornell Box

Miscellaneous:
[x] Fix off by one error in tile compositing @BUG @done (19-05-23 13:31)
4 changes: 2 additions & 2 deletions src/bvh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ BVHNode *bvh_recursive_build(BVHPrimitive *prims, int n, int *total_nodes) {
BVHNode *bvh_build(World *world) {
world->bvh_prims = bvh_preprocess_world(world);
std::vector<BVHPrimitive> bvh_prims_work_copy = world->bvh_prims;
printf("total prims: %llu\n", world->bvh_prims.size());
printf("Total prims: %llu\n", world->bvh_prims.size());
print_prims(world->bvh_prims.data(), world->bvh_prims.size());
int total_nodes = 0;
BVHNode *root = bvh_recursive_build(bvh_prims_work_copy.data(), world->bvh_prims.size(), &total_nodes);
printf("total nodes: %d\n", total_nodes);
printf("Total nodes: %d\n", total_nodes);
return root;
}

Expand Down
2 changes: 1 addition & 1 deletion src/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define BIAS 0.0001f
#define REFRACT_BIAS 0.00001f

#define MAX_DEPTH 2
#define MAX_DEPTH 5
#define SAMPLES_PER_PIXEL 4

#define USE_GLOBAL_ILLUMINATION 0
Expand Down
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <rw/rw_time.h>
#define RWM_IMPLEMENTATION
#include <rw/rw_math.h>
#define RWTR_IMPLEMENTATION
#include <rw/rw_transform.h>

#include "render.h"
#include "mesh.h"
Expand Down Expand Up @@ -80,7 +82,6 @@ int main(int argc, char *argv[]) {
// Intialize scene
World world;
create_world(&world);
world.bvh_prims = bvh_preprocess_world(&world);

int *data = (int *) malloc(WIDTH * HEIGHT * sizeof(int));
int *cur_data = data;
Expand Down
2 changes: 1 addition & 1 deletion src/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void render(WorkerData *data, Tile t) {
for (int i = 0; i < TILE_Y; i++) {
for (int j = 0; j < TILE_X; j++) {
int x = (int) t.top_right.x + j;
int y = (int) t.top_right.y + TILE_Y - 1 - i;
int y = (int) t.top_right.y + TILE_Y - i;
Vec3 color = rwm_v3_zero();
for (int s = 0; s < SAMPLES_PER_PIXEL; s++) {
float s1 = SAMPLES_PER_PIXEL > 1 ? spp_distribution(generator) : 0;
Expand Down
1 change: 0 additions & 1 deletion src/win32_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ int main(int argc, char *argv[]) {
// Intialize scene
World world;
create_world(&world);
world.bvh_root = bvh_build(&world);

int *data = (int *) malloc(WIDTH * HEIGHT * sizeof(int));
int *cur_data = data;
Expand Down
3 changes: 3 additions & 0 deletions src/world.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "world.h"
#include <rw/rw_transform.h>

#include "bvh.h"

void create_world(World *world) {
printf("Loading OBJ files:\n\t");

Expand Down Expand Up @@ -69,4 +71,5 @@ void create_world(World *world) {
});
#endif

world->bvh_root = bvh_build(world);
}

0 comments on commit c39b286

Please sign in to comment.