Commit Graph

330 Commits

Author SHA1 Message Date
646139efda Factor out ray computations that are shared for all triangles. 2019-07-06 09:19:53 +09:00
4b612e2d1a Leaf triangle intersection now loops over triangles per ray.
This is the inverse of what was being done before, which was to
loop over all of the rays for each triangle.  At the moment, this
actually appears to be a tiny bit slower, but it should allow
for future optimizations testing against multiple triangles at once.
2019-07-06 09:01:24 +09:00
4f7335db8c Misc optimizations that add up to a nice speed boost. 2019-06-29 14:20:32 +09:00
c4b8971805 Clean up compiler warnings. 2019-06-29 12:43:24 +09:00
2a0ca001e2 Optimized ray stack task duplication with memcopy. 2019-06-29 12:39:28 +09:00
68fba19fc6 Removed a timer from a hot loop, and fixed node-test stat.
Gives I small performance boost, and now ray/node tests are
actually reported correctly.  Yay!
2019-06-29 09:46:39 +09:00
5a53d7f6f6 Added some additional ray tracing stats. 2019-06-29 09:20:04 +09:00
14b16896ac Fix some compiler warnings. 2019-06-29 08:41:11 +09:00
4ef376dc89 Move multiple-object logic out of BVH4.
This allows each part of Psychopath tp handle the logic in the
best way, instead of a one-size-fits-all approach.
2019-06-29 08:28:41 +09:00
b09f9684d1 Remove non-SIMD BVH4, and keep more bool calculations in SIMD format. 2019-06-29 07:22:22 +09:00
c5d23592b9 Keep Bool4 in its native format instead of converting to a bitmask.
This gives a small performance boost.
2019-06-28 22:56:51 +09:00
2fddcae0fd Reduced the size of a hot return value.
Gives a small performance boost.
2019-06-28 22:22:41 +09:00
aed0f2ede1 Implemented a SIMD version of the BVH4.
It does indeed appear to be faster with this style of traversal!
2019-06-28 21:57:29 +09:00
50f9fd851b Improved ray batch data layout.
Gives a small performance boost.
2019-06-25 18:49:10 +09:00
5dd8eb919b Changed ray batch data access to be through methods.
This is (potentially) just temporary.  It's to make it a bit easier
to play with data layout to see how that affects performance.
2019-06-25 17:31:51 +09:00
eef29c2b2f Type alias for the ray index type.
Makes things easier to play with.
2019-06-23 19:26:30 +09:00
630a79aca5 Initial implementation of ORST traversal.
This is a "just get it working" implementation.  Performance
optimizations still need to be done.
2019-06-23 18:40:52 +09:00
1a29b16aa2 Sketching out the structures for ray traversal tracking. 2019-06-22 04:19:55 +09:00
3d4ac7f57b Created a RayBatch type, which stores multiple rays is SoA layout. 2019-06-21 23:02:44 +09:00
c6a8f93097 Run rustfmt. No functional change. 2019-06-21 21:47:53 +09:00
50f09a6134 Removed full Jakob implementation and moved table loading to build time.
The "light" version of Jakob still remains, which uses a much smaller
table.
2019-06-21 21:45:13 +09:00
48e015996f Initial implementation of Jakob 2019 spectral upsampling.
It has a slight color cast to it at the moment, I believe due to
incorrect color space conversions, not because of the upsampling
method itself.  So Meng upsampling is still the active method
at the moment.
2019-06-09 19:51:43 +09:00
4aa002bb92 Reorganizing spectral upsampling crate for multiple algorithms. 2019-06-08 18:25:35 +09:00
fdad8f71bb Renamed spectral upsampling sub-crate. 2019-06-02 07:28:43 +09:00
764bdbeb06 MicropolyBatch doesn't need to satisfy Surface trait.
Eventually the Surface trait will be changed to actually mean the
ability to be processed _into_ a MicropolyBatch.  So it's ultimately
nonsensical for MicropolyBatch to implement it.
2018-12-29 10:18:38 -08:00
112f94c127 Implemented a "Micropolygon Batch" type.
This is in prep for a shade-before-hit architecture.  The type is
currently unused and untested.
architecture.
2018-12-28 13:40:36 -08:00
8e109efed5 Fixed compiler warnings. 2018-12-28 11:09:17 -08:00
1cd5d28767 Added another color temperature based way of specifying color.
This uses a normalized version of blackbody radiation, so the
colors still vary but the brightness doesn't vary nearly as
wildly as with genuine blackbody radiation.
2018-12-28 01:27:08 -08:00
53754b956c Blackbody colors are now parsed, and PsychoBlend has support as well. 2018-12-28 00:23:02 -08:00
caa4ea3e44 Replaced SurfaceClosure trait with a SurfaceClosure enum.
Also moved surface closures to using Color internally for color
specification.
2018-12-27 22:57:44 -08:00
e5a12cd498 Fixed the Planck's Law implementation to use correct units.
Color temperature specified colors now work!
2018-12-27 20:03:56 -08:00
5add4cfdb1 Implementing Color as a simple enum rather than as a trait.
There's really no reason for it to be a Trait, and this will simplify
a lot of things down the road.
2018-12-27 16:09:03 -08:00
28a07de456 Improve module path usage and remove extern crate declarations where possible. 2018-12-16 13:02:49 -08:00
178c0bd6cb Third step transitioning to Rust 2018. 2018-12-16 12:17:21 -08:00
8deb1e87bb First step transitioning to Rust 2018. 2018-12-16 12:02:20 -08:00
e3a9cbef84 Silenced/fixed the last of the clippy warnings. 2018-12-16 11:48:01 -08:00
c73db2edbe Fix/silence a bunch of clippy warnings in the main crate. 2018-12-15 23:26:12 -08:00
589a67caa4 Run latest rustfmt on code. No functional changes. 2018-12-08 13:23:44 -08:00
498c1ea8d9 Running latest rustfmt. No functional change. 2018-10-30 22:31:25 -07:00
ab637e3bd5 Fixed bug in GTR and GGX BRDFs. 2018-08-09 14:43:32 -07:00
c002514ddf Run latest rustfmt. No functional changes. 2018-08-09 00:43:21 -07:00
caeb1d9c67 Added GGX glossy material, and simplified surface closure API. 2018-08-09 00:42:17 -07:00
5c20fa3ea4 Moved more work out of the triangle mesh intersection inner loop.
This makes the code a bit spaghetti-like, but it provides noticable
speed-ups in the all the scenes I tested.
2018-07-01 17:30:58 -07:00
3f55df7225 Some basic SIMD optimizations for XYZ->Spectrum conversion. 2018-07-01 15:50:34 -07:00
989914b878 Use Float4::splat() in AccelRay methods. 2018-06-29 17:28:39 -07:00
6d21a30840 Formatting with newer cargo fmt.
No meaningful code change, only formatting.
2018-06-24 21:18:10 -07:00
d92ae4b2d7 Updated to latest openexr-rs release. 2018-06-15 14:52:51 -07:00
b2576c20e7 Upgraded to Nom 2.x 2018-03-04 22:06:20 -08:00
c990672dfe Fix compiler warnings. 2018-03-04 13:06:22 -08:00
97d3304149 Run new rustfmt on codebase. 2018-03-04 13:00:55 -08:00
a797ff012d Fixed sampling of very small rectangle lights.
The sampling method used before is numerically unstable for very
small lights.  That sampling method is still used for large/close
lights, since it works very well for that.  But for small/distant
lights a simpler and numerically stable method is used.
2017-10-26 08:42:09 -07:00
3de276cbaa Make MIS routines handle infinite importance better.
Handle it like the limit case: as A approaches infinity, the
limit approaches 1.0.  Before this, we were getting NaN values.
This fixes that.
2017-10-25 07:11:24 -07:00
6ff226f4fa Whoops, nope. The last commit was a mistake.
It *seemed* to fix the problem I was running into, but it actually
made the SphereLight ray intersection code incorrect, and wa just
avoiding intersections that should have happened.

I should test better before committing. :-)
2017-10-25 07:09:16 -07:00
18024d43b9 Stupid bug in SphereLight ray intersection code.
The ray origin wasn't transformed into local space, resulting in
silly problems.
2017-10-25 06:59:35 -07:00
461b3c377e Improved light tree sampling and changed surface closure API.
Thanks to a discovery by Petra Gospodnetic during her GSOC
project, I was able to substantially improve light tree sampling
for lambert surfaces.  As part of this, the part of the surface
closure API relevant to light tree sampling has been adjusted to
be more flexible.

These improvements do not yet affect GTR surface light tree
sampling.
2017-08-23 19:09:26 -07:00
81c8da8113 Implemented ray intersection for RectangleLights.
This means that RectangleLights now work with MIS.  Yay!
2017-08-17 13:46:38 -07:00
072d366892 Changed SurfaceLight API to return the sample point on the light.
More specifically: prior to this, SurfaceLights returned the
shadow ray direction vector to use.  That was fine, but it
kept the responsibility of generating proper offsets (to account
for floating point error) inside the lights.

Now the SurfaceLights return the world-space point on the light
to sample, along with its surface normal and error magnitude.
This allows the robust shadow ray generation code to be in one
place inside the renderer code.
2017-08-17 13:09:48 -07:00
b1bd419779 Factored out interpolating over a triangle's surface into its own function.
We'll be using this in the RectangleLight sampling code soon.
2017-08-17 11:23:47 -07:00
5a03a46ac7 Multiple importance sampling is now basically working.
Intersecting rectangular lights still isn't implemented, and there
are likely bugs in the MIS implementation, but it's more-or-less
working!
2017-08-16 20:04:06 -07:00
462977bd4d WIP: multiple importance sampling.
Reorganized light and surface traits so that light sources are
surfaces as well, which will let them slide easily into
intersection tests with the rest of the scene geometry.
2017-08-16 18:17:50 -07:00
5c91aca002 WIP multiple importance sampling.
Added method for intersecting finite light sources, and implemented
the method for SphereLight.
2017-08-16 17:27:44 -07:00
e2a417884d Added time parameter to shader evaluation.
It's not used right now, but in the future I want shaders to be
able to vary over time and have motion blur.  This serves as a
nice little reminder by putting it in the API.
2017-08-08 14:48:22 -07:00
6f5984a379 Implemented proper handling of Emit surface closure. 2017-08-08 14:31:31 -07:00
bb82727beb Fixed unneeded mutability warning. 2017-08-03 20:40:09 -07:00
ad55aa4f6d Materials are now working in both Psychopath and PsychoBlend.
Except that Emit is still not properly supported, because it needs
special handling.
2017-08-03 20:32:07 -07:00
516803e78a Got basic material parsing and rendering working.
Currently only Lambert is supported.
2017-08-03 19:31:58 -07:00
f4d4152543 Some refactoring in preparation for a material system.
The main change is that SurfaceClosures now have the hero
wavelength baked into them.  Since surface closures come from
surface intersections, and intersections are always specific to
a ray or path, and rays/paths have a fixed wavelength, it doesn't
make sense for the surface closure to constantly be converting
from a more general color representation to spectral samples
whenever its used.

This is also nice because it keeps surface closures removed from
any particular representation of color.  All color space handling
etc. can be kept inside the shaders.
2017-08-03 16:16:36 -07:00
dd56a4e54b Lambert and GTR now handle interpolated shading normals properly. 2017-07-30 23:16:03 -07:00
58a783b01e Silly mistake in calculating interpolated triangle normal.
The normal is in the local space of the model and needs to be
transformed to global space for lighting calculations.
2017-07-30 23:14:03 -07:00
0481d931b9 Surface closures and light sampling now take both shading and geometric normals.
This will allow them to appropriately handle weirdness that comes
from the shading normal and geometric normal being different.
2017-07-30 19:17:32 -07:00
05578a1240 Implemented smooth-shaded triangle meshes.
There are still some things to do to avoid light leakage and
other weird shading in some situations, but the basics are working!
2017-07-30 17:55:03 -07:00
e77d5b7576 Refactored triangle meshes in preparation for custom normals. 2017-07-30 16:56:28 -07:00
c0a26819c6 Bunch of code quality improvements based on running clippy.
None of them change behavior, just make the code cleaner.
2017-07-22 17:21:11 -07:00
3cb684514a Added some additional fast math functions. 2017-07-22 13:34:38 -07:00
5d0e77f5db Improved SAH split code for light tree.
The SAH split would happily repeatedly split on the same axis
as long as the surface area was reduced as much as splitting
on the other axes.  This resulted in sliver-like bounding boxes
for some scenes, which is terrible for the light tree.

The SAH splitting code now accounts for the diagonal of the
bounding box, favoring smaller ones.  This seems to work well,
fixing the issue without introducing any apparent performance
regressions.
2017-07-12 23:49:12 -07:00
2dcba3aca4 Speed up ray/mesh intersection for cases with no transform motion blur. 2017-07-12 01:32:44 -07:00
972c2a90a7 Further work on accurate ray/triangle intersections.
The previous commit dealt with triangles self-shadowing.  This
commit deals with avoiding intersections with _other_ objects
very near a triangle ending up being erroneously shadowed by
it.
2017-07-10 23:37:50 -07:00
b315be0913 Fixed self-intersection bug for coordinates near zero.
This turned out to be a rather interesting one.  The water-tight
ray/triangle intersection algorithm, while very accurate for
finding if there is an intersection with a line segment, is
not as remarkably accurate for determining if that intersection
is within the interval of the ray.

This is because of the coordinate transformation it does
depending on ray direction: for triangles laying flat on one of
the axis planes near zero, that near-zero coordinate can get
transformed to a much less accurate space for testing.  In fact,
generally speaking, beause of the coordinate transform, you can
only rely on the test being as accurate as the least accurate
axis.

The ray-origin offset code was doing offsets based on the
assumption that the error on the major axes are independent, but
as this triangle intersection algorithm shows, you can't actually
depend on that being the case.  So rather than handling triangle
intersection as a special case, I've changed the intersection
position error to be a single float, representing the maximum
possible error on any axis.  This should be robust for any
geometry type added in the future, and also solves the immediate
issue in a correct way.
2017-07-10 00:52:28 -07:00
a1840ec408 Cleaned up implementation of ray/triangle intersection test. 2017-07-10 00:39:09 -07:00
f371e0643a Instrument code to count ray/node tests during BVH traversal. 2017-07-06 22:17:36 -07:00
649a6a0869 Rearrnging the operations in ray/bbox test for slight perf improvement.
The difference is extremely small, but consistent.  I'm guessing
due to better pipelining of instructions.
2017-07-06 22:10:37 -07:00
09daf617ef Implemented a non-SIMD BVH4. Perf appears to be identical to BVH. 2017-07-01 15:08:05 -07:00
554f73eacb Tighter memory layout for LightTree. 2017-06-29 21:11:00 -07:00
e48bff3011 Finished light tree arity configurability.
Turns out going higher arity makes a huge positive difference
is sampling quality.  Currently have 32-arity set as the default,
as it seems to be worth it for the better sampling.
2017-06-29 02:28:30 -07:00
47c2bf4ed9 Almost have configurable arity for light tree building.
Just need to fill in a couple of functions with non-temp code.
2017-06-29 00:29:23 -07:00
b891cc943b Light tree can now be traversed with arbitrary arity.
Next up is building with configurable arity.
2017-06-28 23:20:03 -07:00
27c635982e Adjusting light tree implementation in prep for configurable arity. 2017-06-28 22:51:20 -07:00
4e9bfd6e79 Fix for ray origin offsets when intersection point is at 0.0.
For some reason the ulp incrementing is unreliable when starting
at zero.  It creates subnormal numbers, and that seems to be an
issue somewhere in the pipeline, ultimately leading to weird
render artifacts.  Not entirely sure why.

This fixes it by avoiding subnormal numbers in the final offset
ray origin.  Left a note suggesting investigating in more detail
at some point.
2017-06-21 01:36:08 -07:00
927a86c1fc Update LightArray to work with current code.
It's useful for checking correctness.
2017-06-20 23:28:49 -07:00
011405e131 Implemented robust ray origin calculation for bounced rays.
We take a small performance hit for this, but given that it's
making things meaningfully more correct I feel like it's more
than worth it.
2017-06-19 22:28:44 -07:00
71bdf203aa Fixed bug in mesh intersection code.
Very small triangles were being missed because of the
not-so-robust ray-triangle intersection algorithm I was using.

Switched to the algorithm from the paper "Watertight
Ray/Triangle Intersection" by Woop et al.  Happily, the new
algorithm doesn't seem to measurably slow down renders at all.
2017-06-18 20:51:53 -07:00
2c0e57341c XYZ color curve functions need more accurate exp function. 2017-06-15 22:50:27 -07:00
f649bec585 Reformat code with rustfmt 0.9 2017-06-15 22:00:31 -07:00
Guillaume Gomez
ae11be1397 Improve messages for imge creation 2017-06-14 10:46:28 +02:00
851989f6a6 Added a license and licensing notes.
Also replaced some code I'm not sure where it came from or what
the license was.
2017-06-11 21:29:51 -07:00
b8321beaad Split colorspace transform functions out into their own crate.
They are now generated by a build.rs script from nothing but the
colorspace's primaries, which makes it super easy to add more
colorspaces.  So easy that I added three more: ACES AP0, ACES AP1
and Rec.2020.

This lays the foundation for supporting output to different
colorspaces.
2017-06-11 03:03:23 -07:00
2a66485595 Supress information output when doing serialized ouput for PsychoBlend. 2017-06-10 22:34:14 -07:00
71c320d87c Added command-line argument to render an image cropped. 2017-06-06 21:11:35 -07:00
59555f67f9 PsychoBlend: use stdin/out to transfer scene data by default.
This eliminates writing temp files to disk for any part of the
Blender/Psychopath integration.

The option to export to a file still exists, however, by
specifying an export output path.
2017-06-04 23:24:45 -07:00
a3332d4f6a Fixed a PsychoBlend bug that resulted in render not being fully displayed.
Getting the interplay between the reading the process output and
polling to see if it's finished is a tad tricky.  I think I got
it right this time.
2017-06-03 01:12:21 -07:00