Commit Graph

40 Commits

Author SHA1 Message Date
Sergey Sharybin
7dabfb2048 Cycles: Speedup of kernel side camera-in-volume detection
The idea is to only count intersections with objects which has volumetric shader
and ignore all other objects.

This is probably as fast as we can go without involving some forth level magic.
2014-10-03 12:55:31 +06:00
Sergey Sharybin
21825c4359 Cycles: Avoid temp variable in camera-in-volume check
Was a left-over from some experiments, no need it with the current
implementation, and likely wouldn't need in the future.
2014-09-28 02:35:37 +06:00
Sergey Sharybin
fe731686fb Cycles: Add support for cameras inside volume
Basically the title says it all, volume stack initialization now is aware that
camera might be inside of the volume. This gives quite noticeable render time
regressions in cases camera is in the volume (didn't measure them yet) because
this requires quite a few of ray-casting per camera ray in order to check which
objects we're inside. Not quite sure if this might be optimized.

But the good thing is that we can do quite a good job on detecting whether
camera is outside of any of the volumes and in this case there should be no
time penalty at all (apart from some extra checks during the sync state).

For now we're only doing rather simple AABB checks between the viewplane and
volume objects. This could give some false-positives, but this should be good
starting point.

Need to mention panoramic cameras here, for them it's only check for whether
there are volumes in the scene, which would lead to speed regressions even if
the camera is outside of the volumes. Would need to figure out proper check
for such cameras.

There are still quite a few of TODOs in the code, but the patch is good enough
to start playing around with it checking whether there are some obvious mistakes
somewhere.

Currently the feature is only available in the Experimental feature sey, need
to solve some of the TODOs and look into making things faster before considering
the feature is ready for the official feature set. This would still likely
happen in current release cycle.

Reviewers: brecht, juicyfruit, dingto

Differential Revision: https://developer.blender.org/D794
2014-09-25 23:28:01 +06:00
Thomas Dinges
031620aba2 Cycles: Avoid redundant call to volume_stack_is_heterogeneous() for Distance Sampling. 2014-08-24 16:15:57 +02:00
Thomas Dinges
187d77612b Code refactor: Split __VOLUME__ defines in Cycles.
* __VOLUME__ is basic volume support with Emission and Absorption.
* __VOLUME_SCATTER__ enables volume Scattering support.
* __VOLUME_DECOUPLED__ enables Decoupled Ray Marching.
2014-08-20 23:15:30 +02:00
Thomas Dinges
075f6eff74 Cycles: Further tweak for Decoupled Ray Marching
Avoid some if checks when probalistic_scatter is false.

Differential Revision: https://developer.blender.org/D743
2014-08-20 22:59:08 +02:00
Thomas Dinges
5bdea81319 Cycles: Don't check closure flag in kernel_volume_decoupled_scatter(), we check this before the function already. 2014-08-14 21:25:52 +02:00
Thomas Dinges
32a5313b41 Cycles: Optimize Equi-Angular sampling using binary range search.
Patch by Lukas Tönne and myself.
2014-08-14 20:21:36 +02:00
Thomas Dinges
5af00a3d12 Cycles: Optimization for Heterogeneous Volume Shadows.
* Don't compute expf() for every step, instead sum the intermediate values and calculate it every N (8 for now) steps. This helps a few percent (~5% on a cube with wave texture) in my tests here.
2014-08-14 20:09:25 +02:00
Thomas Dinges
5fefc84783 Cycles: Equi-Angular and MIS Volume sampling work on GPU now.
* malloc() is used now, which is supported since sm_20: http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#dynamic-global-memory-allocation-and-operations The performance of this needs to be tested on various cards still.
* This also works for Heterogeneous Decoupled Ray Marching, but in this case I get sporadic "Illegal Address" errors on my Geforce 540, therefore I did not remove the GPU check in kernel_volume_use_decoupled() yet.

I would appreciate some tests from people who compile themselves, enable Volumetrics in kernel_types.h.
2014-07-06 14:00:11 +02:00
Thomas Dinges
5aec61f849 Cycles: Compile fixes for CUDA Volumetrics.
* CUDA can be compiled with Volume support again, change line 78 kernel_types.h for that.

Volumes are still fragile on GPU though, got some Memory/Address CUDA errors in tests.. needs to be investigated more deeply.
2014-07-05 02:04:07 +02:00
4b209f063c Fix T40695: world surface shader incorrectly visible with world volume. 2014-06-24 11:35:48 +02:00
5fa68133c9 Cycles: volume sampling method can now be set per material/world.
This gives you "Multiple Importance", "Distance" and "Equiangular" choices.

What multiple importance sampling does is make things more robust to certain
types of noise at the cost of a bit more noise in cases where the individual
strategies are always better.

So if you've got a pretty dense volume that's lit from far away then distance
sampling is usually more efficient. If you've got a light inside or near the
volume then equiangular sampling is better. If you have a combination of both,
then the multiple importance sampling will be better.
2014-06-14 13:49:56 +02:00
a29807cd63 Cycles: volume light sampling
* Volume multiple importace sampling support to combine equiangular and distance
  sampling, for both homogeneous and heterogeneous volumes.

* Branched path "Sample All Direct Lights" and "Sample All Indirect Lights" now
  apply to volumes as well as surfaces.

Implementation note:

For simplicity this is all done with decoupled ray marching, the only case we do
not use decoupled is for distance only sampling with one light sample. The
homogeneous case should still compile on the GPU because it only requires fixed
size storage, but the heterogeneous case will be trickier to get working.
2014-06-14 13:49:56 +02:00
0780f5915b Fix T39804: cycles smoke domain visible in rendering.
Transparent objects could become subtly visible by the different sampling
patterns for pixels covered and not covered by the object. It still converged
to the right solution but that can take a while. Now we try to use the same
sampling pattern here.
2014-05-29 14:51:02 +02:00
9e61dcc6b8 Fix T40408: world MIS + equiangular sampling giving unnecessary noise.
It's actually not possible to do equiangular sampling for distant lights, now
it reverts to distance sampling in this case.
2014-05-29 14:50:47 +02:00
Campbell Barton
8d16869d83 Code cleanup: Add -Werror=float-conversion to Cycles 2014-05-03 07:31:46 +10:00
Carlo Andreacchio
7765b73f6d Cycles: add Transparent Depth output to Light Path node.
This can for example be useful if you want to manually terminate the path at
some point and use a color other than black.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D454
2014-04-21 14:44:36 +02:00
a58814acf5 Fix T39525: cycles volume render difference between branched/non-branched path. 2014-04-02 20:51:29 +02:00
f449542d6a Cycles volume: change heterogeneous volume sampling in branched path first hit.
This now uses decoupled ray marching, and removes the probalistic scattering.
What this means is that each AA sample will be slower but contain less noise,
hopefully giving less render time to reach the same noise levels.

For those following along, there's still a bunch of volume sampling improvements
to do: all-light sampling, multiple importance sampling, transmittance threshold,
better indirect light handling, multiple scatter approximation.
2014-03-29 13:03:50 +01:00
3847d0c0df Cycles code internals: add initial implementation of decoupled ray marching.
This basically records all volumes steps, which can then later be used multiple
time to take scattering samples, without having to step through the volume
again. From the paper:

"Importance Sampling Techniques for Path Tracing in Participating Media"

This works only on the CPU, due to usage of malloc/free.
2014-03-29 13:03:50 +01:00
47e7acf231 Cycles code refactor: minor refactoring and comments for volume code. 2014-03-29 13:03:49 +01:00
7cb28f41f9 Cycles volume: change homogeneous volume sampling in branched path first hit.
Similar to surfaces, this will now always scatter rather than probabilistically
scattering or not depending on the transmittance.

This also makes calculation of branched path throughput non-probalistic, which
makes thing slower too. That's to be solved by decoupled ray marching later.
2014-03-29 13:03:49 +01:00
9a77872b2b Cycles code refactor: shuffle homogeneous volume code to factor out hit/miss decision.
This removes a few optimizations to avoid exp() calls and division, they will be
added back later, at the moment it's more important to make the code easier to
understand and refactor.
2014-03-29 13:03:49 +01:00
676e1cbe40 Cycles code refactor: move some more volume code into separate functions. 2014-03-29 13:03:49 +01:00
b1615f0e0e Cycles volumes: don't average coefficients over volume step.
Rather use random point in each step instead of giving the steps random sizes.
Gives a bit more accurate results with large step sizes, but also convenient
convention for later changes.
2014-03-29 13:03:49 +01:00
f5ab699fe8 Fix cycles error for heterogenous volumes, causing double step size to be used.
This gives longer render times due to smaller step size, double it to get
something more like the previous behavior.
2014-03-29 13:03:49 +01:00
28954ce9c4 Cycles code refactor: move some volume code to separate functions. 2014-03-29 13:03:48 +01:00
e8b1cfed0a Cycles code refactor: replace magic ~0 values in the code with defines. 2014-03-29 13:03:47 +01:00
Thomas Dinges
76a7c2173b Cleanup: Fix some typos in the code. 2014-03-01 01:21:46 +01:00
de6b64bca6 Fix use of uninitialized variable in some cases with scatter + emission volume. 2014-02-27 23:41:00 +01:00
e1e247a99b Fix T38710: volume render issue with transparent surfaces. 2014-02-26 18:47:50 +01:00
2bf591762a Cycles: equi-angular sampling for homogeneous volumes
This adds an option in the Volume Sampling panel, which helps rendering lamps
inside or near volumes with less noise. It can also increase noise though and
needs improvements to support MIS and heterogeneous volumes, but since it's
useful in some cases already (especially world volumes) it's there now.

Based on the code in the old branch by Stuart, with modifications by Thomas
and Brecht.

Differential Revision: https://developer.blender.org/D291
2014-02-14 17:37:34 +01:00
01df756bd1 Cycles Volume Render: scattering support.
This is done by adding a Volume Scatter node. In many cases you will want to
add together a Volume Absorption and Volume Scatter node with the same color
and density to get the expected results.

This should work with branched path tracing, mixing closures, overlapping
volumes, etc. However there's still various optimizations needed for sampling.
The main missing thing from the volume branch is the equiangular sampling for
homogeneous volumes.

The heterogeneous scattering code was arranged such that we can use a single
stratified random number for distance sampling, which gives less noise than
pseudo random numbers for each step. For volumes where the color is textured
there still seems to be something off, needs to be investigated.
2014-01-07 15:03:41 +01:00
d0c6f14c73 Fix T38033: cycles volume emission changes with step size. 2014-01-02 21:34:22 +01:00
889d77e6f6 Cycles Volume Render: heterogeneous (textured) volumes support.
Volumes can now have textured colors and density. There is a Volume Sampling
panel in the Render properties with these settings:

* Step size: distance between volume shader samples when rendering the volume.
  Lower values give more accurate and detailed results but also increased render
  time.
* Max steps: maximum number of steps through the volume before giving up, to
  protect from extremely long render times with big objects or small step sizes.

This is much more compute intensive than homogeneous volume, so when you are not
using a texture you should enable the Homogeneous Volume option in the material
or world for faster rendering.

One important missing feature is that Generated texture coordinates are not yet
working in volumes, and they are the default coordinates for nearly all texture
nodes. So until that works you need to plug in object texture coordinates or a
world space position.

This is work by "storm", Stuart Broadfoot, Thomas Dinges and myself.
2013-12-30 00:04:02 +01:00
30aa0c2482 Code refactor: better distinguish scatter and absorption for volume integration. 2013-12-30 00:04:02 +01:00
fe222643b4 Cycles Volume Render: add volume emission support.
This is done using the existing Emission node and closure (we may add a volume
emission node, not clear yet if it will be needed).

Volume emission only supports indirect light sampling which means it's not very
efficient to make small or far away bright light sources. Using direct light
sampling and MIS would be tricky and probably won't be added anytime soon. Other
renderers don't support this either as far as I know, lamps and ray visibility
tricks may be used instead.
2013-12-28 23:20:53 +01:00
2b39214c4d Cycles Volume Render: add support for overlapping volume objects.
This works pretty much as you would expect, overlapping volume objects gives
a more dense volume. What did change is that world volume shaders are now
active everywhere, they are no longer excluded inside objects.

This may not be desirable and we need to think of better control over this.
In some cases you clearly want it to happen, for example if you are rendering
a fire in a foggy environment. In other cases like the inside of a house you
may not want any fog, but it doesn't seem possible in general for the renderer
to automatically determine what is inside or outside of the house.

This is implemented using a simple fixed size array of shader/object ID pairs,
limited to max 15 overlapping objects. The closures from all shaders are put
into a single closure array, exactly the same as if an add shader was used to
combine them.
2013-12-28 20:12:11 +01:00
e369a5c485 Cycles Volume Render: support for rendering of homogeneous volume with absorption.
This is the simplest possible volume rendering case, constant density inside
the volume and no scattering or emission. My plan is to tweak, verify and commit
more volume rendering effects one by one, doing it all at once makes it
difficult to verify correctness and track down bugs.

Documentation is here:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Materials/Volume

Currently this hooks into path tracing in 3 ways, which should get us pretty
far until we add more advanced light sampling. These 3 hooks are repeated in
the path tracing, branched path tracing and transparent shadow code:

* Determine active volume shader at start of the path
* Change active volume shader on transmission through a surface
* Light attenuation over line segments between camera, surfaces and background

This is work by "storm", Stuart Broadfoot, Thomas Dinges and myself.
2013-12-28 16:57:10 +01:00