Commit Graph

85 Commits

Author SHA1 Message Date
Sergey Sharybin
48997d2e40 Cycles: Cleanup, style 2016-10-24 12:26:12 +02:00
7f5441b916 Fix T49640: Cycles constant folding incorrect for texture coordinates. 2016-10-12 18:42:38 +02:00
Mai Lavelle
49df5d0980 Cycles: Fix shading and crashes resulting from constant folding on displacement
Constant folding was removing all nodes connected to the displacement output
if they evaluated to a constant, causing there to be no valid graph for
displacement even when there was displacement to be applied, and sometimes
caused crashes.
2016-09-11 13:49:34 -04:00
Mai Lavelle
92a2c49aab Cycles: Fix bump mapping to use object space when used with true displacement
Bump mapping was happening in world space while displacement happens in object
space, causing shading errors when displacement type was used with bump mapping.

To fix this the proper transforms are added to bump nodes. This is only done
for automatic bump mapping however, to avoid visual changes from other uses of
bump mapping. It would be nice to do this for all bump mapping to be consistent
but that will have to wait till we can break compatibility.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D2191
2016-09-11 11:20:21 -04:00
Mai Lavelle
e7ea1ae78c Cycles microdisplacement: Improved automatic bump mapping
Object coordinates can now be used in the displacement shader and will give
correct results, where as before bump mapping was calculated from the displace
positions and resulted in incorrect shading.

This works by evaluating the shader in two parts, first bump then surface, and
setting the shader state to match what it would be if the surface was
undisplaced for the bump shader evaluation. Currently only `P` is set as if
undisplaced, but other shader variables could be set as well, such as `I` or
`time`. Since these aren't set to anything meaningful for displacement I left
them out of this patch, we can decide what to do with them separately.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D2156
2016-09-01 22:45:49 -04:00
Alexander Gavrilov
f2d5295abf Cycles: log how many nodes were deduplicated for use in tests.
To make the number more meaningful, also skip deduplicating
obviously unused nodes with no outgoing links.
2016-08-02 19:26:57 +03:00
9b6ed3a42b Cycles: refactor kernel closure storage to use structs per closure type.
Reviewed By: dingto, sergey

Differential Revision: https://developer.blender.org/D2127
2016-07-31 02:34:43 +02:00
e44fa4e6a9 Fix another Cycles OSL script node issue with shaders using bump. 2016-07-21 04:40:28 +02:00
Alexander Gavrilov
5234e9ddd3 Cycles: add ConstantFolder class for constant folding boilerplate.
Reviewed By: brecht, sergey

Differential Revision: https://developer.blender.org/D2089
2016-07-18 22:54:30 +02:00
Alexander Gavrilov
81e391a727 Fix issues with node deduplication in Cycles shader graph.
It is not possible to use a set split by name as valid input to
check_node_input_traversed - it needs a complete set of all nodes visited so
far. On the other hand, the merge comparison loop should only check nodes that
were not just visited, but found unique. This means that there should really be
two separate data structures.

Without the fix, check_node_input_traversed actually never returns true, so
only nodes without any inputs are processed.
2016-06-19 20:17:27 +02:00
34a42788e7 Code refactor: small code simplification for Cycles constant folding. 2016-06-19 20:17:27 +02:00
42aec3b355 Cycles: nodify shader nodes
Differential Revision: https://developer.blender.org/D2038
2016-06-11 20:32:24 +02:00
af073e149b Code refactor: pass ShaderInput to constant_fold, so it supports arbitrary types. 2016-05-29 20:30:16 +02:00
b94bfe4cd8 Code refactor: make ShaderNode match Node a bit more, reusing types and enums.
Differential Revision: https://developer.blender.org/D2016
2016-05-28 15:49:15 +02:00
Sergey Sharybin
2aa4b6045a Cycles: Fix wrong closure counter in feature adaptive kernel
Some closures were missing from calculation, leading to an array
under-allocation, presumable causing memory corruption issues with
emission shaders on OpenCL and was causing issues with Volume 3D
textures with CUDA.

The issue was identified by Thomas Dinges, the patch is different
from the original D2006. See the brief discussion there. Current
approach is similar (or the same) as Brecht suggested.
2016-05-23 14:09:27 +02:00
9dc5367c89 Cleanup code style inconsistency in last commits. 2016-05-17 23:41:45 +02:00
a815e10211 Code cleanup: use special type instead of node names. 2016-05-08 20:21:04 +02:00
dd8bfa0929 Code refactor: reduce special node types, use generic constant folding. 2016-05-05 21:43:46 +02:00
Sergey Sharybin
3aa74828ab Cycles: Cleanup, indentation and braces 2016-02-03 15:00:55 +01:00
Sergey Sharybin
5d564da3b6 Cycles: Fix memory leak in shader graph when bump graph is used 2016-01-05 21:18:02 +05:00
Sergey Sharybin
aff9fd60bc Cycles: Optimize nodes deduplication routines
The idea is to have separate sets per node name in order to speed up the
comparison process. This will use a bit more memory and slow down simple
shaders, but this extra memory is not so much huge and time penalty is
not really measurable (at least from initial tests).

This saves orders of magnitude seconds when de-duplicating 17K nodes and
overall process now takes 0.01sec on my laptop,
2015-12-29 20:27:00 +05:00
Sergey Sharybin
3482cdb136 Cycles: Remove assert which is no longer valid
Was a left-over since 5b33115.
2015-12-29 19:19:53 +05:00
Sergey Sharybin
738f6d8127 Cycles: Implement node deduplication routines
The idea of this commit is to merge nodes which has identical settings
and matching inputs into a single node in order to minimize number of
SVM instructions.

This is quite simple bottom-top graph traversal and the trickiest part
is how to compare node settings without too much trouble which seems to
be solved is quite clean way.

Still possibilities for further improvements:

- Support comparison of BSDF nodes
- Support comparison of volume nodes
- Support comparison of curve mapping/ramp nodes

Reviewers: brecht, juicyfruit, dingto

Differential Revision: https://developer.blender.org/D1673
2015-12-28 16:37:48 +05:00
Sergey Sharybin
5b33115070 Cycles: Fix wrong assert failure happening after recent de-duplicate
This is actually intended behavior to return NULL when the socket is not
found. It's used in certain BSDF nodes to query whether some inputs exists
or not.

Perhaps we can be more explicit here and have dedicated logic to query
socket existance and keep assert in place.

In any case, even if we lost assert() for the constant fold now it's
still somewhat better than duplicated code. Perhaps.
2015-12-15 21:01:56 +05:00
Sergey Sharybin
baaf10cb26 Cycles: De-duplicate utility functions in ccl::Graph 2015-12-15 20:04:35 +05:00
Thomas Dinges
a3d774e4c9 Cycles: Fold Value and RGB node as well.
This way, connecting Value or RGB node to e.g. a Math node will still allow folding.

Note: The same should be done for the ConvertNode, but I leave that for another day.
2015-12-06 23:47:38 +01:00
Sergey Sharybin
6552d5bebd Cycles: Avoid recursion when doing constant fold
This reduces stress on the the stack memory which could be really handy
on certain operation systems which applies strict limits on the stack.

Reviewers: brecht, juicyfruit, dingto

Reviewed By: brecht, juicyfruit, dingto

Differential Revision: https://developer.blender.org/D1656
2015-12-02 16:19:39 +05:00
Campbell Barton
fc9505c9c5 Cleanup: warnings & spelling 2015-12-02 13:15:52 +11:00
Sergey Sharybin
1bec2aa54e Cycles: Fix crash in constant folding introduced by recent commit
Graph::disconnect() actually modifies links, needs to create a copy to iterate
if disconnect happens form inside the loop.

Question tho whether we can control this somehow..

Reported by BzztPloink in IRC, thanks!
2015-11-25 20:14:01 +05:00
Thomas Dinges
e796581655 Cycles: Refactor of constant fold.
* Move constant folding from nodes to the shader graph. This way it's part of our (later) 4-step optimization process.
* Instead of only doing a one level constant fold, we can now do a recursive constant fold, allowing us to simplify shaders much further.
Constant folding is implemented for Blackbody, Math and VectorMath nodes.

Example (the highlighted nodes are removed before rendering):
Before: http://archive.dingto.org/2015/blender/code/one_level_constant_fold.jpg
Now: http://archive.dingto.org/2015/blender/code/multi_level_constant_fold.jpg

Thanks to Sergey and Brecht for Review!
Differential Revision: https://developer.blender.org/D1626
2015-11-25 13:57:54 +01:00
Sergey Sharybin
8294452b14 Fix T46782: Updating Shaders very slow with complex nodegraph
The issue was caused by not really optimal graph traversal for gathering nodes
dependencies which could have exponential complexity with a long tree branches
connected with multiple connections between them.

Now we optimize the depth traversal and perform early output if the node was
already traversed.

Please note that this adds some limitations to the use of SVM compiler's
find_dependencies() in the cases when skip_node is not NULL and one wants to
perform dependencies find sequentially with the same set. This doesn't happen
in the code, but one should be aware of this.
2015-11-25 13:46:51 +05:00
Sergey Sharybin
443b159f02 Cycles: Ensure order of shader nodes in the dependnecies set
The issue was than nodes dependencies were stored as set<ShaderNode*> which
is actually a so called "strict weak ordered", meaning order of nodes in
the set is strictly defined, but based on the ShaderNode pointer. This means
that between different render invokations order of original nodes could be
different due to different pointers allocated for ShaderNode.

This commit makes it so dependencies and maps used for ShaderNodes are based
on the node->id which has much more predictable order. It's still possible
to trick the system by doing some crazy edits during viewport rendfer and
cause difference between viewport and final render stacks.

Reviewers: brecht

Reviewed By: brecht

Subscribers: LazyDodo

Differential Revision: https://developer.blender.org/D1630
2015-11-25 13:07:32 +05:00
Sergey Sharybin
7e71be261b Cycles: Fix filter glossy being broken after recent changes
Basically we can not use sharp closure as a substitude when filter glossy is
used. This is because we can not blur sharp reflection/refraction.

This is quite quick and not really clean implementation. Not really happy
with manual handling of original settings, but this is as good as we can do
in the quick patch. It's a good acknowledgment and we now can re-consider
some aspects of graph simplification to make such cases more natively
supported.

P.S. This failure would have been shown by our regression tests, so please,
bother a bit to run Cycles's test sweep before doing such optimizations.
2015-11-20 18:18:27 +05:00
Thomas Dinges
eeed28fefc Fix T46818, crash with Glossy node on Windows. 2015-11-19 08:43:43 +01:00
Thomas Dinges
0639ba8ea5 Cycles / Shader graph: Fallback to Sharp closures for very small roughness.
We fallback to Sharp closures for Glossy, Glass and Refraction nodes now, in case the Roughness input is disconnected and 0 (< 1e-4f to be exact).
This way we gain a few percentages of performance, in case the user did not manually set the closure type to "Sharp" in the UI.

Sharp will probably be removed from the UI as a followup, not needed anymore with this internal optimization.

Original idea by Lukas Stockner(Differential Revision: https://developer.blender.org/D1439), code implementation by myself.
2015-11-18 18:47:56 +01:00
Thomas Dinges
836c69c92f Cleanup: Add some notes in code for upcoming graph simplification process. 2015-11-18 17:20:39 +01:00
Thomas Dinges
38bbc920a6 Cycles: Add utility functions to get a ShaderInput / ShaderOutput by name. 2015-11-18 17:12:26 +01:00
Sergey Sharybin
83a36b2829 Cycles: Fix for wrong optimization of bump node
It can't be simply removed in cases when it's connected to input which is
different from Normal. This is because the input wouldn't be connected to
default Normal geometry input, possibly breaking shading setup.

The fix is not really ideal, but should work at least.

This fixes skin having too much glossy reflection in the file from T46013.
2015-09-04 20:06:31 +05:00
Thomas Dinges
b666593775 Cycles: Remove Bump Node from the graph, if Height input is not connected.
This way we can avoid building the split kernel with NODE_FEATURE_BUMP enabled, in case we don't need it.
2015-06-11 23:09:38 +02:00
Thomas Dinges
67eb2c7897 Cycles: Remove Emission shaders from the graph if color or strength is 0. 2015-05-14 01:13:40 +02:00
Sergey Sharybin
5068f7dc01 Cycles: Add utility function to graph to query number of closures used in it
Currently unused but will be needed soon for the split kernel work.
2015-05-09 19:13:32 +05:00
Thomas Dinges
bc160d8a85 Cleanup: Code style. 2015-04-26 00:42:26 +02:00
Sergey Sharybin
09a746b857 Cycles: Cleanup, typos 2015-04-08 01:15:38 +05:00
Sergey Sharybin
948bc66a00 Cycles: Improve readability of dumped graphs 2015-03-17 21:15:17 +05:00
Sergey Sharybin
a43d00d51e Cycles: Fix displacement code creating cyclic dependencies in graph
Bump result was passed to set_normal node and then set_node was connected
to all unconnected Normal inputs, including the one from original Bump
node, causing cycles.
2015-03-17 19:39:09 +05:00
Thomas Dinges
fa9311c9a4 Cleanup: Update comments and make it more clear what volume interpolation is for. 2015-02-16 22:11:41 +01:00
Thomas Dinges
1aa8f0d3c0 Cleanup / Cycles: Code de-duplication for graph node relinking.
Differential Revision: https://developer.blender.org/D1018
2015-01-22 09:59:16 +01:00
Thomas Dinges
cd72396797 Cycles: Optimization for black world backgrounds
* If a Background node is set to a black color or zero strength,
it now gets removed from the shader graph.

* In case the graph is empty (no background node), the kernel will skip
evaluating it and save some rendertime. This can help quite a bit in scenes,
where the majority of the image consists of a black background.

Example: http://www.pasteall.org/pic/show.php?id=82650
In this case the render is ~16% faster.

Differential Revision: https://developer.blender.org/D972
2015-01-21 20:16:18 +01:00
Thomas Dinges
ee36e75b85 Cleanup: Fix Cycles Apache header.
This was already mixed a bit, but the dot belongs there.
2014-12-25 02:50:24 +01:00
Sergey Sharybin
d6579fe7f3 Cycles: Fix typo on graphiz graph dumper 2014-11-20 18:56:20 +05:00