Skip to content

Commit

Permalink
ISSUE-37: Fixed a bug in the path tracer
Browse files Browse the repository at this point in the history
The final segment of the light path was being discarded
#37
  • Loading branch information
4rknova committed Oct 17, 2018
1 parent 274a631 commit 5c6c68e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion scene/5.2.scn
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ material = {
}

light = {
type = lambert
type = emissive
properties = {
samplers = {
emissive = {
Expand Down
16 changes: 11 additions & 5 deletions scene/5.3.scn
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ version = 0.2
environment = {
type = gradient
config = {
a = col3(0.5,0.5,0.5)
b = col3(0.4,0.4,0.4)
# a = col3(0.3,0.5,0.9)
# b = col3(1.0,1.0,1.0)
a = col3(0,0,0);
b = col3(0,0,0);
}
}

Expand Down Expand Up @@ -94,6 +96,10 @@ material = {
type = color
value = col3(1,1,1)
}
diffuse = {
type = color
value = col3(0,0,0)
}
}
}
}
Expand Down Expand Up @@ -123,10 +129,10 @@ material = {
}

light = {
type = emissive
type = emissive
properties = {
samplers = {
emissive = {
emissive = {
type = color
value = col3(1,1,1)
}
Expand All @@ -139,7 +145,7 @@ material = {
properties = {
scalars = {
exponent = 256
reflectance = 1
reflectance = .5
}

samplers = {
Expand Down
2 changes: 1 addition & 1 deletion scene/5.5.scn
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ version = 0.1
environment = {
type = color
config = {
value = col3(1,1,1)
value = col3(0,0,0)
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/xtcore/integrator/pathtracer/integrator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,21 @@ nimg::ColorRGBf Integrator::eval(size_t depth, hit_result_t &in)
bool hit = ctx->scene.intersection(in.ray, hit_record);
hit_record.ior = in.ior;


if (hit) {
nimg::ColorRGBf value;

const xtcore::asset::IMaterial *m = ctx->scene.get_material(hit_record.id_object);

xtcore::hit_result_t hit_result;
bool path_continues = m->sample_path(hit_result, hit_record);

value = in.intensity * hit_result.intensity;

if (path_continues) {
in.intensity = hit_result.intensity * eval(--depth, hit_result);
value *= eval(--depth, hit_result);
}
return in.intensity;
return value;
}

return ctx->scene.sample_environment(in.ray.direction);
Expand Down

0 comments on commit 5c6c68e

Please sign in to comment.