Commit Graph

202 Commits

Author SHA1 Message Date
Hans Goudey fac27b1b6b Cleanup: Replace most used of SWAP macro with std::swap
Also remove / replace use of the math vector double swapping functions.
2024-01-31 21:12:16 -05:00
Campbell Barton 3b0ced2e31 BLI_math: add add_v3_uchar_clamped (previously color_add_v3_i)
Move color_add_v3_i to a public function,
useful for making minor color adjustments.
2023-09-07 15:54:53 +10:00
Sergey Sharybin c1bc70b711 Cleanup: Add a copyright notice to files and use SPDX format
A lot of files were missing copyright field in the header and
the Blender Foundation contributed to them in a sense of bug
fixing and general maintenance.

This change makes it explicit that those files are at least
partially copyrighted by the Blender Foundation.

Note that this does not make it so the Blender Foundation is
the only holder of the copyright in those files, and developers
who do not have a signed contract with the foundation still
hold the copyright as well.

Another aspect of this change is using SPDX format for the
header. We already used it for the license specification,
and now we state it for the copyright as well, following the
FAQ:

    https://reuse.software/faq/
2023-05-31 16:19:06 +02:00
Campbell Barton 129f6b7b84 Cleanup: spelling in comments, replace slang/informal terms 2023-05-24 20:27:13 +10:00
Campbell Barton b132118f89 Cleanup: balance doxygen grouping, minor grouping adjustment 2023-04-19 09:02:21 +10:00
Campbell Barton ce659dbc4e Cleanup: use doxygen sections 2023-03-29 14:17:32 +11:00
Richard Antalik 5b4efaeeb3 Merge branch 'blender-v3.4-release' 2022-11-27 21:42:37 +01:00
Richard Antalik 3a65d2f591 Fix T101211: Image jitters when scaling by large values
Issue was caused by imprecise math due to using float numbers.
Use double instead.

No negative performance impact was observed.

Reviewed By: jbakker

Differential Revision: https://developer.blender.org/D16517
2022-11-27 21:33:05 +01:00
Hans Goudey 8e535ee9b4 Cleanup: Remove unused math min max utility
This has a friendlier multithreaded implementation in BLI_bounds.hh now.
2022-11-22 12:31:31 -06:00
Campbell Barton b04514da5d Cleanup: match names between functions & declarations
Mostly update the declarations, in some cases rename in the function
especially when the names used were inconstant with related functions.
2022-08-22 11:20:40 +10:00
Yiming Wu 6dd8ceef2a LineArt: Shadow and related functionalities.
This patch includes the full shadow functionality for LineArt:

- Light contour and cast shadow lines.
- Lit/shaded region selection.
- Enclosed light/shadow shape calculation.
- Silhouette/anti-silhouette selection.
- Intersection priority based on shadow edge identifier.

Reviewed By: Sebastian Parborg (zeddb)

Differential Revision: https://developer.blender.org/D15109
2022-06-29 22:54:29 +08:00
Campbell Barton 4d46fac65d Cleanup: use count or num instead of nbr
Follow conventions from T85728.
2022-03-25 12:04:20 +11:00
Campbell Barton c434782e3a File headers: SPDX License migration
Use a shorter/simpler license convention, stops the header taking so
much space.

Follow the SPDX license specification: https://spdx.org/licenses

- C/C++/objc/objc++
- Python
- Shell Scripts
- CMake, GNUmakefile

While most of the source tree has been included

- `./extern/` was left out.
- `./intern/cycles` & `./intern/atomic` are also excluded because they
  use different header conventions.

doc/license/SPDX-license-identifiers.txt has been added to list SPDX all
used identifiers.

See P2788 for the script that automated these edits.

Reviewed By: brecht, mont29, sergey

Ref D14069
2022-02-11 09:14:36 +11:00
Campbell Barton 68a21697be Cleanup: remove "The Original Code is: ..." from code comments
This is almost always meaningless as most code has changed
since the comment was added. Besides this, version control can be used
to check if/when a file was modified.

Some cases of this were kept when they contain details
about the original copyright holder.
2022-02-09 16:04:31 +11:00
Hans Goudey cfa53e0fbe Refactor: Move normals out of MVert, lazy calculation
As described in T91186, this commit moves mesh vertex normals into a
contiguous array of float vectors in a custom data layer, how face
normals are currently stored.

The main interface is documented in `BKE_mesh.h`. Vertex and face
normals are now calculated on-demand and cached, retrieved with an
"ensure" function. Since the logical state of a mesh is now "has
normals when necessary", they can be retrieved from a `const` mesh.

The goal is to use on-demand calculation for all derived data, but
leave room for eager calculation for performance purposes (modifier
evaluation is threaded, but viewport data generation is not).

**Benefits**
This moves us closer to a SoA approach rather than the current AoS
paradigm. Accessing a contiguous `float3` is much more efficient than
retrieving data from a larger struct. The memory requirements for
accessing only normals or vertex locations are smaller, and at the
cost of more memory usage for just normals, they now don't have to
be converted between float and short, which also simplifies code

In the future, the remaining items can be removed from `MVert`,
leaving only `float3`, which has similar benefits (see T93602).

Removing the combination of derived and original data makes it
conceptually simpler to only calculate normals when necessary.
This is especially important now that we have more opportunities
for temporary meshes in geometry nodes.

**Performance**
In addition to the theoretical future performance improvements by
making `MVert == float3`, I've done some basic performance testing
on this patch directly. The data is fairly rough, but it gives an idea
about where things stand generally.
 - Mesh line primitive 4m Verts: 1.16x faster (36 -> 31 ms),
   showing that accessing just `MVert` is now more efficient.
 - Spring Splash Screen: 1.03-1.06 -> 1.06-1.11 FPS, a very slight
   change that at least shows there is no regression.
 - Sprite Fright Snail Smoosh: 3.30-3.40 -> 3.42-3.50 FPS, a small
   but observable speedup.
 - Set Position Node with Scaled Normal: 1.36x faster (53 -> 39 ms),
   shows that using normals in geometry nodes is faster.
 - Normal Calculation 1.6m Vert Cube: 1.19x faster (25 -> 21 ms),
   shows that calculating normals is slightly faster now.
 - File Size of 1.6m Vert Cube: 1.03x smaller (214.7 -> 208.4 MB),
   Normals are not saved in files, which can help with large meshes.

As for memory usage, it may be slightly more in some cases, but
I didn't observe any difference in the production files I tested.

**Tests**
Some modifiers and cycles test results need to be updated with this
commit, for two reasons:
 - The subdivision surface modifier is not responsible for calculating
   normals anymore. In master, the modifier creates different normals
   than the result of the `Mesh` normal calculation, so this is a bug
   fix.
 - There are small differences in the results of some modifiers that
   use normals because they are not converted to and from `short`
   anymore.

**Future improvements**
 - Remove `ModifierTypeInfo::dependsOnNormals`. Code in each modifier
   already retrieves normals if they are needed anyway.
 - Copy normals as part of a better CoW system for attributes.
 - Make more areas use lazy instead of eager normal calculation.
 - Remove `BKE_mesh_normals_tag_dirty` in more places since that is
   now the default state of a new mesh.
 - Possibly apply a similar change to derived face corner normals.

Differential Revision: https://developer.blender.org/D12770
2022-01-13 14:38:25 -06:00
Campbell Barton 3d3bc74884 Cleanup: remove redundant const qualifiers for POD types
MSVC used to warn about const mismatch for arguments passed by value.
Remove these as newer versions of MSVC no longer show this warning.
2022-01-07 14:16:26 +11:00
Campbell Barton fdb2167b4a Docs: use doxygen formatting for BLI
Differentiate doc-strings from title/section text.
2021-12-20 19:07:10 +11:00
Campbell Barton 9e365069af Cleanup: move public doc-strings into headers for 'blenlib'
- Added space below non doc-string comments to make it clear
  these aren't comments for the symbols directly below them.
- Use doxy sections for some headers.
- Minor improvements to doc-strings.

Ref T92709
2021-12-09 20:01:44 +11:00
Campbell Barton 357acd1d50 Cleanup: pass arguments as const 2021-10-04 13:15:15 +11:00
Sybren A. Stüvel 0342fb5d20 Fix T90387: division by zero when trying to invert scale
Fix division by zero when `BKE_bone_parent_transform_invert()` inverts a
scale vector with zero components.

Zero values in the to-be-inverted vector are now simply skipped, i.e.
remain zero after inversion. This at least ensures that
`invert_v3_safe(invert_v3_safe(vector))` results in the same vector.

This commit does NOT fix the conceptual problem that an inversion of a
potentially non-invertible vector is relied upon. It just avoids the
division by zero.
2021-08-03 13:43:42 +02:00
Campbell Barton 4b9ff3cd42 Cleanup: comment blocks, trailing space in comments 2021-06-24 15:59:34 +10:00
Bastien Montagne 748475b943 BLI_math: Cleanup: Use `mul_`/`madd_` functions.
Better to avoid explicit vectors components direct manipulation when a
generic operation for whole vector exists, if nothing else it avoids
potential mistakes in indices.
2021-06-14 12:32:38 +02:00
Bastien Montagne b21db5e698 BLI_math: Fix several division-by-zero cases.
Those were caused by various tools used on degenerate geometry, see
T79775.

Note that fixes are as low-level as possible, to ensure they cover as
much as possible of unreported issues too.

We still probably have many more of those hidden in BLI_math though.
2021-06-14 12:32:38 +02:00
Hans Goudey 1012e9bbfa Cleanup: Fix inconcistent array lengths in function declarations
In some cases functions were defined with arguments of different array
lengths in headers vs. implementations. This commit fixes some of the
cases I ran into, but probably not all of them.
2021-04-28 13:13:43 -05:00
Campbell Barton 16c621e529 Merge branch 'blender-v2.92-release' 2021-02-11 08:40:16 +11:00
Campbell Barton 4719836eca BLI_math: add mid_v2_v2v2v2 2021-02-11 08:27:28 +11:00
Campbell Barton b2a6e2abdb Cleanup: remove extra in trailing asterisk
Comment blocks not conforming to convention.
2021-01-20 16:14:00 +11:00
Clément Foucault 78dcd92edb BLI: Math: Add equals_v3v3_int 2020-09-05 17:49:14 +02:00
Sebastian Parborg 2115232a16 Cleanup: Clang-Tidy readability-inconsistent-declaration-parameter-name fix
No functional changes
2020-09-04 21:04:16 +02:00
Sebastian Parborg 1aa54d4921 Make rigidbody simulation handle animated objects gracefully
The animated objects was not updated for each internal substep for the rigidbody sim.
This would lead to unstable simulations or very annoying clipping artifacts.

Updated the code to use explicit substeps and tie it to the scene frame rate.

Fix T47402: Properly updating the animated objects fixes the reported issue.

Reviewed By: Brecht, Jacques

Differential Revision: http://developer.blender.org/D8762
2020-09-02 14:20:41 +02:00
Clément Foucault 4f395c84fe BLI_math_vector: Add equals_v4v4_int 2020-08-30 13:11:03 +02:00
Howard Trickey 9e09b5c418 Merge newboolean branch into master.
This is for design task T67744, Boolean Redesign.
It adds a choice of solver to the Boolean modifier and the
Intersect (Boolean) and Intersect (Knife) tools.
The 'Fast' choice is the current Bmesh boolean.
The new 'Exact' choice is a more advanced algorithm that supports
overlapping geometry and uses more robust calculations, but is
slower than the Fast choice.
The default with this commit is set to 'Exact'. We can decide before
the 2.91 release whether or not this is the right choice, but this
choice now will get us more testing and feedback on the new code.
2020-08-28 11:01:06 -04:00
Jacques Lucke 91694b9b58 Code Style: use "#pragma once" in source directory
This replaces header include guards with `#pragma once`.
A couple of include guards are not removed yet (e.g. `__RNA_TYPES_H__`),
because they are used in other places.

This patch has been generated by P1561 followed by `make format`.

Differential Revision: https://developer.blender.org/D8466
2020-08-07 09:50:34 +02:00
Germano Cavalcante 47b82fc02f Fix precision issues in 'interp_weights_poly_v2'
These precision issues were evident in corrected uvs when the option
`"Correct Face Attributes"` is enabled.
2020-07-28 09:53:07 -03:00
Pablo Dobarro d7282537f0 CD_PROP_COL datalayer
This implements a generic color datalayer and its functions. Based on
D5975.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D7838
2020-05-27 20:04:46 +02:00
Jacques Lucke 6f985574b7 Cleanup: take includes out of 'extern "C"' blocks
Surrounding includes with an 'extern "C"' block is not necessary anymore.
Also that made it harder to add any C++ code to some headers, or include headers
that have "optional" C++ code like `MEM_guardedalloc.h`.

I tested compilation on linux and windows (and got help from @LazyDodo).
If this still breaks compilation due to some linker error, the header containing
the symbol in question is probably missing an 'extern "C"' block.

Differential Revision: https://developer.blender.org/D7653
2020-05-08 18:22:41 +02:00
Ray Molenkamp 60741cfe18 Fix: Fix build error on windows
Headers and implementation had slightly different signatures
2020-05-01 08:06:34 -06:00
Campbell Barton ff1174e52c Cleanup: improve readability for color assignment 2020-05-01 15:05:25 +10:00
Dalai Felinto 96e2bd8493 Cleanup: Fix forward declaration of headers 2020-03-06 17:26:32 +01:00
Campbell Barton 89b10b8d42 BLI_math: inline clamp functions
These are used in some per-pixel operations such as image sampling and
color conversion, where replacing existing macro use could add overhead.
2020-03-04 11:23:00 +11:00
Tiago Chaves 14c9f64def BLI_math: add clamp_v# and clamp_v#_v#v# utility functions 2020-03-04 10:25:44 +11:00
Pablo Dobarro df45257ec5 Sculpt: Split normal radius and area radius
This enables an extra layer of control in the sculpt brushes.
For now it is enabled only in Scrape, but it should work in all brushes (like normal radius). In the future it may also be enabled in other brushes.
You can tweak in this property in the scrape brush to achieve a much better behavior when working on curve surfaces and control how much volume you want to trim. In most cases, it also fixes the bug where the brush keeps trimming in the same area without disabling accumulate.
It should be possible to fix some other artifacts in other brushes by tweaking this default property.

Reviewed By: jbakker

Differential Revision: https://developer.blender.org/D5993
2020-02-11 20:48:01 +01:00
Lukas Stockner c30d6571bb Add support for tiled images and the UDIM naming scheme
This patch contains the work that I did during my week at the Code Quest - adding support for tiled images to Blender.

With this patch, images now contain a list of tiles. By default, this just contains one tile, but if the source type is set to Tiled, the user can add additional tiles. When acquiring an ImBuf, the tile to be loaded is specified in the ImageUser.
Therefore, code that is not yet aware of tiles will just access the default tile as usual.

The filenames of the additional tiles are derived from the original filename according to the UDIM naming scheme - the filename contains an index that is calculated as (1001 + 10*<y coordinate of the tile> + <x coordinate of the tile>), where the x coordinate never goes above 9.
Internally, the various tiles are stored in a cache just like sequences. When acquired for the first time, the code will try to load the corresponding file from disk. Alternatively, a new operator can be used to initialize the tile similar to the New Image operator.

The following features are supported so far:
- Automatic detection and loading of all tiles when opening the first tile (1001)
- Saving all tiles
- Adding and removing tiles
- Filling tiles with generated images
- Drawing all tiles in the Image Editor
- Viewing a tiled grid even if no image is selected
- Rendering tiled images in Eevee
- Rendering tiled images in Cycles (in SVM mode)
- Automatically skipping loading of unused tiles in Cycles
- 2D texture painting (also across tiles)
- 3D texture painting (also across tiles, only limitation: individual faces can not cross tile borders)
- Assigning custom labels to individual tiles (drawn in the Image Editor instead of the ID)
- Different resolutions between tiles

There still are some missing features that will be added later (see T72390):
- Workbench engine support
- Packing/Unpacking support
- Baking support
- Cycles OSL support
- many other Blender features that rely on images

Thanks to Brecht for the review and to all who tested the intermediate versions!

Differential Revision: https://developer.blender.org/D3509
2019-12-12 18:40:37 +01:00
Jorge Bernal 5ff7827980 Cleanup: correct mul_v4_v4fl declaration 2019-11-14 00:09:39 +11:00
Howard Trickey 749567e0b2 Move math and vector double routines into blenlib from delaunay code 2019-08-28 18:33:24 -06:00
YimingWu 8bee9af462 BLI: double version of some math functions. 2019-08-20 21:09:55 +08:00
Campbell Barton e12c08e8d1 ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211.

For details on usage and instructions for migrating branches
without conflicts, see:

https://wiki.blender.org/wiki/Tools/ClangFormat
2019-04-17 06:21:24 +02:00
Campbell Barton 29039e5c74 Cleanup: remove compare_len_squared utility
There isn't any advantage to this over comparing the squared length.
2019-03-19 00:37:58 +11:00
Campbell Barton de13d0a80c doxygen: add newline after \file
While \file doesn't need an argument, it can't have another doxy
command after it.
2019-02-18 08:22:12 +11:00
Campbell Barton eef4077f18 Cleanup: remove redundant doxygen \file argument
Move \ingroup onto same line to be more compact and
make it clear the file is in the group.
2019-02-06 15:45:22 +11:00