... | ... |
@@ -19,6 +19,7 @@ using namespace glm; |
19 | 19 |
/// Constants |
20 | 20 |
|
21 | 21 |
auto const infinity = std::numeric_limits<float>::infinity(); |
22 |
+auto const delta = 0.001F; |
|
22 | 23 |
|
23 | 24 |
/// Types |
24 | 25 |
|
... | ... |
@@ -28,6 +29,15 @@ struct Ray |
28 | 29 |
vec3 origin; |
29 | 30 |
vec3 direction; |
30 | 31 |
float range; |
32 |
+ vec3 point(float distance) const |
|
33 |
+ { |
|
34 |
+ return origin + direction * distance; |
|
35 |
+ } |
|
36 |
+ Ray resumed(float distance) const |
|
37 |
+ { |
|
38 |
+ distance += delta; |
|
39 |
+ return {point(distance), direction, range - distance}; |
|
40 |
+ } |
|
31 | 41 |
}; |
32 | 42 |
|
33 | 43 |
//// Trace |
... | ... |
@@ -254,10 +264,16 @@ int main(int argc, char const * argv[]) |
254 | 264 |
//// Render |
255 | 265 |
framebuffer.render(viewport, depth_range, [&](vec4 const & frag_coord) |
256 | 266 |
{ |
257 |
- auto const ray = camera.ray(frag_coord, depth_range); |
|
258 |
- auto const trace = scene.trace(ray); |
|
259 |
- auto const rgb = vec3(1.0F / (1.0F + trace.distance)); |
|
260 |
- auto const alpha = (bool)trace; |
|
267 |
+ auto ray = camera.ray(frag_coord, depth_range); |
|
268 |
+ auto trace = Trace{}; |
|
269 |
+ auto traces = 0; |
|
270 |
+ while ((trace = scene.trace(ray))) |
|
271 |
+ { |
|
272 |
+ ++traces; |
|
273 |
+ ray = ray.resumed(trace.distance); |
|
274 |
+ } |
|
275 |
+ auto const rgb = vec3(1.0F / (1.0F + (float)traces)); |
|
276 |
+ auto const alpha = (bool)traces; |
|
261 | 277 |
return vec4(rgb, alpha); |
262 | 278 |
}); |
263 | 279 |
//// Finalize |