2023-05-31 16:19:06 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2002-10-12 13:37:38 +02:00
|
|
|
|
2019-02-17 22:08:12 +01:00
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
2011-02-27 21:40:57 +01:00
|
|
|
*/
|
|
|
|
|
2022-12-29 18:01:32 +01:00
|
|
|
#include <cmath>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cstring>
|
Giant commit!
A full detailed description of this will be done later... is several days
of work. Here's a summary:
Render:
- Full cleanup of render code, removing *all* globals and bad level calls
all over blender. Render module is now not called abusive anymore
- API-fied calls to rendering
- Full recode of internal render pipeline. Is now rendering tiles by
default, prepared for much smarter 'bucket' render later.
- Each thread now can render a full part
- Renders were tested with 4 threads, goes fine, apart from some lookup
tables in softshadow and AO still
- Rendering is prepared to do multiple layers and passes
- No single 32 bits trick in render code anymore, all 100% floats now.
Writing images/movies
- moved writing images to blender kernel (bye bye 'schrijfplaatje'!)
- made a new Movie handle system, also in kernel. This will enable much
easier use of movies in Blender
PreviewRender:
- Using new render API, previewrender (in buttons) now uses regular render
code to generate images.
- new datafile 'preview.blend.c' has the preview scenes in it
- previews get rendered in exact displayed size (1 pixel = 1 pixel)
3D Preview render
- new; press Pkey in 3d window, for a panel that continuously renders
(pkey is for games, i know... but we dont do that in orange now!)
- this render works nearly identical to buttons-preview render, so it stops
rendering on any event (mouse, keyboard, etc)
- on moving/scaling the panel, the render code doesn't recreate all geometry
- same for shifting/panning view
- all other operations (now) regenerate the full render database still.
- this is WIP... but big fun, especially for simple scenes!
Compositor
- Using same node system as now in use for shaders, you can composit images
- works pretty straightforward... needs much more options/tools and integration
with rendering still
- is not threaded yet, nor is so smart to only recalculate changes... will be
done soon!
- the "Render Result" node will get all layers/passes as output sockets
- The "Output" node renders to a builtin image, which you can view in the Image
window. (yes, output nodes to render-result, and to files, is on the list!)
The Bad News
- "Unified Render" is removed. It might come back in some stage, but this
system should be built from scratch. I can't really understand this code...
I expect it is not much needed, especially with advanced layer/passes
control
- Panorama render, Field render, Motion blur, is not coded yet... (I had to
recode every single feature in render, so...!)
- Lens Flare is also not back... needs total revision, might become composit
effect though (using zbuffer for visibility)
- Part render is gone! (well, thats obvious, its default now).
- The render window is only restored with limited functionality... I am going
to check first the option to render to a Image window, so Blender can become
a true single-window application. :)
For example, the 'Spare render buffer' (jkey) doesnt work.
- Render with border, now default creates a smaller image
- No zbuffers are written yet... on the todo!
- Scons files and MSVC will need work to get compiling again
OK... thats what I can quickly recall. Now go compiling!
2006-01-23 23:05:47 +01:00
|
|
|
|
2019-02-01 02:44:19 +01:00
|
|
|
#include "CLG_log.h"
|
|
|
|
|
2002-10-12 13:37:38 +02:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2020-09-10 16:23:53 +02:00
|
|
|
/* Allow using deprecated functionality for .blend file I/O. */
|
|
|
|
#define DNA_DEPRECATED_ALLOW
|
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_ID.h"
|
Bugfix [#31834] Cycles materials cannot be manipulated using drivers
Until now, there was never any code for making drivers on materials get
recalculated when their dependencies were changed. However, since changing
material colors with drivers is something that is quite common, a workaround was
introduced to ensure that materials could still be driven (albeit with the
relevant drivers rooted at object level). This worked well enough so far with
traditional materials - though it was sometimes clunky and confusing for some
users - and would have been ok to tide us over until the depsgraph refactor.
The introduction of Cycles changed this, as it has in many other ways. Now that
people use Cycles to render, they'll need to drive the material colors through
the nested nodetree (and other things nested deeply within that). However, this
is much more difficult to generate hacks to create the relevant paths needed to
work around the problem.
== This Commit... ==
* Adds a recursive driver calculation step to the BKE_object_handle_update()
(which gets called whenever the depsgraph has finished tagging object datablocks
for updates), which goes through calculating the drivers attached to the object
(and the materials/nodetrees attached to that). This case gets handled everytime
the object is tagged as needing updates to its "data" (OB_RECALC_DATA)
* When building the depsgraph, every dependency that the drivers there have are
treated as if they were attached to object.data instead. This should trick the
depsgraph into tagging OB_RECALC_DATA to force recalculation of drivers, at the
expense perhaps of modifiers getting recalculated again.
== Todo ==
* The old workarounds noted are still in place (will be commented out in the
next commit). This fix renders at least the material case redundant, although
the textures case still needs a bit more work.
* Check on whether similar hacks can be done for other datablock combinations
* So far, only simple test cases have been tested. There is probably some
performance penalty for heavy setups still (due to need to traverse down all
parts of material/node hierarchy to find things that need updates). If there
really is a problem here, we could try introducing some tags to limit this
traversal (which get added at depsgraph build time). <--- USER TESTING
NEEDED!!!
2012-07-03 07:11:37 +02:00
|
|
|
#include "DNA_anim_types.h"
|
2018-08-29 15:32:50 +02:00
|
|
|
#include "DNA_collection_types.h"
|
Orange branch feature; Material Layering
(WIP, don't bugs for this in tracker yet please!)
- New Panel "Layers" in Material buttons, allows to add unlimited amount
of materials on top of each other.
- Every Layer is actually just another Material, which gets rendered/shaded
(including texture), and then added on top of previous layer with an
operation like Mix, Add, Mult, etc.
- Layers render fully independent, so bumpmaps are not passed on to next
layers.
- Per Layer you can set if it influences Diffuse, Specular or Alpha
- If a Material returns alpha (like from texture), the alpha value is
used for adding the layers too.
- New texture "Map To" channel allows to have a texture work on a Layer
- Each layer, including basis Material, can be turned on/off individually
Notes:
- at this moment, the full shading pass happens for each layer, including
shadow, AO and raytraced mirror or transparency...
- I had to remove old hacks from preview render, which corrected reflected
normals for preview texturing.
- still needs loadsa testing!
2005-12-04 15:32:21 +01:00
|
|
|
#include "DNA_curve_types.h"
|
Curves: Rename "Hair" types, variables, and functions to "Curves"
Based on discussions from T95355 and T94193, the plan is to use
the name "Curves" to describe the data-block container for multiple
curves. Eventually this will replace the existing "Curve" data-block.
However, it will be a while before the curve data-block can be replaced
so in order to distinguish the two curve types in the UI, "Hair Curves"
will be used, but eventually changed back to "Curves".
This patch renames "hair-related" files, functions, types, and variable
names to this convention. A deep rename is preferred to keep code
consistent and to avoid any "hair" terminology from leaking, since the
new data-block is meant for all curve types, not just hair use cases.
The downside of this naming is that the difference between "Curve"
and "Curves" has become important. That was considered during
design discussons and deemed acceptable, especially given the
non-permanent nature of the somewhat common conflict.
Some points of interest:
- All DNA compatibility is lost, just like rBf59767ff9729.
- I renamed `ID_HA` to `ID_CV` so there is no complete mismatch.
- `hair_curves` is used where necessary to distinguish from the
existing "curves" plural.
- I didn't rename any of the cycles/rendering code function names,
since that is also used by the old hair particle system.
Differential Revision: https://developer.blender.org/D14007
2022-02-07 18:55:54 +01:00
|
|
|
#include "DNA_curves_types.h"
|
TexFace to Material Settings big patch
Summary:
========
The idea here is to move the texface options into the material panel.
For images with the change please visit:
http://code.blender.org/index.php/2011/09/bge-material-texface-changes
1 - Some of the legacy problems 2.49 and 2.5x has with the texface system:
==========================================================================
1.1) Shadow, Bilboard and Halo are mutual exclusive (in the code), yet you can
select a face to be more than one mode.
1.2) Sort only works for blend Alpha yet it's an option regardless of the
Transparency Blend you pick.
1.3) Shared doesn't affect anything in BGE.
1.4) ObColor only works for Text objects (old bitmap texts) when using Texture
Face Materials. (not address yet, I so far ignored obcolor)
2 - Notes:
============
2.1) Now "Use Face Textures" in material Option panel will work in Multitexture
even if there is no texture channel.
2.2) In FaceTexture mode it will use TexFace all the time, even if you don't
check the "Use Texture Face" option in the UI. It's a matter of decision, since
the code for either way is there. I decided by the solution that makes the
creation of a material fast - in this mode the user doesn't need to mess with
textures or this "Use Texture Face" option at all. I'm not strong in my opinion
here. But I think if we don't have this then what is the point of the Texture
Face mode?
2.3) I kept references for tface only when we need the image, UV or the tiling
setting. It should help later when/if we split the Image and UV layers from the
tface struct (Campbell and Brecht proposal).
3 - Changes in a Nutshell:
==========================
3.1) "Texture Face" panel (in the Mesh/Object Data panel) no longer exists. Those settings are all part of the material properties, visible when Game Render is set.
3.2) "Texture Face" Shading mode (in the Render panel) is now called “Single Texture”, it needs a material for special settings (e.g. Billboard, Alpha Sort, …).
3.3) New options in the Material Panel
* Shadeless option in the Material panel is now supported for all three Shading modes.
* Physics is now toggleable, this is the old Collision option.
* Two Side (on) is now called Back Culling (off).
* Alpha Sort is one of the Alpha options, together (and mutually exclusive) to Alpha Blend, Alpha Clip, Add and Opaque (i.e. solid).
* Shadow, Billboard and Halo are grouped in the “Face Orientation” property.
* "Face Textures" and "Face Textures Alpha" (under Options) can be used for all but GLSL shading mode (to be supported in GLSL eventually).
* The backend in the game engine is still the same as before. The only changes are in the interface and in the way you need to think your materials. The bottomline is: It’s no longer possible to share materials between faces that do not share the same game properties.
4 - Acknowledgment:
==================
Mike Pan for the design discussions, and testing along the whole development process.
Vitor Balbio for the first hands-on code with the interface changes. That helped me a lot to push me into work on that.
Benoit Bolsee and Brecht van Lommel for patch review (* no one reviewed the whole patch, or the latest iteractions, so I still hold liability for any problems).
Blender artists that gave feedback and helped testing the patch.
Patch review and original documentation can be found here:
http://wiki.blender.org/index.php/User:Dfelinto/TexFace
http://codereview.appspot.com/4289041/
2011-09-19 21:55:59 +02:00
|
|
|
#include "DNA_customdata_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_defaults.h"
|
2023-03-13 10:42:51 +01:00
|
|
|
#include "DNA_gpencil_legacy_types.h"
|
2023-05-30 11:14:16 +02:00
|
|
|
#include "DNA_grease_pencil_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_material_types.h"
|
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
#include "DNA_meshdata_types.h"
|
2002-10-12 13:37:38 +02:00
|
|
|
#include "DNA_meta_types.h"
|
Christmas coding work!
********* Node editor work:
- To enable Nodes for Materials, you have to set the "Use Nodes"
button, in the new Material buttons "Nodes" Panel or in header
of the Node editor. Doing this will disable Material-Layers.
- Nodes now execute materials ("shaders"), but still only using the
previewrender code.
- Nodes have (optional) previews for rendered images.
- Node headers allow to hide buttons and/or preview image
- Nodes can be dragged larger/smaller (right-bottom corner)
- Nodes can be hidden (minimized) with hotkey H
- CTRL+click on an Input Socket gives a popup with default values.
- Changing Material/Texture or Mix node will adjust Node title.
- Click-drag outside of a Node changes cursor to "Knife' and allows to
draw a rect where to cut Links.
- Added new node types RGBtoBW, Texture, In/Output, ColorRamp
- Material Nodes have options to ouput diffuse or specular, or to use
a negative normal. The input socket 'Normal' will force the material
to use that normal, otherwise it uses the normal from the Material
that has the node tree.
- When drawing a link between two not-matching sockets, Blender inserts
a converting node (now only for value/rgb combos)
- When drawing a link to an input socket that's already in use, the
old link will either disappear or flip to another unused socket.
- A click on a Material Node will activate it, and show all its settings
in the Material Buttons. Active Material Nodes draw the material icon
in red.
- A click on any node will show its options in the Node Panel in the
Material buttons.
- Multiple Output Nodes can be used, to sample contents of a tree, but
only one Output is the real one, which is indicated in a different
color and red material icon.
- Added ThemeColors for node types
- ALT+C will convert existing Material-Layers to Node... this currently
only adds the material/mix nodes and connects them. Dunno if this is
worth a lot of coding work to make perfect?
- Press C to call another "Solve order", which will show all possible
cyclic conflicts (if there are).
- Technical: nodes now use "Type" structs which define the
structure of nodes and in/output sockets. The Type structs store all
fixed info, callbacks, and allow to reconstruct saved Nodes to match
what is required by Blender.
- Defining (new) nodes now is as simple as filling in a fixed
Type struct, plus code some callbacks. A doc will be made!
- Node preview images are by default float
********* Icon drawing:
- Cleanup of how old icons were implemented in new system, making
them 16x16 too, correctly centered *and* scaled.
- Made drawing Icons use float coordinates
- Moved BIF_calcpreview_image() into interface_icons.c, renamed it
icon_from_image(). Removed a lot of unneeded Imbuf magic here! :)
- Skipped scaling and imbuf copying when icons are OK size
********* Preview render:
- Huge cleanup of code....
- renaming BIF_xxx calls that only were used internally
- BIF_previewrender() now accepts an argument for rendering method,
so it supports icons, buttonwindow previewrender and node editor
- Only a single BIF_preview_changed() call now exists, supporting all
signals as needed for buttos and node editor
********* More stuff:
- glutil.c, glaDrawPixelsSafe() and glaDrawPixelsTex() now accept format
argument for GL_FLOAT rects
- Made the ColorBand become a built-in button for interface.c
Was a load of cleanup work in buttons_shading.c...
- removed a load of unneeded glBlendFunc() calls
- Fixed bug in calculating text length for buttons (ancient!)
2005-12-28 16:42:51 +01:00
|
|
|
#include "DNA_node_types.h"
|
Orange branch feature; Material Layering
(WIP, don't bugs for this in tracker yet please!)
- New Panel "Layers" in Material buttons, allows to add unlimited amount
of materials on top of each other.
- Every Layer is actually just another Material, which gets rendered/shaded
(including texture), and then added on top of previous layer with an
operation like Mix, Add, Mult, etc.
- Layers render fully independent, so bumpmaps are not passed on to next
layers.
- Per Layer you can set if it influences Diffuse, Specular or Alpha
- If a Material returns alpha (like from texture), the alpha value is
used for adding the layers too.
- New texture "Map To" channel allows to have a texture work on a Layer
- Each layer, including basis Material, can be turned on/off individually
Notes:
- at this moment, the full shading pass happens for each layer, including
shadow, AO and raytraced mirror or transparency...
- I had to remove old hacks from preview render, which corrected reflected
normals for preview texturing.
- still needs loadsa testing!
2005-12-04 15:32:21 +01:00
|
|
|
#include "DNA_object_types.h"
|
2021-09-27 18:07:01 +02:00
|
|
|
#include "DNA_particle_types.h"
|
2020-03-17 14:41:48 +01:00
|
|
|
#include "DNA_pointcloud_types.h"
|
2002-10-12 13:37:38 +02:00
|
|
|
#include "DNA_scene_types.h"
|
2020-03-17 14:41:48 +01:00
|
|
|
#include "DNA_volume_types.h"
|
2002-10-12 13:37:38 +02:00
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_array_utils.h"
|
2018-06-17 17:05:51 +02:00
|
|
|
#include "BLI_listbase.h"
|
Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).
However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.
This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.
Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).
Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.
Pull Request #110944
2023-08-09 10:39:20 +02:00
|
|
|
#include "BLI_math_color.h"
|
|
|
|
#include "BLI_math_vector.h"
|
2023-09-01 21:37:11 +02:00
|
|
|
#include "BLI_string.h"
|
2011-01-07 19:36:47 +01:00
|
|
|
#include "BLI_utildefines.h"
|
2002-10-12 13:37:38 +02:00
|
|
|
|
2020-03-06 16:38:04 +01:00
|
|
|
#include "BLT_translation.h"
|
|
|
|
|
2020-09-10 16:23:53 +02:00
|
|
|
#include "BKE_anim_data.h"
|
2022-04-08 16:37:35 +02:00
|
|
|
#include "BKE_attribute.h"
|
2023-08-02 22:14:18 +02:00
|
|
|
#include "BKE_brush.hh"
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_curve.hh"
|
Orange branch feature; Material Layering
(WIP, don't bugs for this in tracker yet please!)
- New Panel "Layers" in Material buttons, allows to add unlimited amount
of materials on top of each other.
- Every Layer is actually just another Material, which gets rendered/shaded
(including texture), and then added on top of previous layer with an
operation like Mix, Add, Mult, etc.
- Layers render fully independent, so bumpmaps are not passed on to next
layers.
- Per Layer you can set if it influences Diffuse, Specular or Alpha
- If a Material returns alpha (like from texture), the alpha value is
used for adding the layers too.
- New texture "Map To" channel allows to have a texture work on a Layer
- Each layer, including basis Material, can be turned on/off individually
Notes:
- at this moment, the full shading pass happens for each layer, including
shadow, AO and raytraced mirror or transparency...
- I had to remove old hacks from preview render, which corrected reflected
normals for preview texturing.
- still needs loadsa testing!
2005-12-04 15:32:21 +01:00
|
|
|
#include "BKE_displist.h"
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_editmesh.hh"
|
2023-03-13 10:42:51 +01:00
|
|
|
#include "BKE_gpencil_legacy.h"
|
2023-10-19 13:19:41 +02:00
|
|
|
#include "BKE_grease_pencil.hh"
|
2005-12-21 23:21:43 +01:00
|
|
|
#include "BKE_icons.h"
|
2020-03-06 16:38:04 +01:00
|
|
|
#include "BKE_idtype.h"
|
TexFace to Material Settings big patch
Summary:
========
The idea here is to move the texface options into the material panel.
For images with the change please visit:
http://code.blender.org/index.php/2011/09/bge-material-texface-changes
1 - Some of the legacy problems 2.49 and 2.5x has with the texface system:
==========================================================================
1.1) Shadow, Bilboard and Halo are mutual exclusive (in the code), yet you can
select a face to be more than one mode.
1.2) Sort only works for blend Alpha yet it's an option regardless of the
Transparency Blend you pick.
1.3) Shared doesn't affect anything in BGE.
1.4) ObColor only works for Text objects (old bitmap texts) when using Texture
Face Materials. (not address yet, I so far ignored obcolor)
2 - Notes:
============
2.1) Now "Use Face Textures" in material Option panel will work in Multitexture
even if there is no texture channel.
2.2) In FaceTexture mode it will use TexFace all the time, even if you don't
check the "Use Texture Face" option in the UI. It's a matter of decision, since
the code for either way is there. I decided by the solution that makes the
creation of a material fast - in this mode the user doesn't need to mess with
textures or this "Use Texture Face" option at all. I'm not strong in my opinion
here. But I think if we don't have this then what is the point of the Texture
Face mode?
2.3) I kept references for tface only when we need the image, UV or the tiling
setting. It should help later when/if we split the Image and UV layers from the
tface struct (Campbell and Brecht proposal).
3 - Changes in a Nutshell:
==========================
3.1) "Texture Face" panel (in the Mesh/Object Data panel) no longer exists. Those settings are all part of the material properties, visible when Game Render is set.
3.2) "Texture Face" Shading mode (in the Render panel) is now called “Single Texture”, it needs a material for special settings (e.g. Billboard, Alpha Sort, …).
3.3) New options in the Material Panel
* Shadeless option in the Material panel is now supported for all three Shading modes.
* Physics is now toggleable, this is the old Collision option.
* Two Side (on) is now called Back Culling (off).
* Alpha Sort is one of the Alpha options, together (and mutually exclusive) to Alpha Blend, Alpha Clip, Add and Opaque (i.e. solid).
* Shadow, Billboard and Halo are grouped in the “Face Orientation” property.
* "Face Textures" and "Face Textures Alpha" (under Options) can be used for all but GLSL shading mode (to be supported in GLSL eventually).
* The backend in the game engine is still the same as before. The only changes are in the interface and in the way you need to think your materials. The bottomline is: It’s no longer possible to share materials between faces that do not share the same game properties.
4 - Acknowledgment:
==================
Mike Pan for the design discussions, and testing along the whole development process.
Vitor Balbio for the first hands-on code with the interface changes. That helped me a lot to push me into work on that.
Benoit Bolsee and Brecht van Lommel for patch review (* no one reviewed the whole patch, or the latest iteractions, so I still hold liability for any problems).
Blender artists that gave feedback and helped testing the patch.
Patch review and original documentation can be found here:
http://wiki.blender.org/index.php/User:Dfelinto/TexFace
http://codereview.appspot.com/4289041/
2011-09-19 21:55:59 +02:00
|
|
|
#include "BKE_image.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_id.h"
|
2020-05-07 16:48:43 +02:00
|
|
|
#include "BKE_lib_query.h"
|
Orange branch feature; Material Layering
(WIP, don't bugs for this in tracker yet please!)
- New Panel "Layers" in Material buttons, allows to add unlimited amount
of materials on top of each other.
- Every Layer is actually just another Material, which gets rendered/shaded
(including texture), and then added on top of previous layer with an
operation like Mix, Add, Mult, etc.
- Layers render fully independent, so bumpmaps are not passed on to next
layers.
- Per Layer you can set if it influences Diffuse, Specular or Alpha
- If a Material returns alpha (like from texture), the alpha value is
used for adding the layers too.
- New texture "Map To" channel allows to have a texture work on a Layer
- Each layer, including basis Material, can be turned on/off individually
Notes:
- at this moment, the full shading pass happens for each layer, including
shadow, AO and raytraced mirror or transparency...
- I had to remove old hacks from preview render, which corrected reflected
normals for preview texturing.
- still needs loadsa testing!
2005-12-04 15:32:21 +01:00
|
|
|
#include "BKE_main.h"
|
2002-10-12 13:37:38 +02:00
|
|
|
#include "BKE_material.h"
|
2023-03-12 22:29:15 +01:00
|
|
|
#include "BKE_mesh.hh"
|
2023-05-15 15:14:22 +02:00
|
|
|
#include "BKE_node.hh"
|
2022-12-02 18:12:51 +01:00
|
|
|
#include "BKE_node_runtime.hh"
|
2023-10-09 23:41:53 +02:00
|
|
|
#include "BKE_object.hh"
|
2023-11-15 18:46:07 +01:00
|
|
|
#include "BKE_object_types.hh"
|
2023-09-04 18:02:16 +02:00
|
|
|
#include "BKE_preview_image.hh"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_scene.h"
|
2021-10-06 02:15:53 +02:00
|
|
|
#include "BKE_vfont.h"
|
2002-10-12 13:37:38 +02:00
|
|
|
|
2023-09-22 03:18:17 +02:00
|
|
|
#include "DEG_depsgraph.hh"
|
|
|
|
#include "DEG_depsgraph_build.hh"
|
|
|
|
#include "DEG_depsgraph_query.hh"
|
2017-04-06 16:11:50 +02:00
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 22:51:28 +02:00
|
|
|
#include "GPU_material.h"
|
2003-11-23 15:28:46 +01:00
|
|
|
|
2020-02-06 13:05:45 +01:00
|
|
|
#include "NOD_shader.h"
|
Giant commit!
A full detailed description of this will be done later... is several days
of work. Here's a summary:
Render:
- Full cleanup of render code, removing *all* globals and bad level calls
all over blender. Render module is now not called abusive anymore
- API-fied calls to rendering
- Full recode of internal render pipeline. Is now rendering tiles by
default, prepared for much smarter 'bucket' render later.
- Each thread now can render a full part
- Renders were tested with 4 threads, goes fine, apart from some lookup
tables in softshadow and AO still
- Rendering is prepared to do multiple layers and passes
- No single 32 bits trick in render code anymore, all 100% floats now.
Writing images/movies
- moved writing images to blender kernel (bye bye 'schrijfplaatje'!)
- made a new Movie handle system, also in kernel. This will enable much
easier use of movies in Blender
PreviewRender:
- Using new render API, previewrender (in buttons) now uses regular render
code to generate images.
- new datafile 'preview.blend.c' has the preview scenes in it
- previews get rendered in exact displayed size (1 pixel = 1 pixel)
3D Preview render
- new; press Pkey in 3d window, for a panel that continuously renders
(pkey is for games, i know... but we dont do that in orange now!)
- this render works nearly identical to buttons-preview render, so it stops
rendering on any event (mouse, keyboard, etc)
- on moving/scaling the panel, the render code doesn't recreate all geometry
- same for shifting/panning view
- all other operations (now) regenerate the full render database still.
- this is WIP... but big fun, especially for simple scenes!
Compositor
- Using same node system as now in use for shaders, you can composit images
- works pretty straightforward... needs much more options/tools and integration
with rendering still
- is not threaded yet, nor is so smart to only recalculate changes... will be
done soon!
- the "Render Result" node will get all layers/passes as output sockets
- The "Output" node renders to a builtin image, which you can view in the Image
window. (yes, output nodes to render-result, and to files, is on the list!)
The Bad News
- "Unified Render" is removed. It might come back in some stage, but this
system should be built from scratch. I can't really understand this code...
I expect it is not much needed, especially with advanced layer/passes
control
- Panorama render, Field render, Motion blur, is not coded yet... (I had to
recode every single feature in render, so...!)
- Lens Flare is also not back... needs total revision, might become composit
effect though (using zbuffer for visibility)
- Part render is gone! (well, thats obvious, its default now).
- The render window is only restored with limited functionality... I am going
to check first the option to render to a Image window, so Blender can become
a true single-window application. :)
For example, the 'Spare render buffer' (jkey) doesnt work.
- Render with border, now default creates a smaller image
- No zbuffers are written yet... on the todo!
- Scons files and MSVC will need work to get compiling again
OK... thats what I can quickly recall. Now go compiling!
2006-01-23 23:05:47 +01:00
|
|
|
|
2023-08-28 15:01:05 +02:00
|
|
|
#include "BLO_read_write.hh"
|
2020-09-10 16:23:53 +02:00
|
|
|
|
2019-02-01 02:44:19 +01:00
|
|
|
static CLG_LogRef LOG = {"bke.material"};
|
|
|
|
|
2020-03-06 16:38:04 +01:00
|
|
|
static void material_init_data(ID *id)
|
|
|
|
{
|
|
|
|
Material *material = (Material *)id;
|
|
|
|
|
|
|
|
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(material, id));
|
|
|
|
|
|
|
|
MEMCPY_STRUCT_AFTER(material, DNA_struct_default_get(Material), id);
|
2023-05-19 06:58:38 +02:00
|
|
|
|
|
|
|
*((short *)id->name) = ID_MA;
|
2020-03-06 16:38:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void material_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int flag)
|
|
|
|
{
|
|
|
|
Material *material_dst = (Material *)id_dst;
|
|
|
|
const Material *material_src = (const Material *)id_src;
|
|
|
|
|
2020-10-06 17:43:12 +02:00
|
|
|
const bool is_localized = (flag & LIB_ID_CREATE_LOCAL) != 0;
|
2020-03-06 16:38:04 +01:00
|
|
|
/* We always need allocation of our private ID data. */
|
|
|
|
const int flag_private_id_data = flag & ~LIB_ID_CREATE_NO_ALLOCATE;
|
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
if (material_src->nodetree != nullptr) {
|
2020-10-06 17:43:12 +02:00
|
|
|
if (is_localized) {
|
|
|
|
material_dst->nodetree = ntreeLocalize(material_src->nodetree);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BKE_id_copy_ex(bmain,
|
|
|
|
(ID *)material_src->nodetree,
|
|
|
|
(ID **)&material_dst->nodetree,
|
|
|
|
flag_private_id_data);
|
|
|
|
}
|
2022-09-06 14:57:44 +02:00
|
|
|
material_dst->nodetree->owner_id = &material_dst->id;
|
2020-03-06 16:38:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) {
|
|
|
|
BKE_previewimg_id_copy(&material_dst->id, &material_src->id);
|
|
|
|
}
|
|
|
|
else {
|
2022-11-18 11:08:39 +01:00
|
|
|
material_dst->preview = nullptr;
|
2020-03-06 16:38:04 +01:00
|
|
|
}
|
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
if (material_src->texpaintslot != nullptr) {
|
2020-10-06 17:43:12 +02:00
|
|
|
/* TODO: Think we can also skip copying this data in the more generic `NO_MAIN` case? */
|
2022-11-18 11:08:39 +01:00
|
|
|
material_dst->texpaintslot = is_localized ? nullptr :
|
|
|
|
static_cast<TexPaintSlot *>(
|
|
|
|
MEM_dupallocN(material_src->texpaintslot));
|
2020-03-06 16:38:04 +01:00
|
|
|
}
|
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
if (material_src->gp_style != nullptr) {
|
|
|
|
material_dst->gp_style = static_cast<MaterialGPencilStyle *>(
|
|
|
|
MEM_dupallocN(material_src->gp_style));
|
2020-03-06 16:38:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
BLI_listbase_clear(&material_dst->gpumaterial);
|
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
/* TODO: Duplicate Engine Settings and set runtime to nullptr. */
|
2020-03-06 16:38:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void material_free_data(ID *id)
|
2012-08-22 19:22:04 +02:00
|
|
|
{
|
2020-03-06 16:38:04 +01:00
|
|
|
Material *material = (Material *)id;
|
|
|
|
|
2018-03-05 00:52:19 +01:00
|
|
|
/* Free gpu material before the ntree */
|
2020-03-06 16:38:04 +01:00
|
|
|
GPU_material_free(&material->gpumaterial);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
Orange: more noodle updates!
**** NEW: Group Nodes
Node trees usually become messy and confusing quickly, so we need
not only a way to collapse Nodes into single 'groups', but also a
way to re-use that data to create libraries of effects.
This has been done by making a new Library data type, the NodeTree.
Everything that has been grouped is stored here, and available for
re-use, appending or linking. These NodeTrees are fully generic,
i.e. can store shader trees, composit trees, and so on. The 'type'
value as stored in the NodeTree will keep track of internal type
definitions and execute/drawing callbacks. Needless to say, re-using
shader trees in a composit tree is a bit useless, and will be
prevented in the browsing code. :)
So; any NodeTree can become a "Goup Node" inside in a NodeTree. This
Group Node then works just like any Node.
To prevent the current code to become too complex, I've disabled
the possibility to insert Groups inside of Groups. That might be
enabled later, but is a real nasty piece of code to get OK.
Since Group Nodes are a dynamic Node type, a lot of work has been
done to ensure Node definitions can be dynamic too, but still allow
to be stored in files, and allow to be verified for type-definition
changes on reloading. This system needs a little bit maturing still,
so the Python gurus should better wait a little bit! (Also for me to
write the definite API docs for it).
What works now:
- Press CTRL+G to create a new Group. The grouping code checks for
impossible selections (like an unselected node between selected nodes).
Everthing that's selected then gets removed from the current tree, and
inserted in a new NodeTree library data block. A Group Node then is
added which links to this new NodeTree.
- Press ALT+G to ungroup. This will not delete the NodeTree library
data, but just duplicate the Group into the current tree.
- Press TAB, or click on the NodeTree icon to edit Groups. Note that
NodeTrees are instances, so editing one Group will also change the
other users.
This also means that when removing nodes in a Group (or hiding sockets
or changing internal links) this is immediately corrected for all users
of this Group, also in other Materials.
- While editing Groups, only the internal Nodes can be edited. A single
click outside of the Group boundary will close this 'edit mode'.
What needs to be done:
- SHIFT+A menu in toolbox style, also including a list of Groups
- Enable the single-user button in the Group Node
- Displaying all (visible) internal group UI elements in the Node Panel
- Enable Library linking and prevent editing of Groups then.
**** NEW: Socket Visibility control
Node types will be generated with a lot of possible inputs or outputs,
and drawing all sockets all the time isn't very useful then.
A new option in the Node header ('plus' icon) allows to either hide all
unused sockets (first keypress) or to reveil them (when there are hidden
sockets, the icon displays black, otherwise it's blended).
Hidden sockets in Nodes also are not exported to a Group, so this way
you can control what options (in/outputs) exactly are available.
To be done:
- a way to hide individual sockets, like with a RMB click on it.
**** NEW: Nodes now render!
This is still quite primitive, more on a level to replace the (now
obsolete and disabled) Material Layers.
What needs to be done:
- make the "Geometry" node work properly, also for AA textures
- make the Texture Node work (does very little at the moment)
- give Material Nodes all inputs as needed (like Map-to Panel)
- find a way to export more data from a Material Node, like the
shadow value, or light intensity only, etc
Very important also to separate from the Material Buttons the
"global" options, like "Ztransp" or "Wire" or "Halo". These can not
be set for each Material-Node individually.
Also note that the Preview Render (Buttons window) now renders a bit
differently. This was a horrid piece of antique code, using a totally
incompatible way of rendering. Target is to fully re-use internal
render code for previews.
OK... that's it mostly. Now test!
2006-01-02 14:06:05 +01:00
|
|
|
/* is no lib link block, but material extension */
|
2020-03-06 16:38:04 +01:00
|
|
|
if (material->nodetree) {
|
2020-04-20 16:14:45 +02:00
|
|
|
ntreeFreeEmbeddedTree(material->nodetree);
|
2020-03-06 16:38:04 +01:00
|
|
|
MEM_freeN(material->nodetree);
|
2022-11-18 11:08:39 +01:00
|
|
|
material->nodetree = nullptr;
|
Orange: more noodle updates!
**** NEW: Group Nodes
Node trees usually become messy and confusing quickly, so we need
not only a way to collapse Nodes into single 'groups', but also a
way to re-use that data to create libraries of effects.
This has been done by making a new Library data type, the NodeTree.
Everything that has been grouped is stored here, and available for
re-use, appending or linking. These NodeTrees are fully generic,
i.e. can store shader trees, composit trees, and so on. The 'type'
value as stored in the NodeTree will keep track of internal type
definitions and execute/drawing callbacks. Needless to say, re-using
shader trees in a composit tree is a bit useless, and will be
prevented in the browsing code. :)
So; any NodeTree can become a "Goup Node" inside in a NodeTree. This
Group Node then works just like any Node.
To prevent the current code to become too complex, I've disabled
the possibility to insert Groups inside of Groups. That might be
enabled later, but is a real nasty piece of code to get OK.
Since Group Nodes are a dynamic Node type, a lot of work has been
done to ensure Node definitions can be dynamic too, but still allow
to be stored in files, and allow to be verified for type-definition
changes on reloading. This system needs a little bit maturing still,
so the Python gurus should better wait a little bit! (Also for me to
write the definite API docs for it).
What works now:
- Press CTRL+G to create a new Group. The grouping code checks for
impossible selections (like an unselected node between selected nodes).
Everthing that's selected then gets removed from the current tree, and
inserted in a new NodeTree library data block. A Group Node then is
added which links to this new NodeTree.
- Press ALT+G to ungroup. This will not delete the NodeTree library
data, but just duplicate the Group into the current tree.
- Press TAB, or click on the NodeTree icon to edit Groups. Note that
NodeTrees are instances, so editing one Group will also change the
other users.
This also means that when removing nodes in a Group (or hiding sockets
or changing internal links) this is immediately corrected for all users
of this Group, also in other Materials.
- While editing Groups, only the internal Nodes can be edited. A single
click outside of the Group boundary will close this 'edit mode'.
What needs to be done:
- SHIFT+A menu in toolbox style, also including a list of Groups
- Enable the single-user button in the Group Node
- Displaying all (visible) internal group UI elements in the Node Panel
- Enable Library linking and prevent editing of Groups then.
**** NEW: Socket Visibility control
Node types will be generated with a lot of possible inputs or outputs,
and drawing all sockets all the time isn't very useful then.
A new option in the Node header ('plus' icon) allows to either hide all
unused sockets (first keypress) or to reveil them (when there are hidden
sockets, the icon displays black, otherwise it's blended).
Hidden sockets in Nodes also are not exported to a Group, so this way
you can control what options (in/outputs) exactly are available.
To be done:
- a way to hide individual sockets, like with a RMB click on it.
**** NEW: Nodes now render!
This is still quite primitive, more on a level to replace the (now
obsolete and disabled) Material Layers.
What needs to be done:
- make the "Geometry" node work properly, also for AA textures
- make the Texture Node work (does very little at the moment)
- give Material Nodes all inputs as needed (like Map-to Panel)
- find a way to export more data from a Material Node, like the
shadow value, or light intensity only, etc
Very important also to separate from the Material Buttons the
"global" options, like "Ztransp" or "Wire" or "Halo". These can not
be set for each Material-Node individually.
Also note that the Preview Render (Buttons window) now renders a bit
differently. This was a horrid piece of antique code, using a totally
incompatible way of rendering. Target is to fully re-use internal
render code for previews.
OK... that's it mostly. Now test!
2006-01-02 14:06:05 +01:00
|
|
|
}
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 22:51:28 +02:00
|
|
|
|
2020-03-06 16:38:04 +01:00
|
|
|
MEM_SAFE_FREE(material->texpaintslot);
|
ID-Remap - Step one: core work (cleanup and rework of generic ID datablock handling).
This commit changes a lot of how IDs are handled internally, especially the unlinking/freeing
processes. So far, this was very fuzy, to summarize cleanly deleting or replacing a datablock
was pretty much impossible, except for a few special cases.
Also, unlinking was handled by each datatype, in a rather messy and prone-to-errors way (quite
a few ID usages were missed or wrongly handled that way).
One of the main goal of id-remap branch was to cleanup this, and fatorize ID links handling
by using library_query utils to allow generic handling of those, which is now the case
(now, generic ID links handling is only "knwon" from readfile.c and library_query.c).
This commit also adds backends to allow live replacement and deletion of datablocks in Blender
(so-called 'remapping' process, where we replace all usages of a given ID pointer by a new one,
or NULL one in case of unlinking).
This will allow nice new features, like ability to easily reload or relocate libraries, real immediate
deletion of datablocks in blender, replacement of one datablock by another, etc.
Some of those are for next commits.
A word of warning: this commit is highly risky, because it affects potentially a lot in Blender core.
Though it was tested rather deeply, being totally impossible to check all possible ID usage cases,
it's likely there are some remaining issues and bugs in new code... Please report them! ;)
Review task: D2027 (https://developer.blender.org/D2027).
Reviewed by campbellbarton, thanks a bunch.
2016-06-22 17:29:38 +02:00
|
|
|
|
2020-03-06 16:38:04 +01:00
|
|
|
MEM_SAFE_FREE(material->gp_style);
|
2018-07-31 10:22:19 +02:00
|
|
|
|
2020-03-06 16:38:04 +01:00
|
|
|
BKE_previewimg_free(&material->preview);
|
2023-05-30 07:50:27 +02:00
|
|
|
|
|
|
|
BKE_icon_id_delete((ID *)material);
|
2002-10-12 13:37:38 +02:00
|
|
|
}
|
|
|
|
|
2020-05-07 16:48:43 +02:00
|
|
|
static void material_foreach_id(ID *id, LibraryForeachIDData *data)
|
|
|
|
{
|
2023-08-22 15:42:19 +02:00
|
|
|
Material *material = reinterpret_cast<Material *>(id);
|
|
|
|
const int flag = BKE_lib_query_foreachid_process_flags_get(data);
|
|
|
|
|
2023-07-09 13:22:31 +02:00
|
|
|
/* Node-trees **are owned by IDs**, treat them as mere sub-data and not real ID! */
|
2021-10-27 11:30:43 +02:00
|
|
|
BKE_LIB_FOREACHID_PROCESS_FUNCTION_CALL(
|
|
|
|
data, BKE_library_foreach_ID_embedded(data, (ID **)&material->nodetree));
|
2022-11-18 11:08:39 +01:00
|
|
|
if (material->texpaintslot != nullptr) {
|
2021-10-26 10:40:36 +02:00
|
|
|
BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, material->texpaintslot->ima, IDWALK_CB_NOP);
|
2020-05-07 16:48:43 +02:00
|
|
|
}
|
2022-11-18 11:08:39 +01:00
|
|
|
if (material->gp_style != nullptr) {
|
2021-10-26 10:40:36 +02:00
|
|
|
BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, material->gp_style->sima, IDWALK_CB_USER);
|
|
|
|
BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, material->gp_style->ima, IDWALK_CB_USER);
|
2020-05-07 16:48:43 +02:00
|
|
|
}
|
2023-08-22 15:42:19 +02:00
|
|
|
|
|
|
|
if (flag & IDWALK_DO_DEPRECATED_POINTERS) {
|
|
|
|
BKE_LIB_FOREACHID_PROCESS_ID_NOCHECK(data, material->ipo, IDWALK_CB_USER);
|
|
|
|
}
|
2020-05-07 16:48:43 +02:00
|
|
|
}
|
|
|
|
|
2020-09-10 16:23:53 +02:00
|
|
|
static void material_blend_write(BlendWriter *writer, ID *id, const void *id_address)
|
|
|
|
{
|
|
|
|
Material *ma = (Material *)id;
|
|
|
|
|
2021-08-19 11:13:55 +02:00
|
|
|
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
|
2022-11-18 11:08:39 +01:00
|
|
|
ma->texpaintslot = nullptr;
|
2021-08-19 11:13:55 +02:00
|
|
|
BLI_listbase_clear(&ma->gpumaterial);
|
2020-09-10 16:23:53 +02:00
|
|
|
|
2021-08-19 11:13:55 +02:00
|
|
|
/* write LibData */
|
|
|
|
BLO_write_id_struct(writer, Material, id_address, &ma->id);
|
|
|
|
BKE_id_blend_write(writer, &ma->id);
|
2020-09-10 16:23:53 +02:00
|
|
|
|
2021-08-19 11:13:55 +02:00
|
|
|
/* nodetree is integral part of material, no libdata */
|
|
|
|
if (ma->nodetree) {
|
2023-04-14 10:35:31 +02:00
|
|
|
BLO_Write_IDBuffer *temp_embedded_id_buffer = BLO_write_allocate_id_buffer();
|
|
|
|
BLO_write_init_id_buffer_from_id(
|
|
|
|
temp_embedded_id_buffer, &ma->nodetree->id, BLO_write_is_undo(writer));
|
|
|
|
BLO_write_struct_at_address(
|
|
|
|
writer, bNodeTree, ma->nodetree, BLO_write_get_id_buffer_temp_id(temp_embedded_id_buffer));
|
|
|
|
ntreeBlendWrite(
|
|
|
|
writer,
|
|
|
|
reinterpret_cast<bNodeTree *>(BLO_write_get_id_buffer_temp_id(temp_embedded_id_buffer)));
|
|
|
|
BLO_write_destroy_id_buffer(&temp_embedded_id_buffer);
|
2021-08-19 11:13:55 +02:00
|
|
|
}
|
2020-09-10 16:23:53 +02:00
|
|
|
|
2021-08-19 11:13:55 +02:00
|
|
|
BKE_previewimg_blend_write(writer, ma->preview);
|
2020-09-10 16:23:53 +02:00
|
|
|
|
2021-08-19 11:13:55 +02:00
|
|
|
/* grease pencil settings */
|
|
|
|
if (ma->gp_style) {
|
|
|
|
BLO_write_struct(writer, MaterialGPencilStyle, ma->gp_style);
|
2020-09-10 16:23:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void material_blend_read_data(BlendDataReader *reader, ID *id)
|
|
|
|
{
|
|
|
|
Material *ma = (Material *)id;
|
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
ma->texpaintslot = nullptr;
|
2020-09-10 16:23:53 +02:00
|
|
|
|
|
|
|
BLO_read_data_address(reader, &ma->preview);
|
|
|
|
BKE_previewimg_blend_read(reader, ma->preview);
|
|
|
|
|
|
|
|
BLI_listbase_clear(&ma->gpumaterial);
|
|
|
|
|
|
|
|
BLO_read_data_address(reader, &ma->gp_style);
|
|
|
|
}
|
|
|
|
|
2020-03-06 16:38:04 +01:00
|
|
|
IDTypeInfo IDType_ID_MA = {
|
2023-01-16 02:41:11 +01:00
|
|
|
/*id_code*/ ID_MA,
|
|
|
|
/*id_filter*/ FILTER_ID_MA,
|
|
|
|
/*main_listbase_index*/ INDEX_ID_MA,
|
|
|
|
/*struct_size*/ sizeof(Material),
|
|
|
|
/*name*/ "Material",
|
2023-10-04 02:53:31 +02:00
|
|
|
/*name_plural*/ N_("materials"),
|
2023-01-16 02:41:11 +01:00
|
|
|
/*translation_context*/ BLT_I18NCONTEXT_ID_MATERIAL,
|
|
|
|
/*flags*/ IDTYPE_FLAGS_APPEND_IS_REUSABLE,
|
|
|
|
/*asset_type_info*/ nullptr,
|
|
|
|
|
|
|
|
/*init_data*/ material_init_data,
|
|
|
|
/*copy_data*/ material_copy_data,
|
|
|
|
/*free_data*/ material_free_data,
|
|
|
|
/*make_local*/ nullptr,
|
|
|
|
/*foreach_id*/ material_foreach_id,
|
|
|
|
/*foreach_cache*/ nullptr,
|
|
|
|
/*foreach_path*/ nullptr,
|
|
|
|
/*owner_pointer_get*/ nullptr,
|
|
|
|
|
|
|
|
/*blend_write*/ material_blend_write,
|
|
|
|
/*blend_read_data*/ material_blend_read_data,
|
2023-03-11 18:07:59 +01:00
|
|
|
/*blend_read_after_liblink*/ nullptr,
|
2023-01-16 02:41:11 +01:00
|
|
|
|
|
|
|
/*blend_read_undo_preserve*/ nullptr,
|
|
|
|
|
|
|
|
/*lib_override_apply_post*/ nullptr,
|
2020-03-06 16:38:04 +01:00
|
|
|
};
|
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
void BKE_gpencil_material_attr_init(Material *ma)
|
2018-07-31 10:22:19 +02:00
|
|
|
{
|
2022-11-18 11:08:39 +01:00
|
|
|
if ((ma) && (ma->gp_style == nullptr)) {
|
|
|
|
ma->gp_style = static_cast<MaterialGPencilStyle *>(
|
|
|
|
MEM_callocN(sizeof(MaterialGPencilStyle), "Grease Pencil Material Settings"));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-31 10:22:19 +02:00
|
|
|
MaterialGPencilStyle *gp_style = ma->gp_style;
|
|
|
|
/* set basic settings */
|
|
|
|
gp_style->stroke_rgba[3] = 1.0f;
|
2019-03-02 14:15:56 +01:00
|
|
|
gp_style->fill_rgba[3] = 1.0f;
|
2020-04-27 10:49:33 +02:00
|
|
|
ARRAY_SET_ITEMS(gp_style->mix_rgba, 1.0f, 1.0f, 1.0f, 1.0f);
|
2018-07-31 10:22:19 +02:00
|
|
|
ARRAY_SET_ITEMS(gp_style->texture_scale, 1.0f, 1.0f);
|
2020-04-27 10:49:33 +02:00
|
|
|
gp_style->texture_offset[0] = -0.5f;
|
2018-07-31 10:22:19 +02:00
|
|
|
gp_style->texture_pixsize = 100.0f;
|
2020-04-27 10:49:33 +02:00
|
|
|
gp_style->mix_factor = 0.5f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-09 16:27:24 +01:00
|
|
|
gp_style->flag |= GP_MATERIAL_STROKE_SHOW;
|
2018-07-31 10:22:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-08 17:36:06 +02:00
|
|
|
static void nodetree_mark_previews_dirty_reccursive(bNodeTree *tree)
|
|
|
|
{
|
|
|
|
if (tree == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
tree->runtime->previews_refresh_state++;
|
|
|
|
for (bNode *node : tree->all_nodes()) {
|
|
|
|
if (node->type == NODE_GROUP) {
|
|
|
|
bNodeTree *nested_tree = reinterpret_cast<bNodeTree *>(node->id);
|
|
|
|
nodetree_mark_previews_dirty_reccursive(nested_tree);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_material_make_node_previews_dirty(Material *ma)
|
|
|
|
{
|
|
|
|
if (ma && ma->nodetree) {
|
|
|
|
nodetree_mark_previews_dirty_reccursive(ma->nodetree);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-05 13:46:15 +01:00
|
|
|
Material *BKE_material_add(Main *bmain, const char *name)
|
2002-10-12 13:37:38 +02:00
|
|
|
{
|
|
|
|
Material *ma;
|
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
ma = static_cast<Material *>(BKE_id_new(bmain, ID_MA, name));
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2012-10-21 07:46:41 +02:00
|
|
|
return ma;
|
2002-10-12 13:37:38 +02:00
|
|
|
}
|
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
Material *BKE_gpencil_material_add(Main *bmain, const char *name)
|
2018-07-31 10:22:19 +02:00
|
|
|
{
|
|
|
|
Material *ma;
|
|
|
|
|
|
|
|
ma = BKE_material_add(bmain, name);
|
|
|
|
|
|
|
|
/* grease pencil settings */
|
2022-11-18 11:08:39 +01:00
|
|
|
if (ma != nullptr) {
|
2020-02-05 11:23:58 +01:00
|
|
|
BKE_gpencil_material_attr_init(ma);
|
2018-10-26 09:02:28 +02:00
|
|
|
}
|
2018-07-31 10:22:19 +02:00
|
|
|
return ma;
|
|
|
|
}
|
|
|
|
|
2020-03-04 22:08:23 +01:00
|
|
|
Material ***BKE_object_material_array_p(Object *ob)
|
2002-10-12 13:37:38 +02:00
|
|
|
{
|
2012-05-06 17:15:33 +02:00
|
|
|
if (ob->type == OB_MESH) {
|
2022-11-18 11:08:39 +01:00
|
|
|
Mesh *me = static_cast<Mesh *>(ob->data);
|
2002-10-12 13:37:38 +02:00
|
|
|
return &(me->mat);
|
|
|
|
}
|
2022-02-18 16:50:29 +01:00
|
|
|
if (ELEM(ob->type, OB_CURVES_LEGACY, OB_FONT, OB_SURF)) {
|
2022-11-18 11:08:39 +01:00
|
|
|
Curve *cu = static_cast<Curve *>(ob->data);
|
2002-10-12 13:37:38 +02:00
|
|
|
return &(cu->mat);
|
|
|
|
}
|
2020-08-07 12:30:43 +02:00
|
|
|
if (ob->type == OB_MBALL) {
|
2022-11-18 11:08:39 +01:00
|
|
|
MetaBall *mb = static_cast<MetaBall *>(ob->data);
|
2002-10-12 13:37:38 +02:00
|
|
|
return &(mb->mat);
|
|
|
|
}
|
2023-03-08 12:35:58 +01:00
|
|
|
if (ob->type == OB_GPENCIL_LEGACY) {
|
2022-11-18 11:08:39 +01:00
|
|
|
bGPdata *gpd = static_cast<bGPdata *>(ob->data);
|
2018-07-31 10:22:19 +02:00
|
|
|
return &(gpd->mat);
|
|
|
|
}
|
Curves: Rename "Hair" types, variables, and functions to "Curves"
Based on discussions from T95355 and T94193, the plan is to use
the name "Curves" to describe the data-block container for multiple
curves. Eventually this will replace the existing "Curve" data-block.
However, it will be a while before the curve data-block can be replaced
so in order to distinguish the two curve types in the UI, "Hair Curves"
will be used, but eventually changed back to "Curves".
This patch renames "hair-related" files, functions, types, and variable
names to this convention. A deep rename is preferred to keep code
consistent and to avoid any "hair" terminology from leaking, since the
new data-block is meant for all curve types, not just hair use cases.
The downside of this naming is that the difference between "Curve"
and "Curves" has become important. That was considered during
design discussons and deemed acceptable, especially given the
non-permanent nature of the somewhat common conflict.
Some points of interest:
- All DNA compatibility is lost, just like rBf59767ff9729.
- I renamed `ID_HA` to `ID_CV` so there is no complete mismatch.
- `hair_curves` is used where necessary to distinguish from the
existing "curves" plural.
- I didn't rename any of the cycles/rendering code function names,
since that is also used by the old hair particle system.
Differential Revision: https://developer.blender.org/D14007
2022-02-07 18:55:54 +01:00
|
|
|
if (ob->type == OB_CURVES) {
|
2022-11-18 11:08:39 +01:00
|
|
|
Curves *curves = static_cast<Curves *>(ob->data);
|
Curves: Rename "Hair" types, variables, and functions to "Curves"
Based on discussions from T95355 and T94193, the plan is to use
the name "Curves" to describe the data-block container for multiple
curves. Eventually this will replace the existing "Curve" data-block.
However, it will be a while before the curve data-block can be replaced
so in order to distinguish the two curve types in the UI, "Hair Curves"
will be used, but eventually changed back to "Curves".
This patch renames "hair-related" files, functions, types, and variable
names to this convention. A deep rename is preferred to keep code
consistent and to avoid any "hair" terminology from leaking, since the
new data-block is meant for all curve types, not just hair use cases.
The downside of this naming is that the difference between "Curve"
and "Curves" has become important. That was considered during
design discussons and deemed acceptable, especially given the
non-permanent nature of the somewhat common conflict.
Some points of interest:
- All DNA compatibility is lost, just like rBf59767ff9729.
- I renamed `ID_HA` to `ID_CV` so there is no complete mismatch.
- `hair_curves` is used where necessary to distinguish from the
existing "curves" plural.
- I didn't rename any of the cycles/rendering code function names,
since that is also used by the old hair particle system.
Differential Revision: https://developer.blender.org/D14007
2022-02-07 18:55:54 +01:00
|
|
|
return &(curves->mat);
|
2020-03-17 14:41:48 +01:00
|
|
|
}
|
2020-08-07 12:30:43 +02:00
|
|
|
if (ob->type == OB_POINTCLOUD) {
|
2022-11-18 11:08:39 +01:00
|
|
|
PointCloud *pointcloud = static_cast<PointCloud *>(ob->data);
|
2020-03-17 14:41:48 +01:00
|
|
|
return &(pointcloud->mat);
|
|
|
|
}
|
2020-08-07 12:30:43 +02:00
|
|
|
if (ob->type == OB_VOLUME) {
|
2022-11-18 11:08:39 +01:00
|
|
|
Volume *volume = static_cast<Volume *>(ob->data);
|
2020-03-17 14:41:48 +01:00
|
|
|
return &(volume->mat);
|
|
|
|
}
|
2023-05-30 11:14:16 +02:00
|
|
|
if (ob->type == OB_GREASE_PENCIL) {
|
|
|
|
GreasePencil *grease_pencil = static_cast<GreasePencil *>(ob->data);
|
|
|
|
return &(grease_pencil->material_array);
|
|
|
|
}
|
2022-11-18 11:08:39 +01:00
|
|
|
return nullptr;
|
2002-10-12 13:37:38 +02:00
|
|
|
}
|
|
|
|
|
2020-03-04 22:08:23 +01:00
|
|
|
short *BKE_object_material_len_p(Object *ob)
|
2002-10-12 13:37:38 +02:00
|
|
|
{
|
2012-05-06 17:15:33 +02:00
|
|
|
if (ob->type == OB_MESH) {
|
2022-11-18 11:08:39 +01:00
|
|
|
Mesh *me = static_cast<Mesh *>(ob->data);
|
2002-10-12 13:37:38 +02:00
|
|
|
return &(me->totcol);
|
|
|
|
}
|
2022-02-18 16:50:29 +01:00
|
|
|
if (ELEM(ob->type, OB_CURVES_LEGACY, OB_FONT, OB_SURF)) {
|
2022-11-18 11:08:39 +01:00
|
|
|
Curve *cu = static_cast<Curve *>(ob->data);
|
2002-10-12 13:37:38 +02:00
|
|
|
return &(cu->totcol);
|
|
|
|
}
|
2020-08-07 12:30:43 +02:00
|
|
|
if (ob->type == OB_MBALL) {
|
2022-11-18 11:08:39 +01:00
|
|
|
MetaBall *mb = static_cast<MetaBall *>(ob->data);
|
2002-10-12 13:37:38 +02:00
|
|
|
return &(mb->totcol);
|
|
|
|
}
|
2023-03-08 12:35:58 +01:00
|
|
|
if (ob->type == OB_GPENCIL_LEGACY) {
|
2022-11-18 11:08:39 +01:00
|
|
|
bGPdata *gpd = static_cast<bGPdata *>(ob->data);
|
2018-07-31 10:22:19 +02:00
|
|
|
return &(gpd->totcol);
|
|
|
|
}
|
Curves: Rename "Hair" types, variables, and functions to "Curves"
Based on discussions from T95355 and T94193, the plan is to use
the name "Curves" to describe the data-block container for multiple
curves. Eventually this will replace the existing "Curve" data-block.
However, it will be a while before the curve data-block can be replaced
so in order to distinguish the two curve types in the UI, "Hair Curves"
will be used, but eventually changed back to "Curves".
This patch renames "hair-related" files, functions, types, and variable
names to this convention. A deep rename is preferred to keep code
consistent and to avoid any "hair" terminology from leaking, since the
new data-block is meant for all curve types, not just hair use cases.
The downside of this naming is that the difference between "Curve"
and "Curves" has become important. That was considered during
design discussons and deemed acceptable, especially given the
non-permanent nature of the somewhat common conflict.
Some points of interest:
- All DNA compatibility is lost, just like rBf59767ff9729.
- I renamed `ID_HA` to `ID_CV` so there is no complete mismatch.
- `hair_curves` is used where necessary to distinguish from the
existing "curves" plural.
- I didn't rename any of the cycles/rendering code function names,
since that is also used by the old hair particle system.
Differential Revision: https://developer.blender.org/D14007
2022-02-07 18:55:54 +01:00
|
|
|
if (ob->type == OB_CURVES) {
|
2022-11-18 11:08:39 +01:00
|
|
|
Curves *curves = static_cast<Curves *>(ob->data);
|
Curves: Rename "Hair" types, variables, and functions to "Curves"
Based on discussions from T95355 and T94193, the plan is to use
the name "Curves" to describe the data-block container for multiple
curves. Eventually this will replace the existing "Curve" data-block.
However, it will be a while before the curve data-block can be replaced
so in order to distinguish the two curve types in the UI, "Hair Curves"
will be used, but eventually changed back to "Curves".
This patch renames "hair-related" files, functions, types, and variable
names to this convention. A deep rename is preferred to keep code
consistent and to avoid any "hair" terminology from leaking, since the
new data-block is meant for all curve types, not just hair use cases.
The downside of this naming is that the difference between "Curve"
and "Curves" has become important. That was considered during
design discussons and deemed acceptable, especially given the
non-permanent nature of the somewhat common conflict.
Some points of interest:
- All DNA compatibility is lost, just like rBf59767ff9729.
- I renamed `ID_HA` to `ID_CV` so there is no complete mismatch.
- `hair_curves` is used where necessary to distinguish from the
existing "curves" plural.
- I didn't rename any of the cycles/rendering code function names,
since that is also used by the old hair particle system.
Differential Revision: https://developer.blender.org/D14007
2022-02-07 18:55:54 +01:00
|
|
|
return &(curves->totcol);
|
2020-03-17 14:41:48 +01:00
|
|
|
}
|
2020-08-07 12:30:43 +02:00
|
|
|
if (ob->type == OB_POINTCLOUD) {
|
2022-11-18 11:08:39 +01:00
|
|
|
PointCloud *pointcloud = static_cast<PointCloud *>(ob->data);
|
2020-03-17 14:41:48 +01:00
|
|
|
return &(pointcloud->totcol);
|
|
|
|
}
|
2020-08-07 12:30:43 +02:00
|
|
|
if (ob->type == OB_VOLUME) {
|
2022-11-18 11:08:39 +01:00
|
|
|
Volume *volume = static_cast<Volume *>(ob->data);
|
2020-03-17 14:41:48 +01:00
|
|
|
return &(volume->totcol);
|
|
|
|
}
|
2023-05-30 11:14:16 +02:00
|
|
|
if (ob->type == OB_GREASE_PENCIL) {
|
|
|
|
GreasePencil *grease_pencil = static_cast<GreasePencil *>(ob->data);
|
2023-06-04 11:48:14 +02:00
|
|
|
return &(grease_pencil->material_array_num);
|
2023-05-30 11:14:16 +02:00
|
|
|
}
|
2022-11-18 11:08:39 +01:00
|
|
|
return nullptr;
|
2002-10-12 13:37:38 +02:00
|
|
|
}
|
|
|
|
|
2020-03-04 22:08:23 +01:00
|
|
|
Material ***BKE_id_material_array_p(ID *id)
|
2010-09-03 09:25:37 +02:00
|
|
|
{
|
2012-08-12 16:57:19 +02:00
|
|
|
/* ensure we don't try get materials from non-obdata */
|
|
|
|
BLI_assert(OB_DATA_SUPPORT_ID(GS(id->name)));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-28 08:31:57 +02:00
|
|
|
switch (GS(id->name)) {
|
2012-05-06 17:15:33 +02:00
|
|
|
case ID_ME:
|
|
|
|
return &(((Mesh *)id)->mat);
|
2022-02-18 16:50:29 +01:00
|
|
|
case ID_CU_LEGACY:
|
2012-05-06 17:15:33 +02:00
|
|
|
return &(((Curve *)id)->mat);
|
|
|
|
case ID_MB:
|
|
|
|
return &(((MetaBall *)id)->mat);
|
2023-03-08 12:35:58 +01:00
|
|
|
case ID_GD_LEGACY:
|
2018-08-02 18:03:01 +02:00
|
|
|
return &(((bGPdata *)id)->mat);
|
Curves: Rename "Hair" types, variables, and functions to "Curves"
Based on discussions from T95355 and T94193, the plan is to use
the name "Curves" to describe the data-block container for multiple
curves. Eventually this will replace the existing "Curve" data-block.
However, it will be a while before the curve data-block can be replaced
so in order to distinguish the two curve types in the UI, "Hair Curves"
will be used, but eventually changed back to "Curves".
This patch renames "hair-related" files, functions, types, and variable
names to this convention. A deep rename is preferred to keep code
consistent and to avoid any "hair" terminology from leaking, since the
new data-block is meant for all curve types, not just hair use cases.
The downside of this naming is that the difference between "Curve"
and "Curves" has become important. That was considered during
design discussons and deemed acceptable, especially given the
non-permanent nature of the somewhat common conflict.
Some points of interest:
- All DNA compatibility is lost, just like rBf59767ff9729.
- I renamed `ID_HA` to `ID_CV` so there is no complete mismatch.
- `hair_curves` is used where necessary to distinguish from the
existing "curves" plural.
- I didn't rename any of the cycles/rendering code function names,
since that is also used by the old hair particle system.
Differential Revision: https://developer.blender.org/D14007
2022-02-07 18:55:54 +01:00
|
|
|
case ID_CV:
|
|
|
|
return &(((Curves *)id)->mat);
|
2020-03-17 14:41:48 +01:00
|
|
|
case ID_PT:
|
|
|
|
return &(((PointCloud *)id)->mat);
|
|
|
|
case ID_VO:
|
|
|
|
return &(((Volume *)id)->mat);
|
2023-05-30 11:14:16 +02:00
|
|
|
case ID_GP:
|
|
|
|
return &(((GreasePencil *)id)->material_array);
|
2017-08-28 11:19:58 +02:00
|
|
|
default:
|
|
|
|
break;
|
2010-09-03 09:25:37 +02:00
|
|
|
}
|
2022-11-18 11:08:39 +01:00
|
|
|
return nullptr;
|
2010-09-03 09:25:37 +02:00
|
|
|
}
|
|
|
|
|
2020-03-04 22:08:23 +01:00
|
|
|
short *BKE_id_material_len_p(ID *id)
|
2010-09-03 09:25:37 +02:00
|
|
|
{
|
2012-08-12 16:57:19 +02:00
|
|
|
/* ensure we don't try get materials from non-obdata */
|
|
|
|
BLI_assert(OB_DATA_SUPPORT_ID(GS(id->name)));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-28 08:31:57 +02:00
|
|
|
switch (GS(id->name)) {
|
2012-05-06 17:15:33 +02:00
|
|
|
case ID_ME:
|
|
|
|
return &(((Mesh *)id)->totcol);
|
2022-02-18 16:50:29 +01:00
|
|
|
case ID_CU_LEGACY:
|
2012-05-06 17:15:33 +02:00
|
|
|
return &(((Curve *)id)->totcol);
|
|
|
|
case ID_MB:
|
|
|
|
return &(((MetaBall *)id)->totcol);
|
2023-03-08 12:35:58 +01:00
|
|
|
case ID_GD_LEGACY:
|
2018-07-31 10:22:19 +02:00
|
|
|
return &(((bGPdata *)id)->totcol);
|
Curves: Rename "Hair" types, variables, and functions to "Curves"
Based on discussions from T95355 and T94193, the plan is to use
the name "Curves" to describe the data-block container for multiple
curves. Eventually this will replace the existing "Curve" data-block.
However, it will be a while before the curve data-block can be replaced
so in order to distinguish the two curve types in the UI, "Hair Curves"
will be used, but eventually changed back to "Curves".
This patch renames "hair-related" files, functions, types, and variable
names to this convention. A deep rename is preferred to keep code
consistent and to avoid any "hair" terminology from leaking, since the
new data-block is meant for all curve types, not just hair use cases.
The downside of this naming is that the difference between "Curve"
and "Curves" has become important. That was considered during
design discussons and deemed acceptable, especially given the
non-permanent nature of the somewhat common conflict.
Some points of interest:
- All DNA compatibility is lost, just like rBf59767ff9729.
- I renamed `ID_HA` to `ID_CV` so there is no complete mismatch.
- `hair_curves` is used where necessary to distinguish from the
existing "curves" plural.
- I didn't rename any of the cycles/rendering code function names,
since that is also used by the old hair particle system.
Differential Revision: https://developer.blender.org/D14007
2022-02-07 18:55:54 +01:00
|
|
|
case ID_CV:
|
|
|
|
return &(((Curves *)id)->totcol);
|
2020-03-17 14:41:48 +01:00
|
|
|
case ID_PT:
|
|
|
|
return &(((PointCloud *)id)->totcol);
|
|
|
|
case ID_VO:
|
|
|
|
return &(((Volume *)id)->totcol);
|
2023-05-30 11:14:16 +02:00
|
|
|
case ID_GP:
|
2023-06-04 11:48:14 +02:00
|
|
|
return &(((GreasePencil *)id)->material_array_num);
|
2017-08-28 11:19:58 +02:00
|
|
|
default:
|
|
|
|
break;
|
2010-09-03 09:25:37 +02:00
|
|
|
}
|
2022-11-18 11:08:39 +01:00
|
|
|
return nullptr;
|
2010-09-03 09:25:37 +02:00
|
|
|
}
|
|
|
|
|
2013-08-14 13:29:58 +02:00
|
|
|
static void material_data_index_remove_id(ID *id, short index)
|
2011-07-31 13:12:38 +02:00
|
|
|
{
|
2012-08-12 16:57:19 +02:00
|
|
|
/* ensure we don't try get materials from non-obdata */
|
|
|
|
BLI_assert(OB_DATA_SUPPORT_ID(GS(id->name)));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-28 08:31:57 +02:00
|
|
|
switch (GS(id->name)) {
|
2012-05-06 17:15:33 +02:00
|
|
|
case ID_ME:
|
2013-08-14 13:29:58 +02:00
|
|
|
BKE_mesh_material_index_remove((Mesh *)id, index);
|
2012-05-06 17:15:33 +02:00
|
|
|
break;
|
2022-02-18 16:50:29 +01:00
|
|
|
case ID_CU_LEGACY:
|
2013-08-14 13:29:58 +02:00
|
|
|
BKE_curve_material_index_remove((Curve *)id, index);
|
2012-05-06 17:15:33 +02:00
|
|
|
break;
|
2023-11-17 10:37:56 +01:00
|
|
|
case ID_GP:
|
|
|
|
BKE_grease_pencil_material_index_remove(reinterpret_cast<GreasePencil *>(id), index);
|
|
|
|
break;
|
2012-05-06 17:15:33 +02:00
|
|
|
case ID_MB:
|
Curves: Rename "Hair" types, variables, and functions to "Curves"
Based on discussions from T95355 and T94193, the plan is to use
the name "Curves" to describe the data-block container for multiple
curves. Eventually this will replace the existing "Curve" data-block.
However, it will be a while before the curve data-block can be replaced
so in order to distinguish the two curve types in the UI, "Hair Curves"
will be used, but eventually changed back to "Curves".
This patch renames "hair-related" files, functions, types, and variable
names to this convention. A deep rename is preferred to keep code
consistent and to avoid any "hair" terminology from leaking, since the
new data-block is meant for all curve types, not just hair use cases.
The downside of this naming is that the difference between "Curve"
and "Curves" has become important. That was considered during
design discussons and deemed acceptable, especially given the
non-permanent nature of the somewhat common conflict.
Some points of interest:
- All DNA compatibility is lost, just like rBf59767ff9729.
- I renamed `ID_HA` to `ID_CV` so there is no complete mismatch.
- `hair_curves` is used where necessary to distinguish from the
existing "curves" plural.
- I didn't rename any of the cycles/rendering code function names,
since that is also used by the old hair particle system.
Differential Revision: https://developer.blender.org/D14007
2022-02-07 18:55:54 +01:00
|
|
|
case ID_CV:
|
2020-03-17 14:41:48 +01:00
|
|
|
case ID_PT:
|
|
|
|
case ID_VO:
|
|
|
|
/* No material indices for these object data types. */
|
2012-05-06 17:15:33 +02:00
|
|
|
break;
|
2017-08-28 11:19:58 +02:00
|
|
|
default:
|
|
|
|
break;
|
2011-07-31 13:12:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-27 18:07:01 +02:00
|
|
|
bool BKE_object_material_slot_used(Object *object, short actcol)
|
2019-07-31 21:04:52 +02:00
|
|
|
{
|
2021-09-27 18:07:01 +02:00
|
|
|
if (!BKE_object_supports_material_slots(object)) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-07-31 21:04:52 +02:00
|
|
|
|
2021-09-27 18:07:01 +02:00
|
|
|
LISTBASE_FOREACH (ParticleSystem *, psys, &object->particlesystem) {
|
|
|
|
if (psys->part->omat == actcol) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
ID *ob_data = static_cast<ID *>(object->data);
|
|
|
|
if (ob_data == nullptr || !OB_DATA_SUPPORT_ID(GS(ob_data->name))) {
|
2021-09-27 18:07:01 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (GS(ob_data->name)) {
|
2019-07-31 21:04:52 +02:00
|
|
|
case ID_ME:
|
2021-09-27 18:07:01 +02:00
|
|
|
return BKE_mesh_material_index_used((Mesh *)ob_data, actcol - 1);
|
2022-02-18 16:50:29 +01:00
|
|
|
case ID_CU_LEGACY:
|
2021-09-27 18:07:01 +02:00
|
|
|
return BKE_curve_material_index_used((Curve *)ob_data, actcol - 1);
|
2019-07-31 21:04:52 +02:00
|
|
|
case ID_MB:
|
2021-09-24 03:31:23 +02:00
|
|
|
/* Meta-elements don't support materials at the moment. */
|
2019-07-31 21:04:52 +02:00
|
|
|
return false;
|
2023-03-08 12:35:58 +01:00
|
|
|
case ID_GD_LEGACY:
|
2021-09-27 18:07:01 +02:00
|
|
|
return BKE_gpencil_material_index_used((bGPdata *)ob_data, actcol - 1);
|
2023-11-17 10:37:56 +01:00
|
|
|
case ID_GP:
|
|
|
|
return BKE_grease_pencil_material_index_used(reinterpret_cast<GreasePencil *>(ob_data),
|
|
|
|
actcol - 1);
|
2019-07-31 21:04:52 +02:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-14 13:29:58 +02:00
|
|
|
static void material_data_index_clear_id(ID *id)
|
|
|
|
{
|
|
|
|
/* ensure we don't try get materials from non-obdata */
|
|
|
|
BLI_assert(OB_DATA_SUPPORT_ID(GS(id->name)));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-14 13:29:58 +02:00
|
|
|
switch (GS(id->name)) {
|
|
|
|
case ID_ME:
|
|
|
|
BKE_mesh_material_index_clear((Mesh *)id);
|
|
|
|
break;
|
2022-02-18 16:50:29 +01:00
|
|
|
case ID_CU_LEGACY:
|
2013-08-14 13:29:58 +02:00
|
|
|
BKE_curve_material_index_clear((Curve *)id);
|
|
|
|
break;
|
|
|
|
case ID_MB:
|
Curves: Rename "Hair" types, variables, and functions to "Curves"
Based on discussions from T95355 and T94193, the plan is to use
the name "Curves" to describe the data-block container for multiple
curves. Eventually this will replace the existing "Curve" data-block.
However, it will be a while before the curve data-block can be replaced
so in order to distinguish the two curve types in the UI, "Hair Curves"
will be used, but eventually changed back to "Curves".
This patch renames "hair-related" files, functions, types, and variable
names to this convention. A deep rename is preferred to keep code
consistent and to avoid any "hair" terminology from leaking, since the
new data-block is meant for all curve types, not just hair use cases.
The downside of this naming is that the difference between "Curve"
and "Curves" has become important. That was considered during
design discussons and deemed acceptable, especially given the
non-permanent nature of the somewhat common conflict.
Some points of interest:
- All DNA compatibility is lost, just like rBf59767ff9729.
- I renamed `ID_HA` to `ID_CV` so there is no complete mismatch.
- `hair_curves` is used where necessary to distinguish from the
existing "curves" plural.
- I didn't rename any of the cycles/rendering code function names,
since that is also used by the old hair particle system.
Differential Revision: https://developer.blender.org/D14007
2022-02-07 18:55:54 +01:00
|
|
|
case ID_CV:
|
2020-03-17 14:41:48 +01:00
|
|
|
case ID_PT:
|
|
|
|
case ID_VO:
|
|
|
|
/* No material indices for these object data types. */
|
2013-08-14 13:29:58 +02:00
|
|
|
break;
|
2017-08-28 11:19:58 +02:00
|
|
|
default:
|
|
|
|
break;
|
2013-08-14 13:29:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-09 18:49:40 +02:00
|
|
|
void BKE_id_materials_copy(Main *bmain, ID *id_src, ID *id_dst)
|
|
|
|
{
|
|
|
|
Material ***matar_src = BKE_id_material_array_p(id_src);
|
|
|
|
const short *materials_len_p_src = BKE_id_material_len_p(id_src);
|
|
|
|
|
|
|
|
Material ***matar_dst = BKE_id_material_array_p(id_dst);
|
|
|
|
short *materials_len_p_dst = BKE_id_material_len_p(id_dst);
|
|
|
|
|
|
|
|
*materials_len_p_dst = *materials_len_p_src;
|
|
|
|
if (*materials_len_p_src != 0) {
|
2022-11-18 11:08:39 +01:00
|
|
|
(*matar_dst) = static_cast<Material **>(MEM_dupallocN(*matar_src));
|
2020-04-09 18:49:40 +02:00
|
|
|
|
|
|
|
for (int a = 0; a < *materials_len_p_src; a++) {
|
|
|
|
id_us_plus((ID *)(*matar_dst)[a]);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEG_id_tag_update(id_dst, ID_RECALC_COPY_ON_WRITE);
|
|
|
|
DEG_relations_tag_update(bmain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-04 22:08:23 +01:00
|
|
|
void BKE_id_material_resize(Main *bmain, ID *id, short totcol, bool do_id_user)
|
2013-08-14 16:36:43 +02:00
|
|
|
{
|
2020-03-04 22:08:23 +01:00
|
|
|
Material ***matar = BKE_id_material_array_p(id);
|
|
|
|
short *totcolp = BKE_id_material_len_p(id);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
if (matar == nullptr) {
|
2013-08-14 16:36:43 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-14 16:36:43 +02:00
|
|
|
if (do_id_user && totcol < (*totcolp)) {
|
|
|
|
short i;
|
|
|
|
for (i = totcol; i < (*totcolp); i++) {
|
|
|
|
id_us_min((ID *)(*matar)[i]);
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-14 16:36:43 +02:00
|
|
|
if (totcol == 0) {
|
|
|
|
if (*totcolp) {
|
|
|
|
MEM_freeN(*matar);
|
2022-11-18 11:08:39 +01:00
|
|
|
*matar = nullptr;
|
2013-08-14 16:36:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2022-11-18 11:08:39 +01:00
|
|
|
*matar = static_cast<Material **>(MEM_recallocN(*matar, sizeof(void *) * totcol));
|
2013-08-14 16:36:43 +02:00
|
|
|
}
|
|
|
|
*totcolp = totcol;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(id, ID_RECALC_COPY_ON_WRITE);
|
2017-04-06 16:11:50 +02:00
|
|
|
DEG_relations_tag_update(bmain);
|
2013-08-14 16:36:43 +02:00
|
|
|
}
|
|
|
|
|
2020-03-04 22:08:23 +01:00
|
|
|
void BKE_id_material_append(Main *bmain, ID *id, Material *ma)
|
2010-09-03 09:25:37 +02:00
|
|
|
{
|
|
|
|
Material ***matar;
|
2020-03-04 22:08:23 +01:00
|
|
|
if ((matar = BKE_id_material_array_p(id))) {
|
|
|
|
short *totcol = BKE_id_material_len_p(id);
|
2022-11-18 11:08:39 +01:00
|
|
|
Material **mat = MEM_cnew_array<Material *>((*totcol) + 1, "newmatar");
|
2019-04-22 01:39:35 +02:00
|
|
|
if (*totcol) {
|
2012-02-23 03:17:50 +01:00
|
|
|
memcpy(mat, *matar, sizeof(void *) * (*totcol));
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
if (*matar) {
|
2012-02-23 03:17:50 +01:00
|
|
|
MEM_freeN(*matar);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 17:15:33 +02:00
|
|
|
*matar = mat;
|
|
|
|
(*matar)[(*totcol)++] = ma;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-09-03 09:25:37 +02:00
|
|
|
id_us_plus((ID *)ma);
|
2020-02-05 11:23:58 +01:00
|
|
|
BKE_objects_materials_test_all(bmain, id);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(id, ID_RECALC_COPY_ON_WRITE);
|
2017-04-06 16:11:50 +02:00
|
|
|
DEG_relations_tag_update(bmain);
|
2010-09-03 09:25:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-04 22:08:23 +01:00
|
|
|
Material *BKE_id_material_pop(Main *bmain, ID *id, int index_i)
|
2010-09-03 09:25:37 +02:00
|
|
|
{
|
2022-12-08 03:04:50 +01:00
|
|
|
short index = short(index_i);
|
2022-11-18 11:08:39 +01:00
|
|
|
Material *ret = nullptr;
|
2010-09-03 09:25:37 +02:00
|
|
|
Material ***matar;
|
2020-03-04 22:08:23 +01:00
|
|
|
if ((matar = BKE_id_material_array_p(id))) {
|
|
|
|
short *totcol = BKE_id_material_len_p(id);
|
2012-02-23 03:17:50 +01:00
|
|
|
if (index >= 0 && index < (*totcol)) {
|
2012-05-06 17:15:33 +02:00
|
|
|
ret = (*matar)[index];
|
2011-07-31 13:12:38 +02:00
|
|
|
id_us_min((ID *)ret);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-13 12:21:11 +02:00
|
|
|
if (*totcol <= 1) {
|
|
|
|
*totcol = 0;
|
|
|
|
MEM_freeN(*matar);
|
2022-11-18 11:08:39 +01:00
|
|
|
*matar = nullptr;
|
2013-08-13 12:21:11 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-04-22 01:39:35 +02:00
|
|
|
if (index + 1 != (*totcol)) {
|
2013-08-13 12:21:11 +02:00
|
|
|
memmove((*matar) + index,
|
|
|
|
(*matar) + (index + 1),
|
|
|
|
sizeof(void *) * ((*totcol) - (index + 1)));
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-13 12:21:11 +02:00
|
|
|
(*totcol)--;
|
2022-11-18 11:08:39 +01:00
|
|
|
*matar = static_cast<Material **>(MEM_reallocN(*matar, sizeof(void *) * (*totcol)));
|
2020-02-05 11:23:58 +01:00
|
|
|
BKE_objects_materials_test_all(bmain, id);
|
2013-08-13 12:21:11 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-08-16 14:36:57 +02:00
|
|
|
material_data_index_remove_id(id, index);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(id, ID_RECALC_COPY_ON_WRITE);
|
2017-04-06 16:11:50 +02:00
|
|
|
DEG_relations_tag_update(bmain);
|
2010-09-03 09:25:37 +02:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-09-03 09:25:37 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-03-04 22:08:23 +01:00
|
|
|
void BKE_id_material_clear(Main *bmain, ID *id)
|
2013-08-14 13:29:58 +02:00
|
|
|
{
|
|
|
|
Material ***matar;
|
2020-03-04 22:08:23 +01:00
|
|
|
if ((matar = BKE_id_material_array_p(id))) {
|
|
|
|
short *totcol = BKE_id_material_len_p(id);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-11-19 18:03:38 +01:00
|
|
|
while ((*totcol)--) {
|
|
|
|
id_us_min((ID *)((*matar)[*totcol]));
|
|
|
|
}
|
2013-08-14 13:29:58 +02:00
|
|
|
*totcol = 0;
|
|
|
|
if (*matar) {
|
|
|
|
MEM_freeN(*matar);
|
2022-11-18 11:08:39 +01:00
|
|
|
*matar = nullptr;
|
2013-08-14 13:29:58 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
BKE_objects_materials_test_all(bmain, id);
|
2019-08-16 14:36:57 +02:00
|
|
|
material_data_index_clear_id(id);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(id, ID_RECALC_COPY_ON_WRITE);
|
2017-04-06 16:11:50 +02:00
|
|
|
DEG_relations_tag_update(bmain);
|
2013-08-14 13:29:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
Material **BKE_object_material_get_p(Object *ob, short act)
|
2002-10-12 13:37:38 +02:00
|
|
|
{
|
2019-01-03 02:15:03 +01:00
|
|
|
Material ***matarar, **ma_p;
|
2014-04-26 16:20:13 +02:00
|
|
|
const short *totcolp;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
if (ob == nullptr) {
|
|
|
|
return nullptr;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
/* if object cannot have material, (totcolp == nullptr) */
|
2020-03-04 22:08:23 +01:00
|
|
|
totcolp = BKE_object_material_len_p(ob);
|
2022-11-18 11:08:39 +01:00
|
|
|
if (totcolp == nullptr || *totcolp == 0) {
|
|
|
|
return nullptr;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-11-09 16:59:16 +01:00
|
|
|
/* Clamp to number of slots if index is out of range, same convention as used for rendering. */
|
|
|
|
const int slot_index = clamp_i(act - 1, 0, *totcolp - 1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-11-09 16:59:16 +01:00
|
|
|
/* Fix inconsistency which may happen when library linked data reduces the number of
|
|
|
|
* slots but object was not updated. Ideally should be fixed elsewhere. */
|
|
|
|
if (*totcolp < ob->totcol) {
|
|
|
|
ob->totcol = *totcolp;
|
2002-10-12 13:37:38 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-11-09 16:59:16 +01:00
|
|
|
if (slot_index < ob->totcol && ob->matbits && ob->matbits[slot_index]) {
|
|
|
|
/* Use object material slot. */
|
|
|
|
ma_p = &ob->mat[slot_index];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Use data material slot. */
|
2020-03-04 22:08:23 +01:00
|
|
|
matarar = BKE_object_material_array_p(ob);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-01-03 02:15:03 +01:00
|
|
|
if (matarar && *matarar) {
|
2022-11-09 16:59:16 +01:00
|
|
|
ma_p = &(*matarar)[slot_index];
|
2019-01-03 02:15:03 +01:00
|
|
|
}
|
|
|
|
else {
|
2022-11-18 11:08:39 +01:00
|
|
|
ma_p = nullptr;
|
2019-01-03 02:15:03 +01:00
|
|
|
}
|
2002-10-12 13:37:38 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-01-03 02:15:03 +01:00
|
|
|
return ma_p;
|
|
|
|
}
|
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
Material *BKE_object_material_get(Object *ob, short act)
|
2019-01-03 02:15:03 +01:00
|
|
|
{
|
2020-02-05 11:23:58 +01:00
|
|
|
Material **ma_p = BKE_object_material_get_p(ob, act);
|
2022-11-18 11:08:39 +01:00
|
|
|
return ma_p ? *ma_p : nullptr;
|
2002-10-12 13:37:38 +02:00
|
|
|
}
|
|
|
|
|
2021-05-19 10:23:09 +02:00
|
|
|
static ID *get_evaluated_object_data_with_materials(Object *ob)
|
|
|
|
{
|
2022-11-18 11:08:39 +01:00
|
|
|
ID *data = static_cast<ID *>(ob->data);
|
2021-05-19 10:23:09 +02:00
|
|
|
/* Meshes in edit mode need special handling. */
|
|
|
|
if (ob->type == OB_MESH && ob->mode == OB_MODE_EDIT) {
|
2022-11-18 11:08:39 +01:00
|
|
|
Mesh *mesh = static_cast<Mesh *>(ob->data);
|
2022-01-11 15:42:07 +01:00
|
|
|
Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(ob);
|
|
|
|
if (mesh->edit_mesh && editmesh_eval_final) {
|
|
|
|
data = &editmesh_eval_final->id;
|
2021-05-19 10:23:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
Material *BKE_object_material_get_eval(Object *ob, short act)
|
|
|
|
{
|
|
|
|
BLI_assert(DEG_is_evaluated_object(ob));
|
|
|
|
|
|
|
|
ID *data = get_evaluated_object_data_with_materials(ob);
|
|
|
|
const short *tot_slots_data_ptr = BKE_id_material_len_p(data);
|
|
|
|
const int tot_slots_data = tot_slots_data_ptr ? *tot_slots_data_ptr : 0;
|
2022-11-09 16:59:16 +01:00
|
|
|
|
|
|
|
if (tot_slots_data == 0) {
|
2022-11-18 11:08:39 +01:00
|
|
|
return nullptr;
|
2021-05-19 10:23:09 +02:00
|
|
|
}
|
2022-11-09 16:59:16 +01:00
|
|
|
|
|
|
|
/* Clamp to number of slots if index is out of range, same convention as used for rendering. */
|
|
|
|
const int slot_index = clamp_i(act - 1, 0, tot_slots_data - 1);
|
2021-05-19 10:23:09 +02:00
|
|
|
const int tot_slots_object = ob->totcol;
|
|
|
|
|
|
|
|
Material ***materials_data_ptr = BKE_id_material_array_p(data);
|
2022-11-18 11:08:39 +01:00
|
|
|
Material **materials_data = materials_data_ptr ? *materials_data_ptr : nullptr;
|
2021-05-19 10:23:09 +02:00
|
|
|
Material **materials_object = ob->mat;
|
|
|
|
|
|
|
|
/* Check if slot is overwritten by object. */
|
|
|
|
if (slot_index < tot_slots_object) {
|
|
|
|
if (ob->matbits) {
|
|
|
|
if (ob->matbits[slot_index]) {
|
|
|
|
Material *material = materials_object[slot_index];
|
2022-11-18 11:08:39 +01:00
|
|
|
if (material != nullptr) {
|
2021-05-19 10:23:09 +02:00
|
|
|
return material;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Otherwise use data from object-data. */
|
|
|
|
if (slot_index < tot_slots_data) {
|
|
|
|
Material *material = materials_data[slot_index];
|
|
|
|
return material;
|
|
|
|
}
|
2022-11-18 11:08:39 +01:00
|
|
|
return nullptr;
|
2021-05-19 10:23:09 +02:00
|
|
|
}
|
|
|
|
|
2023-08-04 19:26:04 +02:00
|
|
|
int BKE_object_material_count_eval(const Object *ob)
|
2021-05-19 10:23:09 +02:00
|
|
|
{
|
|
|
|
BLI_assert(DEG_is_evaluated_object(ob));
|
2023-05-06 12:25:45 +02:00
|
|
|
if (ob->type == OB_EMPTY) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
BLI_assert(ob->data != nullptr);
|
2023-08-04 19:26:04 +02:00
|
|
|
const ID *id = get_evaluated_object_data_with_materials(const_cast<Object *>(ob));
|
|
|
|
const short *len_p = BKE_id_material_len_p(const_cast<ID *>(id));
|
2021-05-19 10:23:09 +02:00
|
|
|
return len_p ? *len_p : 0;
|
|
|
|
}
|
|
|
|
|
2021-05-19 11:02:25 +02:00
|
|
|
void BKE_id_material_eval_assign(ID *id, int slot, Material *material)
|
|
|
|
{
|
2021-06-01 15:24:29 +02:00
|
|
|
BLI_assert(slot >= 1);
|
2021-05-19 11:02:25 +02:00
|
|
|
Material ***materials_ptr = BKE_id_material_array_p(id);
|
|
|
|
short *len_ptr = BKE_id_material_len_p(id);
|
2022-11-18 11:08:39 +01:00
|
|
|
if (ELEM(nullptr, materials_ptr, len_ptr)) {
|
2021-05-19 11:02:25 +02:00
|
|
|
BLI_assert_unreachable();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int slot_index = slot - 1;
|
|
|
|
const int old_length = *len_ptr;
|
|
|
|
|
|
|
|
if (slot_index >= old_length) {
|
|
|
|
/* Need to grow slots array. */
|
|
|
|
const int new_length = slot_index + 1;
|
2022-11-18 11:08:39 +01:00
|
|
|
*materials_ptr = static_cast<Material **>(
|
|
|
|
MEM_reallocN(*materials_ptr, sizeof(void *) * new_length));
|
2021-05-19 11:02:25 +02:00
|
|
|
*len_ptr = new_length;
|
|
|
|
for (int i = old_length; i < new_length; i++) {
|
2022-11-18 11:08:39 +01:00
|
|
|
(*materials_ptr)[i] = nullptr;
|
2021-05-19 11:02:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
(*materials_ptr)[slot_index] = material;
|
|
|
|
}
|
|
|
|
|
2021-06-01 15:24:29 +02:00
|
|
|
void BKE_id_material_eval_ensure_default_slot(ID *id)
|
|
|
|
{
|
|
|
|
short *len_ptr = BKE_id_material_len_p(id);
|
2022-11-18 11:08:39 +01:00
|
|
|
if (len_ptr == nullptr) {
|
2021-06-01 15:24:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (*len_ptr == 0) {
|
2022-11-18 11:08:39 +01:00
|
|
|
BKE_id_material_eval_assign(id, 1, nullptr);
|
2021-06-01 15:24:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
Material *BKE_gpencil_material(Object *ob, short act)
|
2019-08-30 14:19:07 +02:00
|
|
|
{
|
2020-02-05 11:23:58 +01:00
|
|
|
Material *ma = BKE_object_material_get(ob, act);
|
2022-11-18 11:08:39 +01:00
|
|
|
if (ma != nullptr) {
|
2019-08-30 14:19:07 +02:00
|
|
|
return ma;
|
|
|
|
}
|
2020-08-07 12:30:43 +02:00
|
|
|
|
|
|
|
return BKE_material_default_gpencil();
|
2019-08-30 14:19:07 +02:00
|
|
|
}
|
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
MaterialGPencilStyle *BKE_gpencil_material_settings(Object *ob, short act)
|
2018-07-31 10:22:19 +02:00
|
|
|
{
|
2020-02-05 11:23:58 +01:00
|
|
|
Material *ma = BKE_object_material_get(ob, act);
|
2022-11-18 11:08:39 +01:00
|
|
|
if (ma != nullptr) {
|
|
|
|
if (ma->gp_style == nullptr) {
|
2020-02-05 11:23:58 +01:00
|
|
|
BKE_gpencil_material_attr_init(ma);
|
2018-07-31 10:22:19 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-31 10:22:19 +02:00
|
|
|
return ma->gp_style;
|
|
|
|
}
|
2020-08-07 12:30:43 +02:00
|
|
|
|
|
|
|
return BKE_material_default_gpencil()->gp_style;
|
2018-07-31 10:22:19 +02:00
|
|
|
}
|
|
|
|
|
2020-03-04 22:08:23 +01:00
|
|
|
void BKE_object_material_resize(Main *bmain, Object *ob, const short totcol, bool do_id_user)
|
2002-10-12 13:37:38 +02:00
|
|
|
{
|
|
|
|
Material **newmatar;
|
2009-07-13 02:40:20 +02:00
|
|
|
char *newmatbits;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-14 16:36:43 +02:00
|
|
|
if (do_id_user && totcol < ob->totcol) {
|
2020-03-06 15:56:09 +01:00
|
|
|
for (int i = totcol; i < ob->totcol; i++) {
|
2013-08-14 16:36:43 +02:00
|
|
|
id_us_min((ID *)ob->mat[i]);
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 17:15:33 +02:00
|
|
|
if (totcol == 0) {
|
2012-02-23 03:17:50 +01:00
|
|
|
if (ob->totcol) {
|
2010-12-06 03:32:16 +01:00
|
|
|
MEM_freeN(ob->mat);
|
|
|
|
MEM_freeN(ob->matbits);
|
2022-11-18 11:08:39 +01:00
|
|
|
ob->mat = nullptr;
|
|
|
|
ob->matbits = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2010-12-06 03:32:16 +01:00
|
|
|
}
|
2012-05-06 17:15:33 +02:00
|
|
|
else if (ob->totcol < totcol) {
|
2022-11-18 11:08:39 +01:00
|
|
|
newmatar = MEM_cnew_array<Material *>(totcol, "newmatar");
|
|
|
|
newmatbits = MEM_cnew_array<char>(totcol, "newmatbits");
|
2012-02-23 03:17:50 +01:00
|
|
|
if (ob->totcol) {
|
2012-05-06 17:15:33 +02:00
|
|
|
memcpy(newmatar, ob->mat, sizeof(void *) * ob->totcol);
|
|
|
|
memcpy(newmatbits, ob->matbits, sizeof(char) * ob->totcol);
|
2010-12-06 03:32:16 +01:00
|
|
|
MEM_freeN(ob->mat);
|
|
|
|
MEM_freeN(ob->matbits);
|
|
|
|
}
|
2012-05-06 17:15:33 +02:00
|
|
|
ob->mat = newmatar;
|
|
|
|
ob->matbits = newmatbits;
|
2002-10-12 13:37:38 +02:00
|
|
|
}
|
2023-02-09 01:30:25 +01:00
|
|
|
/* XXX(@ideasman42): why not realloc on shrink? */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 17:15:33 +02:00
|
|
|
ob->totcol = totcol;
|
2019-04-22 01:39:35 +02:00
|
|
|
if (ob->totcol && ob->actcol == 0) {
|
2012-05-06 17:15:33 +02:00
|
|
|
ob->actcol = 1;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
if (ob->actcol > ob->totcol) {
|
2012-05-06 17:15:33 +02:00
|
|
|
ob->actcol = ob->totcol;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-06 17:52:37 +01:00
|
|
|
DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE | ID_RECALC_GEOMETRY);
|
2017-04-06 16:11:50 +02:00
|
|
|
DEG_relations_tag_update(bmain);
|
2010-12-06 03:32:16 +01:00
|
|
|
}
|
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
void BKE_object_materials_test(Main *bmain, Object *ob, ID *id)
|
2016-07-08 14:36:25 +02:00
|
|
|
{
|
|
|
|
/* make the ob mat-array same size as 'ob->data' mat-array */
|
|
|
|
const short *totcol;
|
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
if (id == nullptr || (totcol = BKE_id_material_len_p(id)) == nullptr) {
|
2016-07-08 14:36:25 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-03 17:57:45 +01:00
|
|
|
if ((ob->id.tag & LIB_TAG_MISSING) == 0 && (id->tag & LIB_TAG_MISSING) != 0) {
|
|
|
|
/* Exception: In case the object is a valid data, but its obdata is an empty place-holder,
|
|
|
|
* use object's material slots amount as reference.
|
2021-11-19 12:44:27 +01:00
|
|
|
* This avoids losing materials in a local object when its linked obdata goes missing.
|
2023-02-12 04:37:16 +01:00
|
|
|
* See #92780. */
|
2022-12-08 03:04:50 +01:00
|
|
|
BKE_id_material_resize(bmain, id, short(ob->totcol), false);
|
2021-11-03 17:57:45 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Normal case: the use the obdata amount of materials slots to update the object's one. */
|
|
|
|
BKE_object_material_resize(bmain, ob, *totcol, false);
|
|
|
|
}
|
2016-07-08 14:36:25 +02:00
|
|
|
}
|
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
void BKE_objects_materials_test_all(Main *bmain, ID *id)
|
2010-12-06 03:32:16 +01:00
|
|
|
{
|
|
|
|
/* make the ob mat-array same size as 'ob->data' mat-array */
|
|
|
|
Object *ob;
|
2014-04-26 16:20:13 +02:00
|
|
|
const short *totcol;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
if (id == nullptr || (totcol = BKE_id_material_len_p(id)) == nullptr) {
|
2010-12-06 03:32:16 +01:00
|
|
|
return;
|
2002-10-12 13:37:38 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-06-26 10:55:40 +02:00
|
|
|
BKE_main_lock(bmain);
|
2022-09-14 10:52:25 +02:00
|
|
|
int processed_objects = 0;
|
2022-11-18 11:08:39 +01:00
|
|
|
for (ob = static_cast<Object *>(bmain->objects.first); ob;
|
|
|
|
ob = static_cast<Object *>(ob->id.next)) {
|
2012-05-06 17:15:33 +02:00
|
|
|
if (ob->data == id) {
|
2020-03-04 22:08:23 +01:00
|
|
|
BKE_object_material_resize(bmain, ob, *totcol, false);
|
2022-09-14 10:52:25 +02:00
|
|
|
processed_objects++;
|
|
|
|
BLI_assert(processed_objects <= id->us && processed_objects > 0);
|
|
|
|
if (processed_objects == id->us) {
|
|
|
|
break;
|
|
|
|
}
|
2002-10-12 13:37:38 +02:00
|
|
|
}
|
|
|
|
}
|
2014-06-26 10:55:40 +02:00
|
|
|
BKE_main_unlock(bmain);
|
2002-10-12 13:37:38 +02:00
|
|
|
}
|
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
void BKE_id_material_assign(Main *bmain, ID *id, Material *ma, short act)
|
2011-10-01 19:51:47 +02:00
|
|
|
{
|
|
|
|
Material *mao, **matar, ***matarar;
|
|
|
|
short *totcolp;
|
|
|
|
|
2019-04-22 01:39:35 +02:00
|
|
|
if (act > MAXMAT) {
|
2012-05-06 17:15:33 +02:00
|
|
|
return;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
if (act < 1) {
|
2012-05-06 17:15:33 +02:00
|
|
|
act = 1;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2011-10-01 19:51:47 +02:00
|
|
|
|
|
|
|
/* test arraylens */
|
|
|
|
|
2020-03-04 22:08:23 +01:00
|
|
|
totcolp = BKE_id_material_len_p(id);
|
|
|
|
matarar = BKE_id_material_array_p(id);
|
2011-10-01 19:51:47 +02:00
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
if (totcolp == nullptr || matarar == nullptr) {
|
2012-05-06 17:15:33 +02:00
|
|
|
return;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2011-10-01 19:51:47 +02:00
|
|
|
|
2012-02-23 03:17:50 +01:00
|
|
|
if (act > *totcolp) {
|
2022-11-18 11:08:39 +01:00
|
|
|
matar = MEM_cnew_array<Material *>(act, "matarray1");
|
2011-10-01 19:51:47 +02:00
|
|
|
|
2012-02-23 03:17:50 +01:00
|
|
|
if (*totcolp) {
|
2012-05-06 17:15:33 +02:00
|
|
|
memcpy(matar, *matarar, sizeof(void *) * (*totcolp));
|
2011-10-01 19:51:47 +02:00
|
|
|
MEM_freeN(*matarar);
|
|
|
|
}
|
|
|
|
|
2012-05-06 17:15:33 +02:00
|
|
|
*matarar = matar;
|
|
|
|
*totcolp = act;
|
2011-10-01 19:51:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* in data */
|
2012-05-06 17:15:33 +02:00
|
|
|
mao = (*matarar)[act - 1];
|
2019-04-22 01:39:35 +02:00
|
|
|
if (mao) {
|
2015-11-09 19:47:10 +01:00
|
|
|
id_us_min(&mao->id);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2012-05-06 17:15:33 +02:00
|
|
|
(*matarar)[act - 1] = ma;
|
2011-10-01 19:51:47 +02:00
|
|
|
|
2019-04-22 01:39:35 +02:00
|
|
|
if (ma) {
|
2015-11-09 19:47:10 +01:00
|
|
|
id_us_plus(&ma->id);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2011-10-01 19:51:47 +02:00
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
BKE_objects_materials_test_all(bmain, id);
|
2011-10-01 19:51:47 +02:00
|
|
|
}
|
|
|
|
|
IO: speed up import of large Alembic/USD/OBJ scenes by optimizing material assignment
The importer parts that were doing assignment of materials to the
imported objects/meshes were essentially having a quadratic complexity
in terms of scene object count. For each material assigned to each
object, they were scanning the whole scene, checking which other
Objects use the same Mesh data, in order to resize their material
arrays to match the size.
Performance details (Windows, Ryzen 5950X):
- Import OBJ Blender 3.0 splash scene (24k objects): 43.0s -> 32.9s
- Import USD Disney Moana scene (260k objects): saves two hours
(~7400s). Note that later on this crashes when trying to render the
imported result; crashes in the same way/place both in master and
this patch.
Implementation details:
The importers were doing "scan the world" basically twice for each
object, for each material: once when creating a new material slot
(assigns an empty material), and then again when assigning the
material.
However, all these importers (USD, Alembic, OBJ) always create one
Object for one Mesh. So that whole quadratic complexity resulting
from "scan the world for possible other users of this obdata" is
completely not needed; it just never finds anything. So add a new
dedicated function BKE_object_material_assign_single_obdata that skips
the expensive part, but should only be used when the caller knows that
the obdata has exactly one user (the passed object).
Reviewed By: Bastien Montagne, Michael Kowalski
Differential Revision: https://developer.blender.org/D15145
2022-07-06 12:29:59 +02:00
|
|
|
static void object_material_assign(
|
|
|
|
Main *bmain, Object *ob, Material *ma, short act, int assign_type, bool do_test_all)
|
2002-10-12 13:37:38 +02:00
|
|
|
{
|
|
|
|
Material *mao, **matar, ***matarar;
|
|
|
|
short *totcolp;
|
2012-08-18 15:07:48 +02:00
|
|
|
char bit = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 01:39:35 +02:00
|
|
|
if (act > MAXMAT) {
|
2012-05-06 17:15:33 +02:00
|
|
|
return;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
if (act < 1) {
|
2012-05-06 17:15:33 +02:00
|
|
|
act = 1;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 13:37:38 +02:00
|
|
|
/* test arraylens */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-04 22:08:23 +01:00
|
|
|
totcolp = BKE_object_material_len_p(ob);
|
|
|
|
matarar = BKE_object_material_array_p(ob);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
if (totcolp == nullptr || matarar == nullptr) {
|
2012-05-06 17:15:33 +02:00
|
|
|
return;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-02-23 03:17:50 +01:00
|
|
|
if (act > *totcolp) {
|
2022-11-18 11:08:39 +01:00
|
|
|
matar = MEM_cnew_array<Material *>(act, "matarray1");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-02-23 03:17:50 +01:00
|
|
|
if (*totcolp) {
|
2012-05-06 17:15:33 +02:00
|
|
|
memcpy(matar, *matarar, sizeof(void *) * (*totcolp));
|
2002-10-12 13:37:38 +02:00
|
|
|
MEM_freeN(*matarar);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 17:15:33 +02:00
|
|
|
*matarar = matar;
|
|
|
|
*totcolp = act;
|
2002-10-12 13:37:38 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-08-06 10:04:13 +02:00
|
|
|
if (act > ob->totcol) {
|
|
|
|
/* Need more space in the material arrays */
|
2022-11-18 11:08:39 +01:00
|
|
|
ob->mat = static_cast<Material **>(
|
|
|
|
MEM_recallocN_id(ob->mat, sizeof(void *) * act, "matarray2"));
|
|
|
|
ob->matbits = static_cast<char *>(
|
|
|
|
MEM_recallocN_id(ob->matbits, sizeof(char) * act, "matbits1"));
|
2015-08-06 10:04:13 +02:00
|
|
|
ob->totcol = act;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-25 01:22:34 +02:00
|
|
|
/* Determine the object/mesh linking */
|
2015-08-06 10:04:13 +02:00
|
|
|
if (assign_type == BKE_MAT_ASSIGN_EXISTING) {
|
|
|
|
/* keep existing option (avoid confusion in scripts),
|
|
|
|
* intentionally ignore userpref (default to obdata). */
|
|
|
|
bit = ob->matbits[act - 1];
|
|
|
|
}
|
|
|
|
else if (assign_type == BKE_MAT_ASSIGN_USERPREF && ob->totcol && ob->actcol) {
|
2012-08-12 19:12:07 +02:00
|
|
|
/* copy from previous material */
|
|
|
|
bit = ob->matbits[ob->actcol - 1];
|
|
|
|
}
|
|
|
|
else {
|
2012-08-18 15:07:48 +02:00
|
|
|
switch (assign_type) {
|
2012-08-12 19:12:07 +02:00
|
|
|
case BKE_MAT_ASSIGN_OBDATA:
|
|
|
|
bit = 0;
|
|
|
|
break;
|
|
|
|
case BKE_MAT_ASSIGN_OBJECT:
|
|
|
|
bit = 1;
|
|
|
|
break;
|
|
|
|
case BKE_MAT_ASSIGN_USERPREF:
|
|
|
|
default:
|
|
|
|
bit = (U.flag & USER_MAT_ON_OB) ? 1 : 0;
|
|
|
|
break;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
2003-04-26 13:56:44 +02:00
|
|
|
/* do it */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-12 19:12:07 +02:00
|
|
|
ob->matbits[act - 1] = bit;
|
|
|
|
if (bit == 1) { /* in object */
|
2012-05-06 17:15:33 +02:00
|
|
|
mao = ob->mat[act - 1];
|
2019-04-22 01:39:35 +02:00
|
|
|
if (mao) {
|
2015-11-09 19:47:10 +01:00
|
|
|
id_us_min(&mao->id);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2012-05-06 17:15:33 +02:00
|
|
|
ob->mat[act - 1] = ma;
|
2022-11-18 11:08:39 +01:00
|
|
|
BKE_object_materials_test(bmain, ob, static_cast<ID *>(ob->data));
|
2002-10-12 13:37:38 +02:00
|
|
|
}
|
2012-05-06 17:15:33 +02:00
|
|
|
else { /* in data */
|
|
|
|
mao = (*matarar)[act - 1];
|
2019-04-22 01:39:35 +02:00
|
|
|
if (mao) {
|
2015-11-09 19:47:10 +01:00
|
|
|
id_us_min(&mao->id);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2012-05-06 17:15:33 +02:00
|
|
|
(*matarar)[act - 1] = ma;
|
IO: speed up import of large Alembic/USD/OBJ scenes by optimizing material assignment
The importer parts that were doing assignment of materials to the
imported objects/meshes were essentially having a quadratic complexity
in terms of scene object count. For each material assigned to each
object, they were scanning the whole scene, checking which other
Objects use the same Mesh data, in order to resize their material
arrays to match the size.
Performance details (Windows, Ryzen 5950X):
- Import OBJ Blender 3.0 splash scene (24k objects): 43.0s -> 32.9s
- Import USD Disney Moana scene (260k objects): saves two hours
(~7400s). Note that later on this crashes when trying to render the
imported result; crashes in the same way/place both in master and
this patch.
Implementation details:
The importers were doing "scan the world" basically twice for each
object, for each material: once when creating a new material slot
(assigns an empty material), and then again when assigning the
material.
However, all these importers (USD, Alembic, OBJ) always create one
Object for one Mesh. So that whole quadratic complexity resulting
from "scan the world for possible other users of this obdata" is
completely not needed; it just never finds anything. So add a new
dedicated function BKE_object_material_assign_single_obdata that skips
the expensive part, but should only be used when the caller knows that
the obdata has exactly one user (the passed object).
Reviewed By: Bastien Montagne, Michael Kowalski
Differential Revision: https://developer.blender.org/D15145
2022-07-06 12:29:59 +02:00
|
|
|
/* Data may be used by several objects. */
|
|
|
|
if (do_test_all) {
|
2022-11-18 11:08:39 +01:00
|
|
|
BKE_objects_materials_test_all(bmain, static_cast<ID *>(ob->data));
|
IO: speed up import of large Alembic/USD/OBJ scenes by optimizing material assignment
The importer parts that were doing assignment of materials to the
imported objects/meshes were essentially having a quadratic complexity
in terms of scene object count. For each material assigned to each
object, they were scanning the whole scene, checking which other
Objects use the same Mesh data, in order to resize their material
arrays to match the size.
Performance details (Windows, Ryzen 5950X):
- Import OBJ Blender 3.0 splash scene (24k objects): 43.0s -> 32.9s
- Import USD Disney Moana scene (260k objects): saves two hours
(~7400s). Note that later on this crashes when trying to render the
imported result; crashes in the same way/place both in master and
this patch.
Implementation details:
The importers were doing "scan the world" basically twice for each
object, for each material: once when creating a new material slot
(assigns an empty material), and then again when assigning the
material.
However, all these importers (USD, Alembic, OBJ) always create one
Object for one Mesh. So that whole quadratic complexity resulting
from "scan the world for possible other users of this obdata" is
completely not needed; it just never finds anything. So add a new
dedicated function BKE_object_material_assign_single_obdata that skips
the expensive part, but should only be used when the caller knows that
the obdata has exactly one user (the passed object).
Reviewed By: Bastien Montagne, Michael Kowalski
Differential Revision: https://developer.blender.org/D15145
2022-07-06 12:29:59 +02:00
|
|
|
}
|
2002-10-12 13:37:38 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 01:39:35 +02:00
|
|
|
if (ma) {
|
2015-11-09 19:47:10 +01:00
|
|
|
id_us_plus(&ma->id);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2002-10-12 13:37:38 +02:00
|
|
|
}
|
|
|
|
|
IO: speed up import of large Alembic/USD/OBJ scenes by optimizing material assignment
The importer parts that were doing assignment of materials to the
imported objects/meshes were essentially having a quadratic complexity
in terms of scene object count. For each material assigned to each
object, they were scanning the whole scene, checking which other
Objects use the same Mesh data, in order to resize their material
arrays to match the size.
Performance details (Windows, Ryzen 5950X):
- Import OBJ Blender 3.0 splash scene (24k objects): 43.0s -> 32.9s
- Import USD Disney Moana scene (260k objects): saves two hours
(~7400s). Note that later on this crashes when trying to render the
imported result; crashes in the same way/place both in master and
this patch.
Implementation details:
The importers were doing "scan the world" basically twice for each
object, for each material: once when creating a new material slot
(assigns an empty material), and then again when assigning the
material.
However, all these importers (USD, Alembic, OBJ) always create one
Object for one Mesh. So that whole quadratic complexity resulting
from "scan the world for possible other users of this obdata" is
completely not needed; it just never finds anything. So add a new
dedicated function BKE_object_material_assign_single_obdata that skips
the expensive part, but should only be used when the caller knows that
the obdata has exactly one user (the passed object).
Reviewed By: Bastien Montagne, Michael Kowalski
Differential Revision: https://developer.blender.org/D15145
2022-07-06 12:29:59 +02:00
|
|
|
void BKE_object_material_assign(Main *bmain, Object *ob, Material *ma, short act, int assign_type)
|
|
|
|
{
|
|
|
|
object_material_assign(bmain, ob, ma, act, assign_type, true);
|
|
|
|
}
|
|
|
|
|
2023-06-03 00:36:28 +02:00
|
|
|
void BKE_object_material_assign_single_obdata(Main *bmain, Object *ob, Material *ma, short act)
|
IO: speed up import of large Alembic/USD/OBJ scenes by optimizing material assignment
The importer parts that were doing assignment of materials to the
imported objects/meshes were essentially having a quadratic complexity
in terms of scene object count. For each material assigned to each
object, they were scanning the whole scene, checking which other
Objects use the same Mesh data, in order to resize their material
arrays to match the size.
Performance details (Windows, Ryzen 5950X):
- Import OBJ Blender 3.0 splash scene (24k objects): 43.0s -> 32.9s
- Import USD Disney Moana scene (260k objects): saves two hours
(~7400s). Note that later on this crashes when trying to render the
imported result; crashes in the same way/place both in master and
this patch.
Implementation details:
The importers were doing "scan the world" basically twice for each
object, for each material: once when creating a new material slot
(assigns an empty material), and then again when assigning the
material.
However, all these importers (USD, Alembic, OBJ) always create one
Object for one Mesh. So that whole quadratic complexity resulting
from "scan the world for possible other users of this obdata" is
completely not needed; it just never finds anything. So add a new
dedicated function BKE_object_material_assign_single_obdata that skips
the expensive part, but should only be used when the caller knows that
the obdata has exactly one user (the passed object).
Reviewed By: Bastien Montagne, Michael Kowalski
Differential Revision: https://developer.blender.org/D15145
2022-07-06 12:29:59 +02:00
|
|
|
{
|
|
|
|
object_material_assign(bmain, ob, ma, act, BKE_MAT_ASSIGN_OBDATA, false);
|
|
|
|
}
|
|
|
|
|
2022-09-25 09:04:52 +02:00
|
|
|
void BKE_object_material_remap(Object *ob, const uint *remap)
|
2015-04-27 23:24:56 +02:00
|
|
|
{
|
2020-03-04 22:08:23 +01:00
|
|
|
Material ***matar = BKE_object_material_array_p(ob);
|
|
|
|
const short *totcol_p = BKE_object_material_len_p(ob);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-04-27 23:24:56 +02:00
|
|
|
BLI_array_permute(ob->mat, ob->totcol, remap);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-04-27 23:24:56 +02:00
|
|
|
if (ob->matbits) {
|
|
|
|
BLI_array_permute(ob->matbits, ob->totcol, remap);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-04-30 00:07:15 +02:00
|
|
|
if (matar) {
|
2015-04-27 23:24:56 +02:00
|
|
|
BLI_array_permute(*matar, *totcol_p, remap);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-04-27 23:24:56 +02:00
|
|
|
if (ob->type == OB_MESH) {
|
2022-11-18 11:08:39 +01:00
|
|
|
BKE_mesh_material_remap(static_cast<Mesh *>(ob->data), remap, ob->totcol);
|
2015-04-27 23:24:56 +02:00
|
|
|
}
|
2022-02-18 16:50:29 +01:00
|
|
|
else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF, OB_FONT)) {
|
2022-11-18 11:08:39 +01:00
|
|
|
BKE_curve_material_remap(static_cast<Curve *>(ob->data), remap, ob->totcol);
|
2015-04-27 23:24:56 +02:00
|
|
|
}
|
2023-03-08 12:35:58 +01:00
|
|
|
else if (ob->type == OB_GPENCIL_LEGACY) {
|
2022-11-18 11:08:39 +01:00
|
|
|
BKE_gpencil_material_remap(static_cast<bGPdata *>(ob->data), remap, ob->totcol);
|
2018-07-31 10:22:19 +02:00
|
|
|
}
|
2023-10-19 13:19:41 +02:00
|
|
|
else if (ob->type == OB_GREASE_PENCIL) {
|
|
|
|
BKE_grease_pencil_material_remap(static_cast<GreasePencil *>(ob->data), remap, ob->totcol);
|
|
|
|
}
|
2015-04-27 23:24:56 +02:00
|
|
|
else {
|
|
|
|
/* add support for this object data! */
|
2022-11-18 11:08:39 +01:00
|
|
|
BLI_assert(matar == nullptr);
|
2015-04-27 23:24:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-04 22:08:23 +01:00
|
|
|
void BKE_object_material_remap_calc(Object *ob_dst, Object *ob_src, short *remap_src_to_dst)
|
2015-12-12 14:34:09 +01:00
|
|
|
{
|
|
|
|
if (ob_src->totcol == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-12-12 14:34:09 +01:00
|
|
|
GHash *gh_mat_map = BLI_ghash_ptr_new_ex(__func__, ob_src->totcol);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-12-12 14:34:09 +01:00
|
|
|
for (int i = 0; i < ob_dst->totcol; i++) {
|
2020-02-05 11:23:58 +01:00
|
|
|
Material *ma_src = BKE_object_material_get(ob_dst, i + 1);
|
2022-11-18 11:08:39 +01:00
|
|
|
BLI_ghash_reinsert(gh_mat_map, ma_src, POINTER_FROM_INT(i), nullptr, nullptr);
|
2015-12-12 14:34:09 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-12-12 14:34:09 +01:00
|
|
|
/* setup default mapping (when materials don't match) */
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
if (ob_dst->totcol >= ob_src->totcol) {
|
|
|
|
for (; i < ob_src->totcol; i++) {
|
|
|
|
remap_src_to_dst[i] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (; i < ob_dst->totcol; i++) {
|
|
|
|
remap_src_to_dst[i] = i;
|
|
|
|
}
|
|
|
|
for (; i < ob_src->totcol; i++) {
|
|
|
|
remap_src_to_dst[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-12-12 14:34:09 +01:00
|
|
|
for (int i = 0; i < ob_src->totcol; i++) {
|
2020-02-05 11:23:58 +01:00
|
|
|
Material *ma_src = BKE_object_material_get(ob_src, i + 1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
if ((i < ob_dst->totcol) && (ma_src == BKE_object_material_get(ob_dst, i + 1))) {
|
2015-12-12 14:34:09 +01:00
|
|
|
/* when objects have exact matching materials - keep existing index */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
void **index_src_p = BLI_ghash_lookup_p(gh_mat_map, ma_src);
|
|
|
|
if (index_src_p) {
|
2018-09-19 04:05:58 +02:00
|
|
|
remap_src_to_dst[i] = POINTER_AS_INT(*index_src_p);
|
2015-12-12 14:34:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
BLI_ghash_free(gh_mat_map, nullptr, nullptr);
|
2015-12-12 14:34:09 +01:00
|
|
|
}
|
|
|
|
|
2022-05-06 11:37:22 +02:00
|
|
|
void BKE_object_material_from_eval_data(Main *bmain, Object *ob_orig, const ID *data_eval)
|
2021-05-20 12:15:57 +02:00
|
|
|
{
|
2022-11-18 11:08:39 +01:00
|
|
|
ID *data_orig = static_cast<ID *>(ob_orig->data);
|
2021-05-20 12:15:57 +02:00
|
|
|
|
|
|
|
short *orig_totcol = BKE_id_material_len_p(data_orig);
|
|
|
|
Material ***orig_mat = BKE_id_material_array_p(data_orig);
|
|
|
|
|
2022-05-06 11:37:22 +02:00
|
|
|
/* Can cast away const, because the data is not changed. */
|
|
|
|
const short *eval_totcol = BKE_id_material_len_p((ID *)data_eval);
|
|
|
|
Material ***eval_mat = BKE_id_material_array_p((ID *)data_eval);
|
2021-05-20 12:15:57 +02:00
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
if (ELEM(nullptr, orig_totcol, orig_mat, eval_totcol, eval_mat)) {
|
2021-05-20 12:15:57 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove old materials from original geometry. */
|
|
|
|
for (int i = 0; i < *orig_totcol; i++) {
|
|
|
|
id_us_min(&(*orig_mat)[i]->id);
|
|
|
|
}
|
|
|
|
MEM_SAFE_FREE(*orig_mat);
|
|
|
|
|
|
|
|
/* Create new material slots based on materials on evaluated geometry. */
|
|
|
|
*orig_totcol = *eval_totcol;
|
2022-11-18 11:08:39 +01:00
|
|
|
*orig_mat = MEM_cnew_array<Material *>(*eval_totcol, __func__);
|
2021-05-20 12:15:57 +02:00
|
|
|
for (int i = 0; i < *eval_totcol; i++) {
|
|
|
|
Material *material_eval = (*eval_mat)[i];
|
2022-11-18 11:08:39 +01:00
|
|
|
if (material_eval != nullptr) {
|
2021-05-20 12:15:57 +02:00
|
|
|
Material *material_orig = (Material *)DEG_get_original_id(&material_eval->id);
|
|
|
|
(*orig_mat)[i] = material_orig;
|
|
|
|
id_us_plus(&material_orig->id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BKE_object_materials_test(bmain, ob_orig, data_orig);
|
|
|
|
}
|
|
|
|
|
2023-06-03 00:36:28 +02:00
|
|
|
void BKE_object_material_array_assign(
|
|
|
|
Main *bmain, Object *ob, Material ***matar, int totcol, const bool to_object_only)
|
2009-10-07 18:32:55 +02:00
|
|
|
{
|
2012-05-06 17:15:33 +02:00
|
|
|
int actcol_orig = ob->actcol;
|
2009-10-07 18:32:55 +02:00
|
|
|
|
2018-05-29 15:49:21 +02:00
|
|
|
while ((ob->totcol > totcol) && BKE_object_material_slot_remove(bmain, ob)) {
|
2016-07-20 22:00:58 +02:00
|
|
|
/* pass */
|
|
|
|
}
|
2009-10-07 18:32:55 +02:00
|
|
|
|
|
|
|
/* now we have the right number of slots */
|
2020-07-28 20:56:34 +02:00
|
|
|
for (int i = 0; i < totcol; i++) {
|
2020-07-28 18:26:56 +02:00
|
|
|
if (to_object_only && ob->matbits[i] == 0) {
|
|
|
|
/* If we only assign to object, and that slot uses obdata material, do nothing. */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
BKE_object_material_assign(bmain,
|
|
|
|
ob,
|
|
|
|
(*matar)[i],
|
|
|
|
i + 1,
|
|
|
|
to_object_only ? BKE_MAT_ASSIGN_OBJECT : BKE_MAT_ASSIGN_USERPREF);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2009-10-07 18:32:55 +02:00
|
|
|
|
2019-04-22 01:39:35 +02:00
|
|
|
if (actcol_orig > ob->totcol) {
|
2012-05-06 17:15:33 +02:00
|
|
|
actcol_orig = ob->totcol;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2009-10-07 18:32:55 +02:00
|
|
|
|
2012-05-06 17:15:33 +02:00
|
|
|
ob->actcol = actcol_orig;
|
2009-10-07 18:32:55 +02:00
|
|
|
}
|
|
|
|
|
2016-07-20 21:56:12 +02:00
|
|
|
short BKE_object_material_slot_find_index(Object *ob, Material *ma)
|
2007-11-28 19:43:09 +01:00
|
|
|
{
|
|
|
|
Material ***matarar;
|
|
|
|
short a, *totcolp;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
if (ma == nullptr) {
|
2012-05-06 17:15:33 +02:00
|
|
|
return 0;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2020-03-04 22:08:23 +01:00
|
|
|
totcolp = BKE_object_material_len_p(ob);
|
|
|
|
matarar = BKE_object_material_array_p(ob);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
if (totcolp == nullptr || matarar == nullptr) {
|
2012-05-06 17:15:33 +02:00
|
|
|
return 0;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 01:39:35 +02:00
|
|
|
for (a = 0; a < *totcolp; a++) {
|
|
|
|
if ((*matarar)[a] == ma) {
|
2012-05-06 17:15:33 +02:00
|
|
|
break;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (a < *totcolp) {
|
2012-05-06 17:15:33 +02:00
|
|
|
return a + 1;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2012-10-21 07:46:41 +02:00
|
|
|
return 0;
|
2007-11-28 19:43:09 +01:00
|
|
|
}
|
|
|
|
|
2018-05-29 15:49:21 +02:00
|
|
|
bool BKE_object_material_slot_add(Main *bmain, Object *ob)
|
2002-10-12 13:37:38 +02:00
|
|
|
{
|
2022-11-18 11:08:39 +01:00
|
|
|
if (ob == nullptr) {
|
2014-04-01 02:34:00 +02:00
|
|
|
return false;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
if (ob->totcol >= MAXMAT) {
|
2014-04-01 02:34:00 +02:00
|
|
|
return false;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
BKE_object_material_assign(bmain, ob, nullptr, ob->totcol + 1, BKE_MAT_ASSIGN_USERPREF);
|
2012-05-06 17:15:33 +02:00
|
|
|
ob->actcol = ob->totcol;
|
2014-04-01 02:34:00 +02:00
|
|
|
return true;
|
2002-10-12 13:37:38 +02:00
|
|
|
}
|
|
|
|
|
Bugfix [#31834] Cycles materials cannot be manipulated using drivers
Until now, there was never any code for making drivers on materials get
recalculated when their dependencies were changed. However, since changing
material colors with drivers is something that is quite common, a workaround was
introduced to ensure that materials could still be driven (albeit with the
relevant drivers rooted at object level). This worked well enough so far with
traditional materials - though it was sometimes clunky and confusing for some
users - and would have been ok to tide us over until the depsgraph refactor.
The introduction of Cycles changed this, as it has in many other ways. Now that
people use Cycles to render, they'll need to drive the material colors through
the nested nodetree (and other things nested deeply within that). However, this
is much more difficult to generate hacks to create the relevant paths needed to
work around the problem.
== This Commit... ==
* Adds a recursive driver calculation step to the BKE_object_handle_update()
(which gets called whenever the depsgraph has finished tagging object datablocks
for updates), which goes through calculating the drivers attached to the object
(and the materials/nodetrees attached to that). This case gets handled everytime
the object is tagged as needing updates to its "data" (OB_RECALC_DATA)
* When building the depsgraph, every dependency that the drivers there have are
treated as if they were attached to object.data instead. This should trick the
depsgraph into tagging OB_RECALC_DATA to force recalculation of drivers, at the
expense perhaps of modifiers getting recalculated again.
== Todo ==
* The old workarounds noted are still in place (will be commented out in the
next commit). This fix renders at least the material case redundant, although
the textures case still needs a bit more work.
* Check on whether similar hacks can be done for other datablock combinations
* So far, only simple test cases have been tested. There is probably some
performance penalty for heavy setups still (due to need to traverse down all
parts of material/node hierarchy to find things that need updates). If there
really is a problem here, we could try introducing some tags to limit this
traversal (which get added at depsgraph build time). <--- USER TESTING
NEEDED!!!
2012-07-03 07:11:37 +02:00
|
|
|
/* ****************** */
|
|
|
|
|
2018-05-29 15:49:21 +02:00
|
|
|
bool BKE_object_material_slot_remove(Main *bmain, Object *ob)
|
2002-10-12 13:37:38 +02:00
|
|
|
{
|
|
|
|
Material *mao, ***matarar;
|
|
|
|
short *totcolp;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
if (ob == nullptr || ob->totcol == 0) {
|
2014-04-01 02:34:00 +02:00
|
|
|
return false;
|
2011-10-12 01:08:17 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-10-12 01:08:17 +02:00
|
|
|
/* this should never happen and used to crash */
|
|
|
|
if (ob->actcol <= 0) {
|
2019-02-01 02:44:19 +01:00
|
|
|
CLOG_ERROR(&LOG, "invalid material index %d, report a bug!", ob->actcol);
|
2014-04-01 02:34:00 +02:00
|
|
|
return false;
|
2011-10-12 01:08:17 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-24 03:21:18 +02:00
|
|
|
/* Take a mesh/curve/meta-ball as starting point, remove 1 index,
|
|
|
|
* AND with all objects that share the `ob->data`.
|
|
|
|
* After that check indices in mesh/curve/meta-ball! */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-04 22:08:23 +01:00
|
|
|
totcolp = BKE_object_material_len_p(ob);
|
|
|
|
matarar = BKE_object_material_array_p(ob);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
if (ELEM(nullptr, matarar, *matarar)) {
|
2013-07-28 08:37:58 +02:00
|
|
|
return false;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-26 18:36:51 +01:00
|
|
|
/* can happen on face selection in editmode */
|
|
|
|
if (ob->actcol > ob->totcol) {
|
|
|
|
ob->actcol = ob->totcol;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2003-04-26 13:56:44 +02:00
|
|
|
/* we delete the actcol */
|
2012-05-06 17:15:33 +02:00
|
|
|
mao = (*matarar)[ob->actcol - 1];
|
2019-04-22 01:39:35 +02:00
|
|
|
if (mao) {
|
2015-11-09 19:47:10 +01:00
|
|
|
id_us_min(&mao->id);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-06 15:56:09 +01:00
|
|
|
for (int a = ob->actcol; a < ob->totcol; a++) {
|
2012-05-06 17:15:33 +02:00
|
|
|
(*matarar)[a - 1] = (*matarar)[a];
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2002-10-12 13:37:38 +02:00
|
|
|
(*totcolp)--;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 17:15:33 +02:00
|
|
|
if (*totcolp == 0) {
|
2002-10-12 13:37:38 +02:00
|
|
|
MEM_freeN(*matarar);
|
2022-11-18 11:08:39 +01:00
|
|
|
*matarar = nullptr;
|
2002-10-12 13:37:38 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-06 15:56:09 +01:00
|
|
|
const int actcol = ob->actcol;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
for (Object *obt = static_cast<Object *>(bmain->objects.first); obt;
|
|
|
|
obt = static_cast<Object *>(obt->id.next))
|
|
|
|
{
|
2012-05-06 17:15:33 +02:00
|
|
|
if (obt->data == ob->data) {
|
2023-02-12 04:37:16 +01:00
|
|
|
/* Can happen when object material lists are used, see: #52953 */
|
2018-01-04 11:35:09 +01:00
|
|
|
if (actcol > obt->totcol) {
|
|
|
|
continue;
|
|
|
|
}
|
2003-04-26 13:56:44 +02:00
|
|
|
/* WATCH IT: do not use actcol from ob or from obt (can become zero) */
|
2012-05-06 17:15:33 +02:00
|
|
|
mao = obt->mat[actcol - 1];
|
2019-04-22 01:39:35 +02:00
|
|
|
if (mao) {
|
2015-11-09 19:47:10 +01:00
|
|
|
id_us_min(&mao->id);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-06 15:56:09 +01:00
|
|
|
for (int a = actcol; a < obt->totcol; a++) {
|
2012-05-06 17:15:33 +02:00
|
|
|
obt->mat[a - 1] = obt->mat[a];
|
|
|
|
obt->matbits[a - 1] = obt->matbits[a];
|
2009-07-13 02:40:20 +02:00
|
|
|
}
|
2002-10-12 13:37:38 +02:00
|
|
|
obt->totcol--;
|
2019-04-22 01:39:35 +02:00
|
|
|
if (obt->actcol > obt->totcol) {
|
2012-05-06 17:15:33 +02:00
|
|
|
obt->actcol = obt->totcol;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 17:15:33 +02:00
|
|
|
if (obt->totcol == 0) {
|
2002-10-12 13:37:38 +02:00
|
|
|
MEM_freeN(obt->mat);
|
2009-07-13 02:40:20 +02:00
|
|
|
MEM_freeN(obt->matbits);
|
2022-11-18 11:08:39 +01:00
|
|
|
obt->mat = nullptr;
|
|
|
|
obt->matbits = nullptr;
|
2002-10-12 13:37:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-11-17 10:37:56 +01:00
|
|
|
/* check indices from mesh and grease pencil. */
|
|
|
|
if (ELEM(ob->type, OB_MESH, OB_CURVES_LEGACY, OB_SURF, OB_FONT, OB_GREASE_PENCIL)) {
|
2013-08-14 13:29:58 +02:00
|
|
|
material_data_index_remove_id((ID *)ob->data, actcol - 1);
|
2023-11-15 18:46:07 +01:00
|
|
|
if (ob->runtime->curve_cache) {
|
|
|
|
BKE_displist_free(&ob->runtime->curve_cache->disp);
|
2013-08-19 11:25:24 +02:00
|
|
|
}
|
2002-10-12 13:37:38 +02:00
|
|
|
}
|
2023-11-17 10:37:56 +01:00
|
|
|
/* check indices from gpencil legacy. */
|
2023-03-08 12:35:58 +01:00
|
|
|
else if (ob->type == OB_GPENCIL_LEGACY) {
|
2019-06-12 15:51:51 +02:00
|
|
|
BKE_gpencil_material_index_reassign((bGPdata *)ob->data, ob->totcol, actcol - 1);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-04-01 02:34:00 +02:00
|
|
|
return true;
|
2002-10-12 13:37:38 +02:00
|
|
|
}
|
Giant commit!
A full detailed description of this will be done later... is several days
of work. Here's a summary:
Render:
- Full cleanup of render code, removing *all* globals and bad level calls
all over blender. Render module is now not called abusive anymore
- API-fied calls to rendering
- Full recode of internal render pipeline. Is now rendering tiles by
default, prepared for much smarter 'bucket' render later.
- Each thread now can render a full part
- Renders were tested with 4 threads, goes fine, apart from some lookup
tables in softshadow and AO still
- Rendering is prepared to do multiple layers and passes
- No single 32 bits trick in render code anymore, all 100% floats now.
Writing images/movies
- moved writing images to blender kernel (bye bye 'schrijfplaatje'!)
- made a new Movie handle system, also in kernel. This will enable much
easier use of movies in Blender
PreviewRender:
- Using new render API, previewrender (in buttons) now uses regular render
code to generate images.
- new datafile 'preview.blend.c' has the preview scenes in it
- previews get rendered in exact displayed size (1 pixel = 1 pixel)
3D Preview render
- new; press Pkey in 3d window, for a panel that continuously renders
(pkey is for games, i know... but we dont do that in orange now!)
- this render works nearly identical to buttons-preview render, so it stops
rendering on any event (mouse, keyboard, etc)
- on moving/scaling the panel, the render code doesn't recreate all geometry
- same for shifting/panning view
- all other operations (now) regenerate the full render database still.
- this is WIP... but big fun, especially for simple scenes!
Compositor
- Using same node system as now in use for shaders, you can composit images
- works pretty straightforward... needs much more options/tools and integration
with rendering still
- is not threaded yet, nor is so smart to only recalculate changes... will be
done soon!
- the "Render Result" node will get all layers/passes as output sockets
- The "Output" node renders to a builtin image, which you can view in the Image
window. (yes, output nodes to render-result, and to files, is on the list!)
The Bad News
- "Unified Render" is removed. It might come back in some stage, but this
system should be built from scratch. I can't really understand this code...
I expect it is not much needed, especially with advanced layer/passes
control
- Panorama render, Field render, Motion blur, is not coded yet... (I had to
recode every single feature in render, so...!)
- Lens Flare is also not back... needs total revision, might become composit
effect though (using zbuffer for visibility)
- Part render is gone! (well, thats obvious, its default now).
- The render window is only restored with limited functionality... I am going
to check first the option to render to a Image window, so Blender can become
a true single-window application. :)
For example, the 'Spare render buffer' (jkey) doesnt work.
- Render with border, now default creates a smaller image
- No zbuffers are written yet... on the todo!
- Scons files and MSVC will need work to get compiling again
OK... thats what I can quickly recall. Now go compiling!
2006-01-23 23:05:47 +01:00
|
|
|
|
2015-01-28 14:42:47 +01:00
|
|
|
static bNode *nodetree_uv_node_recursive(bNode *node)
|
|
|
|
{
|
2023-08-04 00:51:13 +02:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
|
2015-01-28 14:42:47 +01:00
|
|
|
if (sock->link) {
|
2023-08-04 00:51:13 +02:00
|
|
|
bNode *inode = sock->link->fromnode;
|
2015-01-28 14:42:47 +01:00
|
|
|
if (inode->typeinfo->nclass == NODE_CLASS_INPUT && inode->typeinfo->type == SH_NODE_UVMAP) {
|
|
|
|
return inode;
|
|
|
|
}
|
2020-08-07 12:30:43 +02:00
|
|
|
|
|
|
|
return nodetree_uv_node_recursive(inode);
|
2015-01-28 14:42:47 +01:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
return nullptr;
|
2015-01-28 14:42:47 +01:00
|
|
|
}
|
|
|
|
|
2022-04-08 16:37:35 +02:00
|
|
|
/** Bitwise filter for updating paint slots. */
|
2022-12-29 18:01:32 +01:00
|
|
|
enum ePaintSlotFilter {
|
2022-04-08 16:37:35 +02:00
|
|
|
PAINT_SLOT_IMAGE = 1 << 0,
|
|
|
|
PAINT_SLOT_COLOR_ATTRIBUTE = 1 << 1,
|
2022-12-29 18:01:32 +01:00
|
|
|
};
|
2022-11-18 11:08:39 +01:00
|
|
|
ENUM_OPERATORS(ePaintSlotFilter, PAINT_SLOT_COLOR_ATTRIBUTE)
|
2022-04-08 16:37:35 +02:00
|
|
|
|
2022-12-29 18:01:32 +01:00
|
|
|
using ForEachTexNodeCallback = bool (*)(bNode *node, void *userdata);
|
2019-07-31 16:37:03 +02:00
|
|
|
static bool ntree_foreach_texnode_recursive(bNodeTree *nodetree,
|
|
|
|
ForEachTexNodeCallback callback,
|
2022-04-08 16:37:35 +02:00
|
|
|
void *userdata,
|
|
|
|
ePaintSlotFilter slot_filter)
|
2018-09-10 18:18:04 +02:00
|
|
|
{
|
2022-04-08 16:37:35 +02:00
|
|
|
const bool do_image_nodes = (slot_filter & PAINT_SLOT_IMAGE) != 0;
|
|
|
|
const bool do_color_attributes = (slot_filter & PAINT_SLOT_COLOR_ATTRIBUTE) != 0;
|
2022-12-02 18:12:51 +01:00
|
|
|
for (bNode *node : nodetree->all_nodes()) {
|
2022-04-08 16:37:35 +02:00
|
|
|
if (do_image_nodes && node->typeinfo->nclass == NODE_CLASS_TEXTURE &&
|
2018-09-10 18:18:04 +02:00
|
|
|
node->typeinfo->type == SH_NODE_TEX_IMAGE && node->id)
|
|
|
|
{
|
2019-07-31 16:37:03 +02:00
|
|
|
if (!callback(node, userdata)) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-10 18:18:04 +02:00
|
|
|
}
|
2022-04-08 16:37:35 +02:00
|
|
|
if (do_color_attributes && node->typeinfo->type == SH_NODE_ATTRIBUTE) {
|
|
|
|
if (!callback(node, userdata)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-03-16 18:48:22 +01:00
|
|
|
else if (ELEM(node->type, NODE_GROUP, NODE_CUSTOM_GROUP) && node->id) {
|
2018-09-10 18:18:04 +02:00
|
|
|
/* recurse into the node group and see if it contains any textures */
|
2022-04-08 16:37:35 +02:00
|
|
|
if (!ntree_foreach_texnode_recursive((bNodeTree *)node->id, callback, userdata, slot_filter))
|
|
|
|
{
|
2019-07-31 16:37:03 +02:00
|
|
|
return false;
|
|
|
|
}
|
2018-09-10 18:18:04 +02:00
|
|
|
}
|
|
|
|
}
|
2019-07-31 16:37:03 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-12-20 19:51:47 +01:00
|
|
|
static bool count_texture_nodes_cb(bNode * /*node*/, void *userdata)
|
2019-07-31 16:37:03 +02:00
|
|
|
{
|
|
|
|
(*((int *)userdata))++;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-04-08 16:37:35 +02:00
|
|
|
static int count_texture_nodes_recursive(bNodeTree *nodetree, ePaintSlotFilter slot_filter)
|
2019-07-31 16:37:03 +02:00
|
|
|
{
|
|
|
|
int tex_nodes = 0;
|
2022-04-08 16:37:35 +02:00
|
|
|
ntree_foreach_texnode_recursive(nodetree, count_texture_nodes_cb, &tex_nodes, slot_filter);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-10 18:18:04 +02:00
|
|
|
return tex_nodes;
|
|
|
|
}
|
|
|
|
|
2019-07-31 16:37:03 +02:00
|
|
|
struct FillTexPaintSlotsData {
|
|
|
|
bNode *active_node;
|
2022-04-08 16:37:35 +02:00
|
|
|
const Object *ob;
|
2019-07-31 16:37:03 +02:00
|
|
|
Material *ma;
|
|
|
|
int index;
|
|
|
|
int slot_len;
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool fill_texpaint_slots_cb(bNode *node, void *userdata)
|
2018-09-10 18:18:04 +02:00
|
|
|
{
|
2023-06-03 00:36:28 +02:00
|
|
|
FillTexPaintSlotsData *fill_data = static_cast<FillTexPaintSlotsData *>(userdata);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-07-31 16:37:03 +02:00
|
|
|
Material *ma = fill_data->ma;
|
|
|
|
int index = fill_data->index;
|
|
|
|
fill_data->index++;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-07-31 16:37:03 +02:00
|
|
|
if (fill_data->active_node == node) {
|
|
|
|
ma->paint_active_slot = index;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-04-08 16:37:35 +02:00
|
|
|
switch (node->type) {
|
|
|
|
case SH_NODE_TEX_IMAGE: {
|
|
|
|
TexPaintSlot *slot = &ma->texpaintslot[index];
|
|
|
|
slot->ima = (Image *)node->id;
|
2022-04-15 16:39:50 +02:00
|
|
|
NodeTexImage *storage = (NodeTexImage *)node->storage;
|
|
|
|
slot->interp = storage->interpolation;
|
|
|
|
slot->image_user = &storage->iuser;
|
2022-11-01 02:24:06 +01:00
|
|
|
/* For new renderer, we need to traverse the tree back in search of a UV node. */
|
2022-04-08 16:37:35 +02:00
|
|
|
bNode *uvnode = nodetree_uv_node_recursive(node);
|
2019-07-31 16:37:03 +02:00
|
|
|
|
2022-04-08 16:37:35 +02:00
|
|
|
if (uvnode) {
|
2022-04-15 16:39:50 +02:00
|
|
|
NodeShaderUVMap *uv_storage = (NodeShaderUVMap *)uvnode->storage;
|
|
|
|
slot->uvname = uv_storage->uv_map;
|
2022-04-08 16:37:35 +02:00
|
|
|
/* set a value to index so UI knows that we have a valid pointer for the mesh */
|
|
|
|
slot->valid = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* just invalidate the index here so UV map does not get displayed on the UI */
|
|
|
|
slot->valid = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2019-07-31 16:37:03 +02:00
|
|
|
|
2022-04-08 16:37:35 +02:00
|
|
|
case SH_NODE_ATTRIBUTE: {
|
|
|
|
TexPaintSlot *slot = &ma->texpaintslot[index];
|
2022-11-18 11:08:39 +01:00
|
|
|
NodeShaderAttribute *storage = static_cast<NodeShaderAttribute *>(node->storage);
|
2022-04-08 16:37:35 +02:00
|
|
|
slot->attribute_name = storage->name;
|
|
|
|
if (storage->type == SHD_ATTRIBUTE_GEOMETRY) {
|
|
|
|
const Mesh *mesh = (const Mesh *)fill_data->ob->data;
|
2022-06-07 18:55:56 +02:00
|
|
|
const CustomDataLayer *layer = BKE_id_attributes_color_find(&mesh->id, storage->name);
|
2022-11-18 11:08:39 +01:00
|
|
|
slot->valid = layer != nullptr;
|
2022-04-08 16:37:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Do not show unsupported attributes. */
|
|
|
|
if (!slot->valid) {
|
2022-11-18 11:08:39 +01:00
|
|
|
slot->attribute_name = nullptr;
|
2022-04-08 16:37:35 +02:00
|
|
|
fill_data->index--;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2018-09-10 18:18:04 +02:00
|
|
|
}
|
2019-07-31 16:37:03 +02:00
|
|
|
|
|
|
|
return fill_data->index != fill_data->slot_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fill_texpaint_slots_recursive(bNodeTree *nodetree,
|
|
|
|
bNode *active_node,
|
2022-04-08 16:37:35 +02:00
|
|
|
const Object *ob,
|
2019-07-31 16:37:03 +02:00
|
|
|
Material *ma,
|
2022-04-08 16:37:35 +02:00
|
|
|
int slot_len,
|
|
|
|
ePaintSlotFilter slot_filter)
|
|
|
|
{
|
2023-06-03 00:36:28 +02:00
|
|
|
FillTexPaintSlotsData fill_data = {active_node, ob, ma, 0, slot_len};
|
2022-04-08 16:37:35 +02:00
|
|
|
ntree_foreach_texnode_recursive(nodetree, fill_texpaint_slots_cb, &fill_data, slot_filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Check which type of paint slots should be filled for the given object. */
|
2023-06-03 00:36:28 +02:00
|
|
|
static ePaintSlotFilter material_paint_slot_filter(const Object *ob)
|
2019-07-31 16:37:03 +02:00
|
|
|
{
|
2022-04-08 16:37:35 +02:00
|
|
|
ePaintSlotFilter slot_filter = PAINT_SLOT_IMAGE;
|
|
|
|
if (ob->mode == OB_MODE_SCULPT && U.experimental.use_sculpt_texture_paint) {
|
|
|
|
slot_filter |= PAINT_SLOT_COLOR_ATTRIBUTE;
|
|
|
|
}
|
|
|
|
return slot_filter;
|
2018-09-10 18:18:04 +02:00
|
|
|
}
|
|
|
|
|
2023-06-03 00:36:28 +02:00
|
|
|
void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma, const Object *ob)
|
2014-07-21 12:02:05 +02:00
|
|
|
{
|
2019-04-22 01:39:35 +02:00
|
|
|
if (!ma) {
|
2014-08-28 16:40:38 +02:00
|
|
|
return;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2022-04-08 16:37:35 +02:00
|
|
|
const ePaintSlotFilter slot_filter = material_paint_slot_filter(ob);
|
|
|
|
|
2022-10-26 19:27:12 +02:00
|
|
|
const TexPaintSlot *prev_texpaintslot = ma->texpaintslot;
|
|
|
|
const int prev_paint_active_slot = ma->paint_active_slot;
|
|
|
|
const int prev_paint_clone_slot = ma->paint_clone_slot;
|
|
|
|
const int prev_tot_slots = ma->tot_slots;
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
ma->texpaintslot = nullptr;
|
2022-10-26 19:27:12 +02:00
|
|
|
ma->tot_slots = 0;
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2019-03-07 19:39:50 +01:00
|
|
|
if (scene->toolsettings->imapaint.mode == IMAGEPAINT_MODE_IMAGE) {
|
|
|
|
ma->paint_active_slot = 0;
|
|
|
|
ma->paint_clone_slot = 0;
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
}
|
2022-10-26 19:27:12 +02:00
|
|
|
else if (!(ma->nodetree)) {
|
2019-03-07 19:39:50 +01:00
|
|
|
ma->paint_active_slot = 0;
|
|
|
|
ma->paint_clone_slot = 0;
|
2019-02-28 14:09:19 +01:00
|
|
|
}
|
2022-10-26 19:27:12 +02:00
|
|
|
else {
|
|
|
|
int count = count_texture_nodes_recursive(ma->nodetree, slot_filter);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2022-10-26 19:27:12 +02:00
|
|
|
if (count == 0) {
|
|
|
|
ma->paint_active_slot = 0;
|
|
|
|
ma->paint_clone_slot = 0;
|
|
|
|
}
|
|
|
|
else {
|
2022-11-18 11:08:39 +01:00
|
|
|
ma->texpaintslot = static_cast<TexPaintSlot *>(
|
|
|
|
MEM_callocN(sizeof(TexPaintSlot) * count, "texpaint_slots"));
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2023-05-15 15:14:22 +02:00
|
|
|
bNode *active_node = blender::bke::nodeGetActivePaintCanvas(ma->nodetree);
|
2019-03-07 19:39:50 +01:00
|
|
|
|
2022-10-26 19:27:12 +02:00
|
|
|
fill_texpaint_slots_recursive(ma->nodetree, active_node, ob, ma, count, slot_filter);
|
2019-03-07 19:39:50 +01:00
|
|
|
|
2022-10-26 19:27:12 +02:00
|
|
|
ma->tot_slots = count;
|
2019-03-07 19:39:50 +01:00
|
|
|
|
2022-10-26 19:27:12 +02:00
|
|
|
if (ma->paint_active_slot >= count) {
|
|
|
|
ma->paint_active_slot = count - 1;
|
|
|
|
}
|
2019-03-07 19:39:50 +01:00
|
|
|
|
2022-10-26 19:27:12 +02:00
|
|
|
if (ma->paint_clone_slot >= count) {
|
|
|
|
ma->paint_clone_slot = count - 1;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-03-07 19:39:50 +01:00
|
|
|
|
2022-10-26 19:27:12 +02:00
|
|
|
/* COW needed when adding texture slot on an object with no materials.
|
2022-11-01 02:24:06 +01:00
|
|
|
* But do it only when slots actually change to avoid continuous depsgraph updates. */
|
2022-10-26 19:27:12 +02:00
|
|
|
if (ma->tot_slots != prev_tot_slots || ma->paint_active_slot != prev_paint_active_slot ||
|
|
|
|
ma->paint_clone_slot != prev_paint_clone_slot ||
|
|
|
|
(ma->texpaintslot && prev_texpaintslot &&
|
|
|
|
memcmp(ma->texpaintslot, prev_texpaintslot, sizeof(*ma->texpaintslot) * ma->tot_slots) !=
|
|
|
|
0))
|
|
|
|
{
|
|
|
|
DEG_id_tag_update(&ma->id, ID_RECALC_SHADING | ID_RECALC_COPY_ON_WRITE);
|
2019-03-07 19:39:50 +01:00
|
|
|
}
|
2022-10-26 19:27:12 +02:00
|
|
|
|
|
|
|
MEM_SAFE_FREE(prev_texpaintslot);
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
|
|
|
|
2023-06-03 00:36:28 +02:00
|
|
|
void BKE_texpaint_slots_refresh_object(Scene *scene, Object *ob)
|
2014-07-21 12:02:05 +02:00
|
|
|
{
|
2020-09-09 16:35:20 +02:00
|
|
|
for (int i = 1; i < ob->totcol + 1; i++) {
|
2020-02-05 11:23:58 +01:00
|
|
|
Material *ma = BKE_object_material_get(ob, i);
|
2022-04-08 16:37:35 +02:00
|
|
|
BKE_texpaint_slot_refresh_cache(scene, ma, ob);
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-31 16:37:03 +02:00
|
|
|
struct FindTexPaintNodeData {
|
2022-04-08 16:37:35 +02:00
|
|
|
TexPaintSlot *slot;
|
2021-06-04 16:00:51 +02:00
|
|
|
bNode *r_node;
|
2019-07-31 16:37:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool texpaint_slot_node_find_cb(bNode *node, void *userdata)
|
|
|
|
{
|
2023-06-03 00:36:28 +02:00
|
|
|
FindTexPaintNodeData *find_data = static_cast<FindTexPaintNodeData *>(userdata);
|
2022-04-08 16:37:35 +02:00
|
|
|
if (find_data->slot->ima && node->type == SH_NODE_TEX_IMAGE) {
|
|
|
|
Image *node_ima = (Image *)node->id;
|
|
|
|
if (find_data->slot->ima == node_ima) {
|
|
|
|
find_data->r_node = node;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (find_data->slot->attribute_name && node->type == SH_NODE_ATTRIBUTE) {
|
2022-11-18 11:08:39 +01:00
|
|
|
NodeShaderAttribute *storage = static_cast<NodeShaderAttribute *>(node->storage);
|
2022-04-08 16:37:35 +02:00
|
|
|
if (STREQLEN(find_data->slot->attribute_name, storage->name, sizeof(storage->name))) {
|
|
|
|
find_data->r_node = node;
|
|
|
|
return false;
|
|
|
|
}
|
2019-07-31 16:37:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bNode *BKE_texpaint_slot_material_find_node(Material *ma, short texpaint_slot)
|
|
|
|
{
|
2022-04-08 16:37:35 +02:00
|
|
|
TexPaintSlot *slot = &ma->texpaintslot[texpaint_slot];
|
2023-06-03 00:36:28 +02:00
|
|
|
FindTexPaintNodeData find_data = {slot, nullptr};
|
2022-04-08 16:37:35 +02:00
|
|
|
ntree_foreach_texnode_recursive(ma->nodetree,
|
|
|
|
texpaint_slot_node_find_cb,
|
|
|
|
&find_data,
|
|
|
|
PAINT_SLOT_IMAGE | PAINT_SLOT_COLOR_ATTRIBUTE);
|
2019-07-31 16:37:03 +02:00
|
|
|
|
2021-06-04 16:00:51 +02:00
|
|
|
return find_data.r_node;
|
2019-07-31 16:37:03 +02:00
|
|
|
}
|
|
|
|
|
2011-11-26 14:11:55 +01:00
|
|
|
void ramp_blend(int type, float r_col[3], const float fac, const float col[3])
|
Giant commit!
A full detailed description of this will be done later... is several days
of work. Here's a summary:
Render:
- Full cleanup of render code, removing *all* globals and bad level calls
all over blender. Render module is now not called abusive anymore
- API-fied calls to rendering
- Full recode of internal render pipeline. Is now rendering tiles by
default, prepared for much smarter 'bucket' render later.
- Each thread now can render a full part
- Renders were tested with 4 threads, goes fine, apart from some lookup
tables in softshadow and AO still
- Rendering is prepared to do multiple layers and passes
- No single 32 bits trick in render code anymore, all 100% floats now.
Writing images/movies
- moved writing images to blender kernel (bye bye 'schrijfplaatje'!)
- made a new Movie handle system, also in kernel. This will enable much
easier use of movies in Blender
PreviewRender:
- Using new render API, previewrender (in buttons) now uses regular render
code to generate images.
- new datafile 'preview.blend.c' has the preview scenes in it
- previews get rendered in exact displayed size (1 pixel = 1 pixel)
3D Preview render
- new; press Pkey in 3d window, for a panel that continuously renders
(pkey is for games, i know... but we dont do that in orange now!)
- this render works nearly identical to buttons-preview render, so it stops
rendering on any event (mouse, keyboard, etc)
- on moving/scaling the panel, the render code doesn't recreate all geometry
- same for shifting/panning view
- all other operations (now) regenerate the full render database still.
- this is WIP... but big fun, especially for simple scenes!
Compositor
- Using same node system as now in use for shaders, you can composit images
- works pretty straightforward... needs much more options/tools and integration
with rendering still
- is not threaded yet, nor is so smart to only recalculate changes... will be
done soon!
- the "Render Result" node will get all layers/passes as output sockets
- The "Output" node renders to a builtin image, which you can view in the Image
window. (yes, output nodes to render-result, and to files, is on the list!)
The Bad News
- "Unified Render" is removed. It might come back in some stage, but this
system should be built from scratch. I can't really understand this code...
I expect it is not much needed, especially with advanced layer/passes
control
- Panorama render, Field render, Motion blur, is not coded yet... (I had to
recode every single feature in render, so...!)
- Lens Flare is also not back... needs total revision, might become composit
effect though (using zbuffer for visibility)
- Part render is gone! (well, thats obvious, its default now).
- The render window is only restored with limited functionality... I am going
to check first the option to render to a Image window, so Blender can become
a true single-window application. :)
For example, the 'Spare render buffer' (jkey) doesnt work.
- Render with border, now default creates a smaller image
- No zbuffers are written yet... on the todo!
- Scons files and MSVC will need work to get compiling again
OK... thats what I can quickly recall. Now go compiling!
2006-01-23 23:05:47 +01:00
|
|
|
{
|
2012-05-06 17:15:33 +02:00
|
|
|
float tmp, facm = 1.0f - fac;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Giant commit!
A full detailed description of this will be done later... is several days
of work. Here's a summary:
Render:
- Full cleanup of render code, removing *all* globals and bad level calls
all over blender. Render module is now not called abusive anymore
- API-fied calls to rendering
- Full recode of internal render pipeline. Is now rendering tiles by
default, prepared for much smarter 'bucket' render later.
- Each thread now can render a full part
- Renders were tested with 4 threads, goes fine, apart from some lookup
tables in softshadow and AO still
- Rendering is prepared to do multiple layers and passes
- No single 32 bits trick in render code anymore, all 100% floats now.
Writing images/movies
- moved writing images to blender kernel (bye bye 'schrijfplaatje'!)
- made a new Movie handle system, also in kernel. This will enable much
easier use of movies in Blender
PreviewRender:
- Using new render API, previewrender (in buttons) now uses regular render
code to generate images.
- new datafile 'preview.blend.c' has the preview scenes in it
- previews get rendered in exact displayed size (1 pixel = 1 pixel)
3D Preview render
- new; press Pkey in 3d window, for a panel that continuously renders
(pkey is for games, i know... but we dont do that in orange now!)
- this render works nearly identical to buttons-preview render, so it stops
rendering on any event (mouse, keyboard, etc)
- on moving/scaling the panel, the render code doesn't recreate all geometry
- same for shifting/panning view
- all other operations (now) regenerate the full render database still.
- this is WIP... but big fun, especially for simple scenes!
Compositor
- Using same node system as now in use for shaders, you can composit images
- works pretty straightforward... needs much more options/tools and integration
with rendering still
- is not threaded yet, nor is so smart to only recalculate changes... will be
done soon!
- the "Render Result" node will get all layers/passes as output sockets
- The "Output" node renders to a builtin image, which you can view in the Image
window. (yes, output nodes to render-result, and to files, is on the list!)
The Bad News
- "Unified Render" is removed. It might come back in some stage, but this
system should be built from scratch. I can't really understand this code...
I expect it is not much needed, especially with advanced layer/passes
control
- Panorama render, Field render, Motion blur, is not coded yet... (I had to
recode every single feature in render, so...!)
- Lens Flare is also not back... needs total revision, might become composit
effect though (using zbuffer for visibility)
- Part render is gone! (well, thats obvious, its default now).
- The render window is only restored with limited functionality... I am going
to check first the option to render to a Image window, so Blender can become
a true single-window application. :)
For example, the 'Spare render buffer' (jkey) doesnt work.
- Render with border, now default creates a smaller image
- No zbuffers are written yet... on the todo!
- Scons files and MSVC will need work to get compiling again
OK... thats what I can quickly recall. Now go compiling!
2006-01-23 23:05:47 +01:00
|
|
|
switch (type) {
|
|
|
|
case MA_RAMP_BLEND:
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[0] = facm * (r_col[0]) + fac * col[0];
|
|
|
|
r_col[1] = facm * (r_col[1]) + fac * col[1];
|
|
|
|
r_col[2] = facm * (r_col[2]) + fac * col[2];
|
2011-11-26 22:42:04 +01:00
|
|
|
break;
|
Giant commit!
A full detailed description of this will be done later... is several days
of work. Here's a summary:
Render:
- Full cleanup of render code, removing *all* globals and bad level calls
all over blender. Render module is now not called abusive anymore
- API-fied calls to rendering
- Full recode of internal render pipeline. Is now rendering tiles by
default, prepared for much smarter 'bucket' render later.
- Each thread now can render a full part
- Renders were tested with 4 threads, goes fine, apart from some lookup
tables in softshadow and AO still
- Rendering is prepared to do multiple layers and passes
- No single 32 bits trick in render code anymore, all 100% floats now.
Writing images/movies
- moved writing images to blender kernel (bye bye 'schrijfplaatje'!)
- made a new Movie handle system, also in kernel. This will enable much
easier use of movies in Blender
PreviewRender:
- Using new render API, previewrender (in buttons) now uses regular render
code to generate images.
- new datafile 'preview.blend.c' has the preview scenes in it
- previews get rendered in exact displayed size (1 pixel = 1 pixel)
3D Preview render
- new; press Pkey in 3d window, for a panel that continuously renders
(pkey is for games, i know... but we dont do that in orange now!)
- this render works nearly identical to buttons-preview render, so it stops
rendering on any event (mouse, keyboard, etc)
- on moving/scaling the panel, the render code doesn't recreate all geometry
- same for shifting/panning view
- all other operations (now) regenerate the full render database still.
- this is WIP... but big fun, especially for simple scenes!
Compositor
- Using same node system as now in use for shaders, you can composit images
- works pretty straightforward... needs much more options/tools and integration
with rendering still
- is not threaded yet, nor is so smart to only recalculate changes... will be
done soon!
- the "Render Result" node will get all layers/passes as output sockets
- The "Output" node renders to a builtin image, which you can view in the Image
window. (yes, output nodes to render-result, and to files, is on the list!)
The Bad News
- "Unified Render" is removed. It might come back in some stage, but this
system should be built from scratch. I can't really understand this code...
I expect it is not much needed, especially with advanced layer/passes
control
- Panorama render, Field render, Motion blur, is not coded yet... (I had to
recode every single feature in render, so...!)
- Lens Flare is also not back... needs total revision, might become composit
effect though (using zbuffer for visibility)
- Part render is gone! (well, thats obvious, its default now).
- The render window is only restored with limited functionality... I am going
to check first the option to render to a Image window, so Blender can become
a true single-window application. :)
For example, the 'Spare render buffer' (jkey) doesnt work.
- Render with border, now default creates a smaller image
- No zbuffers are written yet... on the todo!
- Scons files and MSVC will need work to get compiling again
OK... thats what I can quickly recall. Now go compiling!
2006-01-23 23:05:47 +01:00
|
|
|
case MA_RAMP_ADD:
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[0] += fac * col[0];
|
|
|
|
r_col[1] += fac * col[1];
|
|
|
|
r_col[2] += fac * col[2];
|
2011-11-26 22:42:04 +01:00
|
|
|
break;
|
Giant commit!
A full detailed description of this will be done later... is several days
of work. Here's a summary:
Render:
- Full cleanup of render code, removing *all* globals and bad level calls
all over blender. Render module is now not called abusive anymore
- API-fied calls to rendering
- Full recode of internal render pipeline. Is now rendering tiles by
default, prepared for much smarter 'bucket' render later.
- Each thread now can render a full part
- Renders were tested with 4 threads, goes fine, apart from some lookup
tables in softshadow and AO still
- Rendering is prepared to do multiple layers and passes
- No single 32 bits trick in render code anymore, all 100% floats now.
Writing images/movies
- moved writing images to blender kernel (bye bye 'schrijfplaatje'!)
- made a new Movie handle system, also in kernel. This will enable much
easier use of movies in Blender
PreviewRender:
- Using new render API, previewrender (in buttons) now uses regular render
code to generate images.
- new datafile 'preview.blend.c' has the preview scenes in it
- previews get rendered in exact displayed size (1 pixel = 1 pixel)
3D Preview render
- new; press Pkey in 3d window, for a panel that continuously renders
(pkey is for games, i know... but we dont do that in orange now!)
- this render works nearly identical to buttons-preview render, so it stops
rendering on any event (mouse, keyboard, etc)
- on moving/scaling the panel, the render code doesn't recreate all geometry
- same for shifting/panning view
- all other operations (now) regenerate the full render database still.
- this is WIP... but big fun, especially for simple scenes!
Compositor
- Using same node system as now in use for shaders, you can composit images
- works pretty straightforward... needs much more options/tools and integration
with rendering still
- is not threaded yet, nor is so smart to only recalculate changes... will be
done soon!
- the "Render Result" node will get all layers/passes as output sockets
- The "Output" node renders to a builtin image, which you can view in the Image
window. (yes, output nodes to render-result, and to files, is on the list!)
The Bad News
- "Unified Render" is removed. It might come back in some stage, but this
system should be built from scratch. I can't really understand this code...
I expect it is not much needed, especially with advanced layer/passes
control
- Panorama render, Field render, Motion blur, is not coded yet... (I had to
recode every single feature in render, so...!)
- Lens Flare is also not back... needs total revision, might become composit
effect though (using zbuffer for visibility)
- Part render is gone! (well, thats obvious, its default now).
- The render window is only restored with limited functionality... I am going
to check first the option to render to a Image window, so Blender can become
a true single-window application. :)
For example, the 'Spare render buffer' (jkey) doesnt work.
- Render with border, now default creates a smaller image
- No zbuffers are written yet... on the todo!
- Scons files and MSVC will need work to get compiling again
OK... thats what I can quickly recall. Now go compiling!
2006-01-23 23:05:47 +01:00
|
|
|
case MA_RAMP_MULT:
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[0] *= (facm + fac * col[0]);
|
|
|
|
r_col[1] *= (facm + fac * col[1]);
|
|
|
|
r_col[2] *= (facm + fac * col[2]);
|
2011-11-26 22:42:04 +01:00
|
|
|
break;
|
Giant commit!
A full detailed description of this will be done later... is several days
of work. Here's a summary:
Render:
- Full cleanup of render code, removing *all* globals and bad level calls
all over blender. Render module is now not called abusive anymore
- API-fied calls to rendering
- Full recode of internal render pipeline. Is now rendering tiles by
default, prepared for much smarter 'bucket' render later.
- Each thread now can render a full part
- Renders were tested with 4 threads, goes fine, apart from some lookup
tables in softshadow and AO still
- Rendering is prepared to do multiple layers and passes
- No single 32 bits trick in render code anymore, all 100% floats now.
Writing images/movies
- moved writing images to blender kernel (bye bye 'schrijfplaatje'!)
- made a new Movie handle system, also in kernel. This will enable much
easier use of movies in Blender
PreviewRender:
- Using new render API, previewrender (in buttons) now uses regular render
code to generate images.
- new datafile 'preview.blend.c' has the preview scenes in it
- previews get rendered in exact displayed size (1 pixel = 1 pixel)
3D Preview render
- new; press Pkey in 3d window, for a panel that continuously renders
(pkey is for games, i know... but we dont do that in orange now!)
- this render works nearly identical to buttons-preview render, so it stops
rendering on any event (mouse, keyboard, etc)
- on moving/scaling the panel, the render code doesn't recreate all geometry
- same for shifting/panning view
- all other operations (now) regenerate the full render database still.
- this is WIP... but big fun, especially for simple scenes!
Compositor
- Using same node system as now in use for shaders, you can composit images
- works pretty straightforward... needs much more options/tools and integration
with rendering still
- is not threaded yet, nor is so smart to only recalculate changes... will be
done soon!
- the "Render Result" node will get all layers/passes as output sockets
- The "Output" node renders to a builtin image, which you can view in the Image
window. (yes, output nodes to render-result, and to files, is on the list!)
The Bad News
- "Unified Render" is removed. It might come back in some stage, but this
system should be built from scratch. I can't really understand this code...
I expect it is not much needed, especially with advanced layer/passes
control
- Panorama render, Field render, Motion blur, is not coded yet... (I had to
recode every single feature in render, so...!)
- Lens Flare is also not back... needs total revision, might become composit
effect though (using zbuffer for visibility)
- Part render is gone! (well, thats obvious, its default now).
- The render window is only restored with limited functionality... I am going
to check first the option to render to a Image window, so Blender can become
a true single-window application. :)
For example, the 'Spare render buffer' (jkey) doesnt work.
- Render with border, now default creates a smaller image
- No zbuffers are written yet... on the todo!
- Scons files and MSVC will need work to get compiling again
OK... thats what I can quickly recall. Now go compiling!
2006-01-23 23:05:47 +01:00
|
|
|
case MA_RAMP_SCREEN:
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[0] = 1.0f - (facm + fac * (1.0f - col[0])) * (1.0f - r_col[0]);
|
|
|
|
r_col[1] = 1.0f - (facm + fac * (1.0f - col[1])) * (1.0f - r_col[1]);
|
|
|
|
r_col[2] = 1.0f - (facm + fac * (1.0f - col[2])) * (1.0f - r_col[2]);
|
2011-11-26 22:42:04 +01:00
|
|
|
break;
|
2006-02-14 19:41:34 +01:00
|
|
|
case MA_RAMP_OVERLAY:
|
2019-04-22 01:39:35 +02:00
|
|
|
if (r_col[0] < 0.5f) {
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[0] *= (facm + 2.0f * fac * col[0]);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[0] = 1.0f - (facm + 2.0f * fac * (1.0f - col[0])) * (1.0f - r_col[0]);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
if (r_col[1] < 0.5f) {
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[1] *= (facm + 2.0f * fac * col[1]);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[1] = 1.0f - (facm + 2.0f * fac * (1.0f - col[1])) * (1.0f - r_col[1]);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
if (r_col[2] < 0.5f) {
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[2] *= (facm + 2.0f * fac * col[2]);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[2] = 1.0f - (facm + 2.0f * fac * (1.0f - col[2])) * (1.0f - r_col[2]);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2011-11-26 22:42:04 +01:00
|
|
|
break;
|
Giant commit!
A full detailed description of this will be done later... is several days
of work. Here's a summary:
Render:
- Full cleanup of render code, removing *all* globals and bad level calls
all over blender. Render module is now not called abusive anymore
- API-fied calls to rendering
- Full recode of internal render pipeline. Is now rendering tiles by
default, prepared for much smarter 'bucket' render later.
- Each thread now can render a full part
- Renders were tested with 4 threads, goes fine, apart from some lookup
tables in softshadow and AO still
- Rendering is prepared to do multiple layers and passes
- No single 32 bits trick in render code anymore, all 100% floats now.
Writing images/movies
- moved writing images to blender kernel (bye bye 'schrijfplaatje'!)
- made a new Movie handle system, also in kernel. This will enable much
easier use of movies in Blender
PreviewRender:
- Using new render API, previewrender (in buttons) now uses regular render
code to generate images.
- new datafile 'preview.blend.c' has the preview scenes in it
- previews get rendered in exact displayed size (1 pixel = 1 pixel)
3D Preview render
- new; press Pkey in 3d window, for a panel that continuously renders
(pkey is for games, i know... but we dont do that in orange now!)
- this render works nearly identical to buttons-preview render, so it stops
rendering on any event (mouse, keyboard, etc)
- on moving/scaling the panel, the render code doesn't recreate all geometry
- same for shifting/panning view
- all other operations (now) regenerate the full render database still.
- this is WIP... but big fun, especially for simple scenes!
Compositor
- Using same node system as now in use for shaders, you can composit images
- works pretty straightforward... needs much more options/tools and integration
with rendering still
- is not threaded yet, nor is so smart to only recalculate changes... will be
done soon!
- the "Render Result" node will get all layers/passes as output sockets
- The "Output" node renders to a builtin image, which you can view in the Image
window. (yes, output nodes to render-result, and to files, is on the list!)
The Bad News
- "Unified Render" is removed. It might come back in some stage, but this
system should be built from scratch. I can't really understand this code...
I expect it is not much needed, especially with advanced layer/passes
control
- Panorama render, Field render, Motion blur, is not coded yet... (I had to
recode every single feature in render, so...!)
- Lens Flare is also not back... needs total revision, might become composit
effect though (using zbuffer for visibility)
- Part render is gone! (well, thats obvious, its default now).
- The render window is only restored with limited functionality... I am going
to check first the option to render to a Image window, so Blender can become
a true single-window application. :)
For example, the 'Spare render buffer' (jkey) doesnt work.
- Render with border, now default creates a smaller image
- No zbuffers are written yet... on the todo!
- Scons files and MSVC will need work to get compiling again
OK... thats what I can quickly recall. Now go compiling!
2006-01-23 23:05:47 +01:00
|
|
|
case MA_RAMP_SUB:
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[0] -= fac * col[0];
|
|
|
|
r_col[1] -= fac * col[1];
|
|
|
|
r_col[2] -= fac * col[2];
|
2011-11-26 22:42:04 +01:00
|
|
|
break;
|
Giant commit!
A full detailed description of this will be done later... is several days
of work. Here's a summary:
Render:
- Full cleanup of render code, removing *all* globals and bad level calls
all over blender. Render module is now not called abusive anymore
- API-fied calls to rendering
- Full recode of internal render pipeline. Is now rendering tiles by
default, prepared for much smarter 'bucket' render later.
- Each thread now can render a full part
- Renders were tested with 4 threads, goes fine, apart from some lookup
tables in softshadow and AO still
- Rendering is prepared to do multiple layers and passes
- No single 32 bits trick in render code anymore, all 100% floats now.
Writing images/movies
- moved writing images to blender kernel (bye bye 'schrijfplaatje'!)
- made a new Movie handle system, also in kernel. This will enable much
easier use of movies in Blender
PreviewRender:
- Using new render API, previewrender (in buttons) now uses regular render
code to generate images.
- new datafile 'preview.blend.c' has the preview scenes in it
- previews get rendered in exact displayed size (1 pixel = 1 pixel)
3D Preview render
- new; press Pkey in 3d window, for a panel that continuously renders
(pkey is for games, i know... but we dont do that in orange now!)
- this render works nearly identical to buttons-preview render, so it stops
rendering on any event (mouse, keyboard, etc)
- on moving/scaling the panel, the render code doesn't recreate all geometry
- same for shifting/panning view
- all other operations (now) regenerate the full render database still.
- this is WIP... but big fun, especially for simple scenes!
Compositor
- Using same node system as now in use for shaders, you can composit images
- works pretty straightforward... needs much more options/tools and integration
with rendering still
- is not threaded yet, nor is so smart to only recalculate changes... will be
done soon!
- the "Render Result" node will get all layers/passes as output sockets
- The "Output" node renders to a builtin image, which you can view in the Image
window. (yes, output nodes to render-result, and to files, is on the list!)
The Bad News
- "Unified Render" is removed. It might come back in some stage, but this
system should be built from scratch. I can't really understand this code...
I expect it is not much needed, especially with advanced layer/passes
control
- Panorama render, Field render, Motion blur, is not coded yet... (I had to
recode every single feature in render, so...!)
- Lens Flare is also not back... needs total revision, might become composit
effect though (using zbuffer for visibility)
- Part render is gone! (well, thats obvious, its default now).
- The render window is only restored with limited functionality... I am going
to check first the option to render to a Image window, so Blender can become
a true single-window application. :)
For example, the 'Spare render buffer' (jkey) doesnt work.
- Render with border, now default creates a smaller image
- No zbuffers are written yet... on the todo!
- Scons files and MSVC will need work to get compiling again
OK... thats what I can quickly recall. Now go compiling!
2006-01-23 23:05:47 +01:00
|
|
|
case MA_RAMP_DIV:
|
2019-04-22 01:39:35 +02:00
|
|
|
if (col[0] != 0.0f) {
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[0] = facm * (r_col[0]) + fac * (r_col[0]) / col[0];
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
if (col[1] != 0.0f) {
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[1] = facm * (r_col[1]) + fac * (r_col[1]) / col[1];
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
if (col[2] != 0.0f) {
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[2] = facm * (r_col[2]) + fac * (r_col[2]) / col[2];
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2011-11-26 22:42:04 +01:00
|
|
|
break;
|
Giant commit!
A full detailed description of this will be done later... is several days
of work. Here's a summary:
Render:
- Full cleanup of render code, removing *all* globals and bad level calls
all over blender. Render module is now not called abusive anymore
- API-fied calls to rendering
- Full recode of internal render pipeline. Is now rendering tiles by
default, prepared for much smarter 'bucket' render later.
- Each thread now can render a full part
- Renders were tested with 4 threads, goes fine, apart from some lookup
tables in softshadow and AO still
- Rendering is prepared to do multiple layers and passes
- No single 32 bits trick in render code anymore, all 100% floats now.
Writing images/movies
- moved writing images to blender kernel (bye bye 'schrijfplaatje'!)
- made a new Movie handle system, also in kernel. This will enable much
easier use of movies in Blender
PreviewRender:
- Using new render API, previewrender (in buttons) now uses regular render
code to generate images.
- new datafile 'preview.blend.c' has the preview scenes in it
- previews get rendered in exact displayed size (1 pixel = 1 pixel)
3D Preview render
- new; press Pkey in 3d window, for a panel that continuously renders
(pkey is for games, i know... but we dont do that in orange now!)
- this render works nearly identical to buttons-preview render, so it stops
rendering on any event (mouse, keyboard, etc)
- on moving/scaling the panel, the render code doesn't recreate all geometry
- same for shifting/panning view
- all other operations (now) regenerate the full render database still.
- this is WIP... but big fun, especially for simple scenes!
Compositor
- Using same node system as now in use for shaders, you can composit images
- works pretty straightforward... needs much more options/tools and integration
with rendering still
- is not threaded yet, nor is so smart to only recalculate changes... will be
done soon!
- the "Render Result" node will get all layers/passes as output sockets
- The "Output" node renders to a builtin image, which you can view in the Image
window. (yes, output nodes to render-result, and to files, is on the list!)
The Bad News
- "Unified Render" is removed. It might come back in some stage, but this
system should be built from scratch. I can't really understand this code...
I expect it is not much needed, especially with advanced layer/passes
control
- Panorama render, Field render, Motion blur, is not coded yet... (I had to
recode every single feature in render, so...!)
- Lens Flare is also not back... needs total revision, might become composit
effect though (using zbuffer for visibility)
- Part render is gone! (well, thats obvious, its default now).
- The render window is only restored with limited functionality... I am going
to check first the option to render to a Image window, so Blender can become
a true single-window application. :)
For example, the 'Spare render buffer' (jkey) doesnt work.
- Render with border, now default creates a smaller image
- No zbuffers are written yet... on the todo!
- Scons files and MSVC will need work to get compiling again
OK... thats what I can quickly recall. Now go compiling!
2006-01-23 23:05:47 +01:00
|
|
|
case MA_RAMP_DIFF:
|
2012-09-30 08:12:47 +02:00
|
|
|
r_col[0] = facm * (r_col[0]) + fac * fabsf(r_col[0] - col[0]);
|
|
|
|
r_col[1] = facm * (r_col[1]) + fac * fabsf(r_col[1] - col[1]);
|
|
|
|
r_col[2] = facm * (r_col[2]) + fac * fabsf(r_col[2] - col[2]);
|
2011-11-26 22:42:04 +01:00
|
|
|
break;
|
2022-11-18 13:52:14 +01:00
|
|
|
case MA_RAMP_EXCLUSION:
|
|
|
|
r_col[0] = max_ff(facm * (r_col[0]) + fac * (r_col[0] + col[0] - 2.0f * r_col[0] * col[0]),
|
|
|
|
0.0f);
|
|
|
|
r_col[1] = max_ff(facm * (r_col[1]) + fac * (r_col[1] + col[1] - 2.0f * r_col[1] * col[1]),
|
|
|
|
0.0f);
|
|
|
|
r_col[2] = max_ff(facm * (r_col[2]) + fac * (r_col[2] + col[2] - 2.0f * r_col[2] * col[2]),
|
|
|
|
0.0f);
|
|
|
|
break;
|
Giant commit!
A full detailed description of this will be done later... is several days
of work. Here's a summary:
Render:
- Full cleanup of render code, removing *all* globals and bad level calls
all over blender. Render module is now not called abusive anymore
- API-fied calls to rendering
- Full recode of internal render pipeline. Is now rendering tiles by
default, prepared for much smarter 'bucket' render later.
- Each thread now can render a full part
- Renders were tested with 4 threads, goes fine, apart from some lookup
tables in softshadow and AO still
- Rendering is prepared to do multiple layers and passes
- No single 32 bits trick in render code anymore, all 100% floats now.
Writing images/movies
- moved writing images to blender kernel (bye bye 'schrijfplaatje'!)
- made a new Movie handle system, also in kernel. This will enable much
easier use of movies in Blender
PreviewRender:
- Using new render API, previewrender (in buttons) now uses regular render
code to generate images.
- new datafile 'preview.blend.c' has the preview scenes in it
- previews get rendered in exact displayed size (1 pixel = 1 pixel)
3D Preview render
- new; press Pkey in 3d window, for a panel that continuously renders
(pkey is for games, i know... but we dont do that in orange now!)
- this render works nearly identical to buttons-preview render, so it stops
rendering on any event (mouse, keyboard, etc)
- on moving/scaling the panel, the render code doesn't recreate all geometry
- same for shifting/panning view
- all other operations (now) regenerate the full render database still.
- this is WIP... but big fun, especially for simple scenes!
Compositor
- Using same node system as now in use for shaders, you can composit images
- works pretty straightforward... needs much more options/tools and integration
with rendering still
- is not threaded yet, nor is so smart to only recalculate changes... will be
done soon!
- the "Render Result" node will get all layers/passes as output sockets
- The "Output" node renders to a builtin image, which you can view in the Image
window. (yes, output nodes to render-result, and to files, is on the list!)
The Bad News
- "Unified Render" is removed. It might come back in some stage, but this
system should be built from scratch. I can't really understand this code...
I expect it is not much needed, especially with advanced layer/passes
control
- Panorama render, Field render, Motion blur, is not coded yet... (I had to
recode every single feature in render, so...!)
- Lens Flare is also not back... needs total revision, might become composit
effect though (using zbuffer for visibility)
- Part render is gone! (well, thats obvious, its default now).
- The render window is only restored with limited functionality... I am going
to check first the option to render to a Image window, so Blender can become
a true single-window application. :)
For example, the 'Spare render buffer' (jkey) doesnt work.
- Render with border, now default creates a smaller image
- No zbuffers are written yet... on the todo!
- Scons files and MSVC will need work to get compiling again
OK... thats what I can quickly recall. Now go compiling!
2006-01-23 23:05:47 +01:00
|
|
|
case MA_RAMP_DARK:
|
2014-04-28 17:38:34 +02:00
|
|
|
r_col[0] = min_ff(r_col[0], col[0]) * fac + r_col[0] * facm;
|
|
|
|
r_col[1] = min_ff(r_col[1], col[1]) * fac + r_col[1] * facm;
|
|
|
|
r_col[2] = min_ff(r_col[2], col[2]) * fac + r_col[2] * facm;
|
2011-11-26 22:42:04 +01:00
|
|
|
break;
|
Giant commit!
A full detailed description of this will be done later... is several days
of work. Here's a summary:
Render:
- Full cleanup of render code, removing *all* globals and bad level calls
all over blender. Render module is now not called abusive anymore
- API-fied calls to rendering
- Full recode of internal render pipeline. Is now rendering tiles by
default, prepared for much smarter 'bucket' render later.
- Each thread now can render a full part
- Renders were tested with 4 threads, goes fine, apart from some lookup
tables in softshadow and AO still
- Rendering is prepared to do multiple layers and passes
- No single 32 bits trick in render code anymore, all 100% floats now.
Writing images/movies
- moved writing images to blender kernel (bye bye 'schrijfplaatje'!)
- made a new Movie handle system, also in kernel. This will enable much
easier use of movies in Blender
PreviewRender:
- Using new render API, previewrender (in buttons) now uses regular render
code to generate images.
- new datafile 'preview.blend.c' has the preview scenes in it
- previews get rendered in exact displayed size (1 pixel = 1 pixel)
3D Preview render
- new; press Pkey in 3d window, for a panel that continuously renders
(pkey is for games, i know... but we dont do that in orange now!)
- this render works nearly identical to buttons-preview render, so it stops
rendering on any event (mouse, keyboard, etc)
- on moving/scaling the panel, the render code doesn't recreate all geometry
- same for shifting/panning view
- all other operations (now) regenerate the full render database still.
- this is WIP... but big fun, especially for simple scenes!
Compositor
- Using same node system as now in use for shaders, you can composit images
- works pretty straightforward... needs much more options/tools and integration
with rendering still
- is not threaded yet, nor is so smart to only recalculate changes... will be
done soon!
- the "Render Result" node will get all layers/passes as output sockets
- The "Output" node renders to a builtin image, which you can view in the Image
window. (yes, output nodes to render-result, and to files, is on the list!)
The Bad News
- "Unified Render" is removed. It might come back in some stage, but this
system should be built from scratch. I can't really understand this code...
I expect it is not much needed, especially with advanced layer/passes
control
- Panorama render, Field render, Motion blur, is not coded yet... (I had to
recode every single feature in render, so...!)
- Lens Flare is also not back... needs total revision, might become composit
effect though (using zbuffer for visibility)
- Part render is gone! (well, thats obvious, its default now).
- The render window is only restored with limited functionality... I am going
to check first the option to render to a Image window, so Blender can become
a true single-window application. :)
For example, the 'Spare render buffer' (jkey) doesnt work.
- Render with border, now default creates a smaller image
- No zbuffers are written yet... on the todo!
- Scons files and MSVC will need work to get compiling again
OK... thats what I can quickly recall. Now go compiling!
2006-01-23 23:05:47 +01:00
|
|
|
case MA_RAMP_LIGHT:
|
2012-05-06 17:15:33 +02:00
|
|
|
tmp = fac * col[0];
|
2019-04-22 01:39:35 +02:00
|
|
|
if (tmp > r_col[0]) {
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[0] = tmp;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2012-05-06 17:15:33 +02:00
|
|
|
tmp = fac * col[1];
|
2019-04-22 01:39:35 +02:00
|
|
|
if (tmp > r_col[1]) {
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[1] = tmp;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2012-05-06 17:15:33 +02:00
|
|
|
tmp = fac * col[2];
|
2019-04-22 01:39:35 +02:00
|
|
|
if (tmp > r_col[2]) {
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[2] = tmp;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2012-05-06 17:15:33 +02:00
|
|
|
break;
|
2011-11-26 22:42:04 +01:00
|
|
|
case MA_RAMP_DODGE:
|
2012-02-23 03:17:50 +01:00
|
|
|
if (r_col[0] != 0.0f) {
|
2012-05-06 17:15:33 +02:00
|
|
|
tmp = 1.0f - fac * col[0];
|
2019-04-22 01:39:35 +02:00
|
|
|
if (tmp <= 0.0f) {
|
2011-11-26 14:11:55 +01:00
|
|
|
r_col[0] = 1.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else if ((tmp = (r_col[0]) / tmp) > 1.0f) {
|
2011-11-26 14:11:55 +01:00
|
|
|
r_col[0] = 1.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2011-11-26 14:11:55 +01:00
|
|
|
r_col[0] = tmp;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2006-06-05 11:55:39 +02:00
|
|
|
}
|
2012-02-23 03:17:50 +01:00
|
|
|
if (r_col[1] != 0.0f) {
|
2012-05-06 17:15:33 +02:00
|
|
|
tmp = 1.0f - fac * col[1];
|
2019-04-22 01:39:35 +02:00
|
|
|
if (tmp <= 0.0f) {
|
2011-11-26 22:42:04 +01:00
|
|
|
r_col[1] = 1.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else if ((tmp = (r_col[1]) / tmp) > 1.0f) {
|
2011-11-26 22:42:04 +01:00
|
|
|
r_col[1] = 1.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2011-11-26 22:42:04 +01:00
|
|
|
r_col[1] = tmp;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2006-06-03 15:26:39 +02:00
|
|
|
}
|
2012-02-23 03:17:50 +01:00
|
|
|
if (r_col[2] != 0.0f) {
|
2012-05-06 17:15:33 +02:00
|
|
|
tmp = 1.0f - fac * col[2];
|
2019-04-22 01:39:35 +02:00
|
|
|
if (tmp <= 0.0f) {
|
2011-11-26 22:42:04 +01:00
|
|
|
r_col[2] = 1.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else if ((tmp = (r_col[2]) / tmp) > 1.0f) {
|
2011-11-26 22:42:04 +01:00
|
|
|
r_col[2] = 1.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2011-11-26 22:42:04 +01:00
|
|
|
r_col[2] = tmp;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2011-11-26 22:42:04 +01:00
|
|
|
}
|
|
|
|
break;
|
2006-06-03 15:26:39 +02:00
|
|
|
case MA_RAMP_BURN:
|
2012-05-06 17:15:33 +02:00
|
|
|
tmp = facm + fac * col[0];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 01:39:35 +02:00
|
|
|
if (tmp <= 0.0f) {
|
2011-11-26 14:11:55 +01:00
|
|
|
r_col[0] = 0.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else if ((tmp = (1.0f - (1.0f - (r_col[0])) / tmp)) < 0.0f) {
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[0] = 0.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else if (tmp > 1.0f) {
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[0] = 1.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2011-11-26 14:11:55 +01:00
|
|
|
r_col[0] = tmp;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 17:15:33 +02:00
|
|
|
tmp = facm + fac * col[1];
|
2019-04-22 01:39:35 +02:00
|
|
|
if (tmp <= 0.0f) {
|
2011-11-26 22:42:04 +01:00
|
|
|
r_col[1] = 0.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else if ((tmp = (1.0f - (1.0f - (r_col[1])) / tmp)) < 0.0f) {
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[1] = 0.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else if (tmp > 1.0f) {
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[1] = 1.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2011-11-26 22:42:04 +01:00
|
|
|
r_col[1] = tmp;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 17:15:33 +02:00
|
|
|
tmp = facm + fac * col[2];
|
2019-04-22 01:39:35 +02:00
|
|
|
if (tmp <= 0.0f) {
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[2] = 0.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else if ((tmp = (1.0f - (1.0f - (r_col[2])) / tmp)) < 0.0f) {
|
2011-11-26 22:42:04 +01:00
|
|
|
r_col[2] = 0.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else if (tmp > 1.0f) {
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[2] = 1.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2011-11-26 22:42:04 +01:00
|
|
|
r_col[2] = tmp;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2011-11-26 22:42:04 +01:00
|
|
|
break;
|
|
|
|
case MA_RAMP_HUE: {
|
2012-05-06 17:15:33 +02:00
|
|
|
float rH, rS, rV;
|
|
|
|
float colH, colS, colV;
|
|
|
|
float tmpr, tmpg, tmpb;
|
|
|
|
rgb_to_hsv(col[0], col[1], col[2], &colH, &colS, &colV);
|
|
|
|
if (colS != 0) {
|
2012-04-29 17:47:02 +02:00
|
|
|
rgb_to_hsv(r_col[0], r_col[1], r_col[2], &rH, &rS, &rV);
|
2012-05-06 17:15:33 +02:00
|
|
|
hsv_to_rgb(colH, rS, rV, &tmpr, &tmpg, &tmpb);
|
|
|
|
r_col[0] = facm * (r_col[0]) + fac * tmpr;
|
|
|
|
r_col[1] = facm * (r_col[1]) + fac * tmpg;
|
|
|
|
r_col[2] = facm * (r_col[2]) + fac * tmpb;
|
2006-06-03 15:26:39 +02:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2012-05-06 17:15:33 +02:00
|
|
|
}
|
|
|
|
case MA_RAMP_SAT: {
|
|
|
|
float rH, rS, rV;
|
|
|
|
float colH, colS, colV;
|
|
|
|
rgb_to_hsv(r_col[0], r_col[1], r_col[2], &rH, &rS, &rV);
|
|
|
|
if (rS != 0) {
|
2012-04-29 17:47:02 +02:00
|
|
|
rgb_to_hsv(col[0], col[1], col[2], &colH, &colS, &colV);
|
2012-05-06 17:15:33 +02:00
|
|
|
hsv_to_rgb(rH, (facm * rS + fac * colS), rV, r_col + 0, r_col + 1, r_col + 2);
|
2006-06-03 15:26:39 +02:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2012-05-06 17:15:33 +02:00
|
|
|
}
|
|
|
|
case MA_RAMP_VAL: {
|
|
|
|
float rH, rS, rV;
|
|
|
|
float colH, colS, colV;
|
|
|
|
rgb_to_hsv(r_col[0], r_col[1], r_col[2], &rH, &rS, &rV);
|
|
|
|
rgb_to_hsv(col[0], col[1], col[2], &colH, &colS, &colV);
|
|
|
|
hsv_to_rgb(rH, rS, (facm * rV + fac * colV), r_col + 0, r_col + 1, r_col + 2);
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2012-05-06 17:15:33 +02:00
|
|
|
}
|
2011-11-26 22:42:04 +01:00
|
|
|
case MA_RAMP_COLOR: {
|
2012-05-06 17:15:33 +02:00
|
|
|
float rH, rS, rV;
|
|
|
|
float colH, colS, colV;
|
|
|
|
float tmpr, tmpg, tmpb;
|
|
|
|
rgb_to_hsv(col[0], col[1], col[2], &colH, &colS, &colV);
|
|
|
|
if (colS != 0) {
|
|
|
|
rgb_to_hsv(r_col[0], r_col[1], r_col[2], &rH, &rS, &rV);
|
|
|
|
hsv_to_rgb(colH, colS, rV, &tmpr, &tmpg, &tmpb);
|
|
|
|
r_col[0] = facm * (r_col[0]) + fac * tmpr;
|
|
|
|
r_col[1] = facm * (r_col[1]) + fac * tmpg;
|
|
|
|
r_col[2] = facm * (r_col[2]) + fac * tmpb;
|
2006-06-03 15:26:39 +02:00
|
|
|
}
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2012-05-06 17:15:33 +02:00
|
|
|
}
|
2011-11-26 22:42:04 +01:00
|
|
|
case MA_RAMP_SOFT: {
|
2012-05-06 17:15:33 +02:00
|
|
|
float scr, scg, scb;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 17:15:33 +02:00
|
|
|
/* first calculate non-fac based Screen mix */
|
|
|
|
scr = 1.0f - (1.0f - col[0]) * (1.0f - r_col[0]);
|
|
|
|
scg = 1.0f - (1.0f - col[1]) * (1.0f - r_col[1]);
|
|
|
|
scb = 1.0f - (1.0f - col[2]) * (1.0f - r_col[2]);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[0] = facm * (r_col[0]) +
|
|
|
|
fac * (((1.0f - r_col[0]) * col[0] * (r_col[0])) + (r_col[0] * scr));
|
|
|
|
r_col[1] = facm * (r_col[1]) +
|
|
|
|
fac * (((1.0f - r_col[1]) * col[1] * (r_col[1])) + (r_col[1] * scg));
|
|
|
|
r_col[2] = facm * (r_col[2]) +
|
|
|
|
fac * (((1.0f - r_col[2]) * col[2] * (r_col[2])) + (r_col[2] * scb));
|
2013-07-19 17:23:42 +02:00
|
|
|
break;
|
2012-05-06 17:15:33 +02:00
|
|
|
}
|
2011-11-26 22:42:04 +01:00
|
|
|
case MA_RAMP_LINEAR:
|
2019-04-22 01:39:35 +02:00
|
|
|
if (col[0] > 0.5f) {
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[0] = r_col[0] + fac * (2.0f * (col[0] - 0.5f));
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[0] = r_col[0] + fac * (2.0f * (col[0]) - 1.0f);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
if (col[1] > 0.5f) {
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[1] = r_col[1] + fac * (2.0f * (col[1] - 0.5f));
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[1] = r_col[1] + fac * (2.0f * (col[1]) - 1.0f);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
if (col[2] > 0.5f) {
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[2] = r_col[2] + fac * (2.0f * (col[2] - 0.5f));
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-05-06 17:15:33 +02:00
|
|
|
r_col[2] = r_col[2] + fac * (2.0f * (col[2]) - 1.0f);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2011-11-26 22:42:04 +01:00
|
|
|
break;
|
|
|
|
}
|
Giant commit!
A full detailed description of this will be done later... is several days
of work. Here's a summary:
Render:
- Full cleanup of render code, removing *all* globals and bad level calls
all over blender. Render module is now not called abusive anymore
- API-fied calls to rendering
- Full recode of internal render pipeline. Is now rendering tiles by
default, prepared for much smarter 'bucket' render later.
- Each thread now can render a full part
- Renders were tested with 4 threads, goes fine, apart from some lookup
tables in softshadow and AO still
- Rendering is prepared to do multiple layers and passes
- No single 32 bits trick in render code anymore, all 100% floats now.
Writing images/movies
- moved writing images to blender kernel (bye bye 'schrijfplaatje'!)
- made a new Movie handle system, also in kernel. This will enable much
easier use of movies in Blender
PreviewRender:
- Using new render API, previewrender (in buttons) now uses regular render
code to generate images.
- new datafile 'preview.blend.c' has the preview scenes in it
- previews get rendered in exact displayed size (1 pixel = 1 pixel)
3D Preview render
- new; press Pkey in 3d window, for a panel that continuously renders
(pkey is for games, i know... but we dont do that in orange now!)
- this render works nearly identical to buttons-preview render, so it stops
rendering on any event (mouse, keyboard, etc)
- on moving/scaling the panel, the render code doesn't recreate all geometry
- same for shifting/panning view
- all other operations (now) regenerate the full render database still.
- this is WIP... but big fun, especially for simple scenes!
Compositor
- Using same node system as now in use for shaders, you can composit images
- works pretty straightforward... needs much more options/tools and integration
with rendering still
- is not threaded yet, nor is so smart to only recalculate changes... will be
done soon!
- the "Render Result" node will get all layers/passes as output sockets
- The "Output" node renders to a builtin image, which you can view in the Image
window. (yes, output nodes to render-result, and to files, is on the list!)
The Bad News
- "Unified Render" is removed. It might come back in some stage, but this
system should be built from scratch. I can't really understand this code...
I expect it is not much needed, especially with advanced layer/passes
control
- Panorama render, Field render, Motion blur, is not coded yet... (I had to
recode every single feature in render, so...!)
- Lens Flare is also not back... needs total revision, might become composit
effect though (using zbuffer for visibility)
- Part render is gone! (well, thats obvious, its default now).
- The render window is only restored with limited functionality... I am going
to check first the option to render to a Image window, so Blender can become
a true single-window application. :)
For example, the 'Spare render buffer' (jkey) doesnt work.
- Render with border, now default creates a smaller image
- No zbuffers are written yet... on the todo!
- Scons files and MSVC will need work to get compiling again
OK... thats what I can quickly recall. Now go compiling!
2006-01-23 23:05:47 +01:00
|
|
|
}
|
|
|
|
|
2023-06-03 00:36:28 +02:00
|
|
|
void BKE_material_eval(Depsgraph *depsgraph, Material *material)
|
2017-07-20 16:13:08 +02:00
|
|
|
{
|
2018-05-02 11:46:56 +02:00
|
|
|
DEG_debug_print_eval(depsgraph, __func__, material->id.name, material);
|
2018-06-08 16:11:34 +02:00
|
|
|
GPU_material_free(&material->gpumaterial);
|
2017-07-20 16:13:08 +02:00
|
|
|
}
|
2020-02-06 13:05:45 +01:00
|
|
|
|
|
|
|
/* Default Materials
|
|
|
|
*
|
|
|
|
* Used for rendering when objects have no materials assigned, and initializing
|
|
|
|
* default shader nodes. */
|
|
|
|
|
|
|
|
static Material default_material_empty;
|
2020-04-23 17:40:22 +02:00
|
|
|
static Material default_material_holdout;
|
2020-02-06 13:05:45 +01:00
|
|
|
static Material default_material_surface;
|
|
|
|
static Material default_material_volume;
|
|
|
|
static Material default_material_gpencil;
|
|
|
|
|
|
|
|
static Material *default_materials[] = {&default_material_empty,
|
2020-04-23 17:40:22 +02:00
|
|
|
&default_material_holdout,
|
2020-02-06 13:05:45 +01:00
|
|
|
&default_material_surface,
|
|
|
|
&default_material_volume,
|
|
|
|
&default_material_gpencil,
|
2022-11-18 11:08:39 +01:00
|
|
|
nullptr};
|
2020-02-06 13:05:45 +01:00
|
|
|
|
|
|
|
static void material_default_gpencil_init(Material *ma)
|
|
|
|
{
|
2023-05-19 06:58:38 +02:00
|
|
|
BLI_strncpy(ma->id.name + 2, "Default GPencil", MAX_NAME);
|
2020-02-06 13:05:45 +01:00
|
|
|
BKE_gpencil_material_attr_init(ma);
|
|
|
|
add_v3_fl(&ma->gp_style->stroke_rgba[0], 0.6f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void material_default_surface_init(Material *ma)
|
|
|
|
{
|
2023-05-19 06:58:38 +02:00
|
|
|
BLI_strncpy(ma->id.name + 2, "Default Surface", MAX_NAME);
|
2022-04-19 09:57:45 +02:00
|
|
|
|
2023-05-15 15:14:22 +02:00
|
|
|
bNodeTree *ntree = blender::bke::ntreeAddTreeEmbedded(
|
2022-11-18 11:08:39 +01:00
|
|
|
nullptr, &ma->id, "Shader Nodetree", ntreeType_Shader->idname);
|
2020-02-27 14:56:01 +01:00
|
|
|
ma->use_nodes = true;
|
2020-02-06 13:05:45 +01:00
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
bNode *principled = nodeAddStaticNode(nullptr, ntree, SH_NODE_BSDF_PRINCIPLED);
|
2020-02-06 13:05:45 +01:00
|
|
|
bNodeSocket *base_color = nodeFindSocket(principled, SOCK_IN, "Base Color");
|
|
|
|
copy_v3_v3(((bNodeSocketValueRGBA *)base_color->default_value)->value, &ma->r);
|
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
bNode *output = nodeAddStaticNode(nullptr, ntree, SH_NODE_OUTPUT_MATERIAL);
|
2020-02-06 13:05:45 +01:00
|
|
|
|
|
|
|
nodeAddLink(ntree,
|
|
|
|
principled,
|
|
|
|
nodeFindSocket(principled, SOCK_OUT, "BSDF"),
|
|
|
|
output,
|
|
|
|
nodeFindSocket(output, SOCK_IN, "Surface"));
|
|
|
|
|
|
|
|
principled->locx = 10.0f;
|
|
|
|
principled->locy = 300.0f;
|
|
|
|
output->locx = 300.0f;
|
|
|
|
output->locy = 300.0f;
|
|
|
|
|
|
|
|
nodeSetActive(ntree, output);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void material_default_volume_init(Material *ma)
|
|
|
|
{
|
2023-05-19 06:58:38 +02:00
|
|
|
BLI_strncpy(ma->id.name + 2, "Default Volume", MAX_NAME);
|
2022-04-19 09:57:45 +02:00
|
|
|
|
2023-05-15 15:14:22 +02:00
|
|
|
bNodeTree *ntree = blender::bke::ntreeAddTreeEmbedded(
|
2022-11-18 11:08:39 +01:00
|
|
|
nullptr, &ma->id, "Shader Nodetree", ntreeType_Shader->idname);
|
2020-02-27 14:56:01 +01:00
|
|
|
ma->use_nodes = true;
|
2020-02-06 13:05:45 +01:00
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
bNode *principled = nodeAddStaticNode(nullptr, ntree, SH_NODE_VOLUME_PRINCIPLED);
|
|
|
|
bNode *output = nodeAddStaticNode(nullptr, ntree, SH_NODE_OUTPUT_MATERIAL);
|
2020-02-06 13:05:45 +01:00
|
|
|
|
|
|
|
nodeAddLink(ntree,
|
|
|
|
principled,
|
|
|
|
nodeFindSocket(principled, SOCK_OUT, "Volume"),
|
|
|
|
output,
|
|
|
|
nodeFindSocket(output, SOCK_IN, "Volume"));
|
|
|
|
|
|
|
|
principled->locx = 10.0f;
|
|
|
|
principled->locy = 300.0f;
|
|
|
|
output->locx = 300.0f;
|
|
|
|
output->locy = 300.0f;
|
|
|
|
|
|
|
|
nodeSetActive(ntree, output);
|
|
|
|
}
|
|
|
|
|
2020-08-05 22:29:21 +02:00
|
|
|
static void material_default_holdout_init(Material *ma)
|
|
|
|
{
|
2023-05-19 06:58:38 +02:00
|
|
|
BLI_strncpy(ma->id.name + 2, "Default Holdout", MAX_NAME);
|
2022-04-19 09:57:45 +02:00
|
|
|
|
2023-05-15 15:14:22 +02:00
|
|
|
bNodeTree *ntree = blender::bke::ntreeAddTreeEmbedded(
|
2022-11-18 11:08:39 +01:00
|
|
|
nullptr, &ma->id, "Shader Nodetree", ntreeType_Shader->idname);
|
2020-08-05 22:29:21 +02:00
|
|
|
ma->use_nodes = true;
|
|
|
|
|
2022-11-18 11:08:39 +01:00
|
|
|
bNode *holdout = nodeAddStaticNode(nullptr, ntree, SH_NODE_HOLDOUT);
|
|
|
|
bNode *output = nodeAddStaticNode(nullptr, ntree, SH_NODE_OUTPUT_MATERIAL);
|
2020-08-05 22:29:21 +02:00
|
|
|
|
|
|
|
nodeAddLink(ntree,
|
|
|
|
holdout,
|
|
|
|
nodeFindSocket(holdout, SOCK_OUT, "Holdout"),
|
|
|
|
output,
|
|
|
|
nodeFindSocket(output, SOCK_IN, "Surface"));
|
|
|
|
|
|
|
|
holdout->locx = 10.0f;
|
|
|
|
holdout->locy = 300.0f;
|
|
|
|
output->locx = 300.0f;
|
|
|
|
output->locy = 300.0f;
|
|
|
|
|
|
|
|
nodeSetActive(ntree, output);
|
|
|
|
}
|
|
|
|
|
2023-07-02 11:37:22 +02:00
|
|
|
Material *BKE_material_default_empty()
|
2020-02-06 13:05:45 +01:00
|
|
|
{
|
|
|
|
return &default_material_empty;
|
|
|
|
}
|
|
|
|
|
2023-07-02 11:37:22 +02:00
|
|
|
Material *BKE_material_default_holdout()
|
2020-04-23 17:40:22 +02:00
|
|
|
{
|
|
|
|
return &default_material_holdout;
|
|
|
|
}
|
|
|
|
|
2023-07-02 11:37:22 +02:00
|
|
|
Material *BKE_material_default_surface()
|
2020-02-06 13:05:45 +01:00
|
|
|
{
|
|
|
|
return &default_material_surface;
|
|
|
|
}
|
|
|
|
|
2023-07-02 11:37:22 +02:00
|
|
|
Material *BKE_material_default_volume()
|
2020-02-06 13:05:45 +01:00
|
|
|
{
|
|
|
|
return &default_material_volume;
|
|
|
|
}
|
|
|
|
|
2023-07-02 11:37:22 +02:00
|
|
|
Material *BKE_material_default_gpencil()
|
2020-02-06 13:05:45 +01:00
|
|
|
{
|
|
|
|
return &default_material_gpencil;
|
|
|
|
}
|
|
|
|
|
2023-07-02 11:37:22 +02:00
|
|
|
void BKE_material_defaults_free_gpu()
|
2020-02-06 13:05:45 +01:00
|
|
|
{
|
|
|
|
for (int i = 0; default_materials[i]; i++) {
|
|
|
|
Material *ma = default_materials[i];
|
|
|
|
if (ma->gpumaterial.first) {
|
|
|
|
GPU_material_free(&ma->gpumaterial);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Module functions called on startup and exit. */
|
|
|
|
|
2023-07-02 11:37:22 +02:00
|
|
|
void BKE_materials_init()
|
2020-02-06 13:05:45 +01:00
|
|
|
{
|
|
|
|
for (int i = 0; default_materials[i]; i++) {
|
2020-03-06 16:38:04 +01:00
|
|
|
material_init_data(&default_materials[i]->id);
|
2020-02-06 13:05:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
material_default_surface_init(&default_material_surface);
|
|
|
|
material_default_volume_init(&default_material_volume);
|
2020-08-05 22:29:21 +02:00
|
|
|
material_default_holdout_init(&default_material_holdout);
|
2020-02-06 13:05:45 +01:00
|
|
|
material_default_gpencil_init(&default_material_gpencil);
|
|
|
|
}
|
|
|
|
|
2023-07-02 11:37:22 +02:00
|
|
|
void BKE_materials_exit()
|
2020-02-06 13:05:45 +01:00
|
|
|
{
|
|
|
|
for (int i = 0; default_materials[i]; i++) {
|
2020-03-06 16:38:04 +01:00
|
|
|
material_free_data(&default_materials[i]->id);
|
2020-02-06 13:05:45 +01:00
|
|
|
}
|
|
|
|
}
|