2011-10-10 11:38:02 +02:00
|
|
|
/*
|
2002-10-12 13:37:38 +02:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-01-07 20:13:47 +01:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 13:37:38 +02:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 14:34:04 +01:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 13:37:38 +02:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2019-02-17 22:08:12 +01:00
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
2011-02-27 21:40:57 +01:00
|
|
|
*/
|
|
|
|
|
2002-10-12 13:37:38 +02:00
|
|
|
#include <string.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
|
|
|
#include <math.h>
|
2011-09-20 06:38:59 +02:00
|
|
|
#include <stddef.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
|
|
|
|
2019-02-01 02:44:19 +01:00
|
|
|
#include "CLG_log.h"
|
|
|
|
|
2002-10-12 13:37:38 +02:00
|
|
|
#include "MEM_guardedalloc.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"
|
2002-10-12 13:37:38 +02:00
|
|
|
#include "DNA_material_types.h"
|
|
|
|
#include "DNA_mesh_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_meshdata_types.h"
|
|
|
|
#include "DNA_customdata_types.h"
|
2018-07-31 10:22:19 +02:00
|
|
|
#include "DNA_gpencil_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_ID.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"
|
2002-10-12 13:37:38 +02:00
|
|
|
#include "DNA_scene_types.h"
|
2019-09-09 19:16:18 +02:00
|
|
|
#include "DNA_defaults.h"
|
2002-10-12 13:37:38 +02:00
|
|
|
|
2018-06-17 17:05:51 +02:00
|
|
|
#include "BLI_math.h"
|
|
|
|
#include "BLI_listbase.h"
|
2011-01-07 19:36:47 +01:00
|
|
|
#include "BLI_utildefines.h"
|
2015-04-27 23:24:56 +02:00
|
|
|
#include "BLI_array_utils.h"
|
2002-10-12 13:37:38 +02:00
|
|
|
|
2009-01-18 11:41:45 +01:00
|
|
|
#include "BKE_animsys.h"
|
2018-10-26 09:02:28 +02:00
|
|
|
#include "BKE_brush.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_displist.h"
|
2018-07-31 10:22:19 +02:00
|
|
|
#include "BKE_gpencil.h"
|
2005-12-21 23:21:43 +01:00
|
|
|
#include "BKE_icons.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"
|
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"
|
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_mesh.h"
|
2014-08-27 15:52:24 +02:00
|
|
|
#include "BKE_scene.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 "BKE_node.h"
|
2011-07-31 13:12:38 +02:00
|
|
|
#include "BKE_curve.h"
|
2015-04-27 23:24:56 +02:00
|
|
|
#include "BKE_editmesh.h"
|
|
|
|
#include "BKE_font.h"
|
2002-10-12 13:37:38 +02:00
|
|
|
|
2018-03-16 11:17:45 +01:00
|
|
|
#include "DEG_depsgraph.h"
|
2017-04-06 16:11:50 +02:00
|
|
|
#include "DEG_depsgraph_build.h"
|
|
|
|
|
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
|
|
|
|
2019-02-01 02:44:19 +01:00
|
|
|
static CLG_LogRef LOG = {"bke.material"};
|
|
|
|
|
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
|
|
|
/** Free (or release) any data used by this material (does not free the material itself). */
|
2012-05-05 16:03:12 +02:00
|
|
|
void BKE_material_free(Material *ma)
|
2012-08-22 19:22:04 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_animdata_free((ID *)ma, false);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Free gpu material before the ntree */
|
|
|
|
GPU_material_free(&ma->gpumaterial);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* is no lib link block, but material extension */
|
|
|
|
if (ma->nodetree) {
|
|
|
|
ntreeFreeNestedTree(ma->nodetree);
|
|
|
|
MEM_freeN(ma->nodetree);
|
|
|
|
ma->nodetree = NULL;
|
|
|
|
}
|
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
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_SAFE_FREE(ma->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
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_SAFE_FREE(ma->gp_style);
|
2018-07-31 10:22:19 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_icon_id_delete((ID *)ma);
|
|
|
|
BKE_previewimg_free(&ma->preview);
|
2002-10-12 13:37:38 +02: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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if ((ma) && (ma->gp_style == NULL)) {
|
|
|
|
ma->gp_style = MEM_callocN(sizeof(MaterialGPencilStyle), "Grease Pencil Material Settings");
|
|
|
|
|
|
|
|
MaterialGPencilStyle *gp_style = ma->gp_style;
|
|
|
|
/* set basic settings */
|
|
|
|
gp_style->stroke_rgba[3] = 1.0f;
|
|
|
|
gp_style->fill_rgba[3] = 1.0f;
|
|
|
|
gp_style->pattern_gridsize = 0.1f;
|
|
|
|
gp_style->gradient_radius = 0.5f;
|
|
|
|
ARRAY_SET_ITEMS(gp_style->mix_rgba, 1.0f, 1.0f, 1.0f, 0.2f);
|
|
|
|
ARRAY_SET_ITEMS(gp_style->gradient_scale, 1.0f, 1.0f);
|
|
|
|
ARRAY_SET_ITEMS(gp_style->texture_scale, 1.0f, 1.0f);
|
|
|
|
gp_style->texture_opacity = 1.0f;
|
|
|
|
gp_style->texture_pixsize = 100.0f;
|
|
|
|
|
|
|
|
gp_style->flag |= GP_STYLE_STROKE_SHOW;
|
|
|
|
}
|
2018-07-31 10:22:19 +02:00
|
|
|
}
|
|
|
|
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
void BKE_material_init(Material *ma)
|
2002-10-12 13:37:38 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(ma, id));
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
|
2019-09-09 19:16:18 +02:00
|
|
|
MEMCPY_STRUCT_AFTER(ma, DNA_struct_default_get(Material), id);
|
2002-10-12 13:37:38 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Material *ma;
|
2002-10-12 13:37:38 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ma = BKE_libblock_alloc(bmain, ID_MA, name, 0);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_material_init(ma);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Material *ma;
|
2018-07-31 10:22:19 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ma = BKE_material_add(bmain, name);
|
2018-07-31 10:22:19 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* grease pencil settings */
|
|
|
|
if (ma != NULL) {
|
2020-02-05 11:23:58 +01:00
|
|
|
BKE_gpencil_material_attr_init(ma);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
return ma;
|
2018-07-31 10:22:19 +02:00
|
|
|
}
|
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
/**
|
2019-04-27 04:07:07 +02:00
|
|
|
* Only copy internal data of Material ID from source
|
|
|
|
* to already allocated/initialized destination.
|
|
|
|
* You probably never want to use that directly,
|
|
|
|
* use #BKE_id_copy or #BKE_id_copy_ex for typical needs.
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
*
|
|
|
|
* WARNING! This function will not handle ID user count!
|
|
|
|
*
|
2020-02-10 12:58:59 +01:00
|
|
|
* \param flag: Copying options (see BKE_lib_id.h's LIB_ID_COPY_... flags for more).
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
*/
|
|
|
|
void BKE_material_copy_data(Main *bmain, Material *ma_dst, const Material *ma_src, const int flag)
|
2002-10-12 13:37:38 +02:00
|
|
|
{
|
2019-09-02 17:34:56 +02:00
|
|
|
/* We always need allocation of our private ID data. */
|
2019-09-12 12:24:24 +02:00
|
|
|
const int flag_private_id_data = flag & ~LIB_ID_CREATE_NO_ALLOCATE;
|
2019-09-02 17:34:56 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ma_src->nodetree) {
|
2019-09-02 17:34:56 +02:00
|
|
|
BKE_id_copy_ex(bmain, (ID *)ma_src->nodetree, (ID **)&ma_dst->nodetree, flag_private_id_data);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) {
|
|
|
|
BKE_previewimg_id_copy(&ma_dst->id, &ma_src->id);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ma_dst->preview = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ma_src->texpaintslot != NULL) {
|
|
|
|
ma_dst->texpaintslot = MEM_dupallocN(ma_src->texpaintslot);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ma_src->gp_style != NULL) {
|
|
|
|
ma_dst->gp_style = MEM_dupallocN(ma_src->gp_style);
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_listbase_clear(&ma_dst->gpumaterial);
|
|
|
|
|
|
|
|
/* TODO Duplicate Engine Settings and set runtime to NULL */
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
}
|
2015-01-09 09:52:51 +01:00
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
Material *BKE_material_copy(Main *bmain, const Material *ma)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Material *ma_copy;
|
|
|
|
BKE_id_copy(bmain, &ma->id, (ID **)&ma_copy);
|
|
|
|
return ma_copy;
|
2002-10-12 13:37:38 +02:00
|
|
|
}
|
|
|
|
|
2010-12-19 21:12:12 +01:00
|
|
|
/* XXX (see above) material copy without adding to main dbase */
|
2018-01-10 23:55:41 +01:00
|
|
|
Material *BKE_material_localize(Material *ma)
|
2010-12-19 21:12:12 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* TODO(bastien): Replace with something like:
|
|
|
|
*
|
|
|
|
* Material *ma_copy;
|
|
|
|
* BKE_id_copy_ex(bmain, &ma->id, (ID **)&ma_copy,
|
|
|
|
* LIB_ID_COPY_NO_MAIN | LIB_ID_COPY_NO_PREVIEW | LIB_ID_COPY_NO_USER_REFCOUNT,
|
|
|
|
* false);
|
|
|
|
* return ma_copy;
|
|
|
|
*
|
|
|
|
* NOTE: Only possible once nested node trees are fully converted to that too. */
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
Material *man = BKE_libblock_copy_for_localize(&ma->id);
|
2010-12-19 21:12:12 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
man->texpaintslot = NULL;
|
|
|
|
man->preview = NULL;
|
2018-05-03 11:07:09 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ma->nodetree != NULL) {
|
|
|
|
man->nodetree = ntreeLocalize(ma->nodetree);
|
|
|
|
}
|
2018-11-15 16:50:30 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ma->gp_style != NULL) {
|
|
|
|
man->gp_style = MEM_dupallocN(ma->gp_style);
|
|
|
|
}
|
2018-11-18 15:56:14 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_listbase_clear(&man->gpumaterial);
|
2017-02-07 11:20:15 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* TODO Duplicate Engine Settings and set runtime to NULL */
|
2018-04-30 17:52:45 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
man->id.tag |= LIB_TAG_LOCALIZED;
|
2018-04-30 17:52:45 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return man;
|
2010-12-19 21:12:12 +01:00
|
|
|
}
|
|
|
|
|
2020-03-04 11:42:15 +01:00
|
|
|
void BKE_material_make_local(Main *bmain, Material *ma, const int flags)
|
2002-10-12 13:37:38 +02:00
|
|
|
{
|
2020-03-04 11:42:15 +01:00
|
|
|
BKE_lib_id_make_local_generic(bmain, &ma->id, flags);
|
2002-10-12 13:37:38 +02:00
|
|
|
}
|
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
Material ***BKE_object_material_array(Object *ob)
|
2002-10-12 13:37:38 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Mesh *me;
|
|
|
|
Curve *cu;
|
|
|
|
MetaBall *mb;
|
|
|
|
bGPdata *gpd;
|
|
|
|
|
|
|
|
if (ob->type == OB_MESH) {
|
|
|
|
me = ob->data;
|
|
|
|
return &(me->mat);
|
|
|
|
}
|
|
|
|
else if (ELEM(ob->type, OB_CURVE, OB_FONT, OB_SURF)) {
|
|
|
|
cu = ob->data;
|
|
|
|
return &(cu->mat);
|
|
|
|
}
|
|
|
|
else if (ob->type == OB_MBALL) {
|
|
|
|
mb = ob->data;
|
|
|
|
return &(mb->mat);
|
|
|
|
}
|
|
|
|
else if (ob->type == OB_GPENCIL) {
|
|
|
|
gpd = ob->data;
|
|
|
|
return &(gpd->mat);
|
|
|
|
}
|
|
|
|
return NULL;
|
2002-10-12 13:37:38 +02:00
|
|
|
}
|
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
short *BKE_object_material_num(Object *ob)
|
2002-10-12 13:37:38 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Mesh *me;
|
|
|
|
Curve *cu;
|
|
|
|
MetaBall *mb;
|
|
|
|
bGPdata *gpd;
|
|
|
|
|
|
|
|
if (ob->type == OB_MESH) {
|
|
|
|
me = ob->data;
|
|
|
|
return &(me->totcol);
|
|
|
|
}
|
|
|
|
else if (ELEM(ob->type, OB_CURVE, OB_FONT, OB_SURF)) {
|
|
|
|
cu = ob->data;
|
|
|
|
return &(cu->totcol);
|
|
|
|
}
|
|
|
|
else if (ob->type == OB_MBALL) {
|
|
|
|
mb = ob->data;
|
|
|
|
return &(mb->totcol);
|
|
|
|
}
|
|
|
|
else if (ob->type == OB_GPENCIL) {
|
|
|
|
gpd = ob->data;
|
|
|
|
return &(gpd->totcol);
|
|
|
|
}
|
|
|
|
return NULL;
|
2002-10-12 13:37:38 +02:00
|
|
|
}
|
|
|
|
|
2010-09-03 09:25:37 +02:00
|
|
|
/* same as above but for ID's */
|
2020-02-05 11:23:58 +01:00
|
|
|
Material ***BKE_id_material_array(ID *id)
|
2010-09-03 09:25:37 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* ensure we don't try get materials from non-obdata */
|
|
|
|
BLI_assert(OB_DATA_SUPPORT_ID(GS(id->name)));
|
|
|
|
|
|
|
|
switch (GS(id->name)) {
|
|
|
|
case ID_ME:
|
|
|
|
return &(((Mesh *)id)->mat);
|
|
|
|
case ID_CU:
|
|
|
|
return &(((Curve *)id)->mat);
|
|
|
|
case ID_MB:
|
|
|
|
return &(((MetaBall *)id)->mat);
|
|
|
|
case ID_GD:
|
|
|
|
return &(((bGPdata *)id)->mat);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NULL;
|
2010-09-03 09:25:37 +02:00
|
|
|
}
|
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
short *BKE_id_material_num(ID *id)
|
2010-09-03 09:25:37 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* ensure we don't try get materials from non-obdata */
|
|
|
|
BLI_assert(OB_DATA_SUPPORT_ID(GS(id->name)));
|
|
|
|
|
|
|
|
switch (GS(id->name)) {
|
|
|
|
case ID_ME:
|
|
|
|
return &(((Mesh *)id)->totcol);
|
|
|
|
case ID_CU:
|
|
|
|
return &(((Curve *)id)->totcol);
|
|
|
|
case ID_MB:
|
|
|
|
return &(((MetaBall *)id)->totcol);
|
|
|
|
case ID_GD:
|
|
|
|
return &(((bGPdata *)id)->totcol);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NULL;
|
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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* ensure we don't try get materials from non-obdata */
|
|
|
|
BLI_assert(OB_DATA_SUPPORT_ID(GS(id->name)));
|
|
|
|
|
|
|
|
switch (GS(id->name)) {
|
|
|
|
case ID_ME:
|
|
|
|
BKE_mesh_material_index_remove((Mesh *)id, index);
|
|
|
|
break;
|
|
|
|
case ID_CU:
|
|
|
|
BKE_curve_material_index_remove((Curve *)id, index);
|
|
|
|
break;
|
|
|
|
case ID_MB:
|
|
|
|
/* meta-elems don't have materials atm */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-07-31 13:12:38 +02:00
|
|
|
}
|
|
|
|
|
2019-07-31 21:04:52 +02:00
|
|
|
bool BKE_object_material_slot_used(ID *id, short actcol)
|
|
|
|
{
|
|
|
|
/* ensure we don't try get materials from non-obdata */
|
|
|
|
BLI_assert(OB_DATA_SUPPORT_ID(GS(id->name)));
|
|
|
|
|
|
|
|
switch (GS(id->name)) {
|
|
|
|
case ID_ME:
|
|
|
|
return BKE_mesh_material_index_used((Mesh *)id, actcol - 1);
|
|
|
|
case ID_CU:
|
|
|
|
return BKE_curve_material_index_used((Curve *)id, actcol - 1);
|
|
|
|
case ID_MB:
|
|
|
|
/* meta-elems don't have materials atm */
|
|
|
|
return false;
|
|
|
|
case ID_GD:
|
|
|
|
return BKE_gpencil_material_index_used((bGPdata *)id, actcol - 1);
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-14 13:29:58 +02:00
|
|
|
static void material_data_index_clear_id(ID *id)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* ensure we don't try get materials from non-obdata */
|
|
|
|
BLI_assert(OB_DATA_SUPPORT_ID(GS(id->name)));
|
|
|
|
|
|
|
|
switch (GS(id->name)) {
|
|
|
|
case ID_ME:
|
|
|
|
BKE_mesh_material_index_clear((Mesh *)id);
|
|
|
|
break;
|
|
|
|
case ID_CU:
|
|
|
|
BKE_curve_material_index_clear((Curve *)id);
|
|
|
|
break;
|
|
|
|
case ID_MB:
|
|
|
|
/* meta-elems don't have materials atm */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-08-14 13:29:58 +02:00
|
|
|
}
|
|
|
|
|
2016-08-12 14:59:11 +02:00
|
|
|
void BKE_material_resize_id(Main *bmain, ID *id, short totcol, bool do_id_user)
|
2013-08-14 16:36:43 +02:00
|
|
|
{
|
2020-02-05 11:23:58 +01:00
|
|
|
Material ***matar = BKE_id_material_array(id);
|
|
|
|
short *totcolp = BKE_id_material_num(id);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if (matar == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_id_user && totcol < (*totcolp)) {
|
|
|
|
short i;
|
|
|
|
for (i = totcol; i < (*totcolp); i++) {
|
|
|
|
id_us_min((ID *)(*matar)[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (totcol == 0) {
|
|
|
|
if (*totcolp) {
|
|
|
|
MEM_freeN(*matar);
|
|
|
|
*matar = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*matar = MEM_recallocN(*matar, sizeof(void *) * totcol);
|
|
|
|
}
|
|
|
|
*totcolp = totcol;
|
|
|
|
|
|
|
|
DEG_id_tag_update(id, ID_RECALC_COPY_ON_WRITE);
|
|
|
|
DEG_relations_tag_update(bmain);
|
2013-08-14 16:36:43 +02:00
|
|
|
}
|
|
|
|
|
2016-08-12 14:59:11 +02:00
|
|
|
void BKE_material_append_id(Main *bmain, ID *id, Material *ma)
|
2010-09-03 09:25:37 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Material ***matar;
|
2020-02-05 11:23:58 +01:00
|
|
|
if ((matar = BKE_id_material_array(id))) {
|
|
|
|
short *totcol = BKE_id_material_num(id);
|
2019-04-17 06:17:24 +02:00
|
|
|
Material **mat = MEM_callocN(sizeof(void *) * ((*totcol) + 1), "newmatar");
|
2019-04-22 01:39:35 +02:00
|
|
|
if (*totcol) {
|
2019-04-17 06:17:24 +02:00
|
|
|
memcpy(mat, *matar, sizeof(void *) * (*totcol));
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
if (*matar) {
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(*matar);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
*matar = mat;
|
|
|
|
(*matar)[(*totcol)++] = ma;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
DEG_id_tag_update(id, ID_RECALC_COPY_ON_WRITE);
|
|
|
|
DEG_relations_tag_update(bmain);
|
|
|
|
}
|
2010-09-03 09:25:37 +02:00
|
|
|
}
|
|
|
|
|
2019-08-16 14:36:57 +02:00
|
|
|
Material *BKE_material_pop_id(Main *bmain, ID *id, int index_i)
|
2010-09-03 09:25:37 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
short index = (short)index_i;
|
|
|
|
Material *ret = NULL;
|
|
|
|
Material ***matar;
|
2020-02-05 11:23:58 +01:00
|
|
|
if ((matar = BKE_id_material_array(id))) {
|
|
|
|
short *totcol = BKE_id_material_num(id);
|
2019-04-17 06:17:24 +02:00
|
|
|
if (index >= 0 && index < (*totcol)) {
|
|
|
|
ret = (*matar)[index];
|
|
|
|
id_us_min((ID *)ret);
|
|
|
|
|
|
|
|
if (*totcol <= 1) {
|
|
|
|
*totcol = 0;
|
|
|
|
MEM_freeN(*matar);
|
|
|
|
*matar = NULL;
|
|
|
|
}
|
|
|
|
else {
|
2019-04-22 01:39:35 +02:00
|
|
|
if (index + 1 != (*totcol)) {
|
2019-04-17 06:17:24 +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
|
|
|
|
|
|
|
(*totcol)--;
|
|
|
|
*matar = MEM_reallocN(*matar, sizeof(void *) * (*totcol));
|
2020-02-05 11:23:58 +01:00
|
|
|
BKE_objects_materials_test_all(bmain, id);
|
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
|
|
|
|
|
|
|
DEG_id_tag_update(id, ID_RECALC_COPY_ON_WRITE);
|
|
|
|
DEG_relations_tag_update(bmain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2010-09-03 09:25:37 +02:00
|
|
|
}
|
|
|
|
|
2019-08-16 14:36:57 +02:00
|
|
|
void BKE_material_clear_id(Main *bmain, ID *id)
|
2013-08-14 13:29:58 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Material ***matar;
|
2020-02-05 11:23:58 +01:00
|
|
|
if ((matar = BKE_id_material_array(id))) {
|
|
|
|
short *totcol = BKE_id_material_num(id);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
while ((*totcol)--) {
|
|
|
|
id_us_min((ID *)((*matar)[*totcol]));
|
|
|
|
}
|
|
|
|
*totcol = 0;
|
|
|
|
if (*matar) {
|
|
|
|
MEM_freeN(*matar);
|
|
|
|
*matar = NULL;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
DEG_id_tag_update(id, ID_RECALC_COPY_ON_WRITE);
|
|
|
|
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-04-17 06:17:24 +02:00
|
|
|
Material ***matarar, **ma_p;
|
|
|
|
const short *totcolp;
|
|
|
|
|
2019-04-22 01:39:35 +02:00
|
|
|
if (ob == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* if object cannot have material, (totcolp == NULL) */
|
2020-02-05 11:23:58 +01:00
|
|
|
totcolp = BKE_object_material_num(ob);
|
2019-04-22 01:39:35 +02:00
|
|
|
if (totcolp == NULL || ob->totcol == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* return NULL for invalid 'act', can happen for mesh face indices */
|
2019-04-22 01:39:35 +02:00
|
|
|
if (act > ob->totcol) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
else if (act <= 0) {
|
|
|
|
if (act < 0) {
|
|
|
|
CLOG_ERROR(&LOG, "Negative material index!");
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ob->matbits && ob->matbits[act - 1]) { /* in object */
|
|
|
|
ma_p = &ob->mat[act - 1];
|
|
|
|
}
|
|
|
|
else { /* in data */
|
|
|
|
|
|
|
|
/* check for inconsistency */
|
2019-04-22 01:39:35 +02:00
|
|
|
if (*totcolp < ob->totcol) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ob->totcol = *totcolp;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
if (act > ob->totcol) {
|
2019-04-17 06:17:24 +02:00
|
|
|
act = ob->totcol;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
matarar = BKE_object_material_array(ob);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if (matarar && *matarar) {
|
|
|
|
ma_p = &(*matarar)[act - 1];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ma_p = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ma_p;
|
2019-01-03 02:15:03 +01:00
|
|
|
}
|
|
|
|
|
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);
|
2019-04-17 06:17:24 +02:00
|
|
|
return ma_p ? *ma_p : NULL;
|
2002-10-12 13:37:38 +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);
|
2019-08-30 14:19:07 +02:00
|
|
|
if (ma != NULL) {
|
|
|
|
return ma;
|
|
|
|
}
|
|
|
|
else {
|
2020-02-06 13:05:45 +01: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);
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ma != NULL) {
|
|
|
|
if (ma->gp_style == NULL) {
|
2020-02-05 11:23:58 +01:00
|
|
|
BKE_gpencil_material_attr_init(ma);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ma->gp_style;
|
|
|
|
}
|
|
|
|
else {
|
2020-02-06 13:05:45 +01:00
|
|
|
return BKE_material_default_gpencil()->gp_style;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-07-31 10:22:19 +02:00
|
|
|
}
|
|
|
|
|
2016-08-12 14:59:11 +02:00
|
|
|
void BKE_material_resize_object(Main *bmain, Object *ob, const short totcol, bool do_id_user)
|
2002-10-12 13:37:38 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Material **newmatar;
|
|
|
|
char *newmatbits;
|
|
|
|
|
|
|
|
if (do_id_user && totcol < ob->totcol) {
|
|
|
|
short i;
|
|
|
|
for (i = totcol; i < ob->totcol; i++) {
|
|
|
|
id_us_min((ID *)ob->mat[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (totcol == 0) {
|
|
|
|
if (ob->totcol) {
|
|
|
|
MEM_freeN(ob->mat);
|
|
|
|
MEM_freeN(ob->matbits);
|
|
|
|
ob->mat = NULL;
|
|
|
|
ob->matbits = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ob->totcol < totcol) {
|
|
|
|
newmatar = MEM_callocN(sizeof(void *) * totcol, "newmatar");
|
|
|
|
newmatbits = MEM_callocN(sizeof(char) * totcol, "newmatbits");
|
|
|
|
if (ob->totcol) {
|
|
|
|
memcpy(newmatar, ob->mat, sizeof(void *) * ob->totcol);
|
|
|
|
memcpy(newmatbits, ob->matbits, sizeof(char) * ob->totcol);
|
|
|
|
MEM_freeN(ob->mat);
|
|
|
|
MEM_freeN(ob->matbits);
|
|
|
|
}
|
|
|
|
ob->mat = newmatar;
|
|
|
|
ob->matbits = newmatbits;
|
|
|
|
}
|
|
|
|
/* XXX, why not realloc on shrink? - campbell */
|
|
|
|
|
|
|
|
ob->totcol = totcol;
|
2019-04-22 01:39:35 +02:00
|
|
|
if (ob->totcol && ob->actcol == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ob->actcol = 1;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
if (ob->actcol > ob->totcol) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ob->actcol = ob->totcol;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE | ID_RECALC_GEOMETRY);
|
|
|
|
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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* make the ob mat-array same size as 'ob->data' mat-array */
|
|
|
|
const short *totcol;
|
2016-07-08 14:36:25 +02:00
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
if (id == NULL || (totcol = BKE_id_material_num(id)) == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-07-08 14:36:25 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_material_resize_object(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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* make the ob mat-array same size as 'ob->data' mat-array */
|
|
|
|
Object *ob;
|
|
|
|
const short *totcol;
|
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
if (id == NULL || (totcol = BKE_id_material_num(id)) == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BKE_main_lock(bmain);
|
|
|
|
for (ob = bmain->objects.first; ob; ob = ob->id.next) {
|
|
|
|
if (ob->data == id) {
|
|
|
|
BKE_material_resize_object(bmain, ob, *totcol, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Material *mao, **matar, ***matarar;
|
|
|
|
short *totcolp;
|
2011-10-01 19:51:47 +02:00
|
|
|
|
2019-04-22 01:39:35 +02:00
|
|
|
if (act > MAXMAT) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
if (act < 1) {
|
2019-04-17 06:17:24 +02:00
|
|
|
act = 1;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2011-10-01 19:51:47 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* test arraylens */
|
2011-10-01 19:51:47 +02:00
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
totcolp = BKE_id_material_num(id);
|
|
|
|
matarar = BKE_id_material_array(id);
|
2011-10-01 19:51:47 +02:00
|
|
|
|
2019-04-22 01:39:35 +02:00
|
|
|
if (totcolp == NULL || matarar == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2011-10-01 19:51:47 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (act > *totcolp) {
|
|
|
|
matar = MEM_callocN(sizeof(void *) * act, "matarray1");
|
2011-10-01 19:51:47 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (*totcolp) {
|
|
|
|
memcpy(matar, *matarar, sizeof(void *) * (*totcolp));
|
|
|
|
MEM_freeN(*matarar);
|
|
|
|
}
|
2011-10-01 19:51:47 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
*matarar = matar;
|
|
|
|
*totcolp = act;
|
|
|
|
}
|
2011-10-01 19:51:47 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* in data */
|
|
|
|
mao = (*matarar)[act - 1];
|
2019-04-22 01:39:35 +02:00
|
|
|
if (mao) {
|
2019-04-17 06:17:24 +02:00
|
|
|
id_us_min(&mao->id);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
(*matarar)[act - 1] = ma;
|
2011-10-01 19:51:47 +02:00
|
|
|
|
2019-04-22 01:39:35 +02:00
|
|
|
if (ma) {
|
2019-04-17 06:17:24 +02: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
|
|
|
}
|
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
void BKE_object_material_assign(Main *bmain, Object *ob, Material *ma, short act, int assign_type)
|
2002-10-12 13:37:38 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Material *mao, **matar, ***matarar;
|
|
|
|
short *totcolp;
|
|
|
|
char bit = 0;
|
|
|
|
|
2019-04-22 01:39:35 +02:00
|
|
|
if (act > MAXMAT) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
if (act < 1) {
|
2019-04-17 06:17:24 +02:00
|
|
|
act = 1;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* prevent crashing when using accidentally */
|
|
|
|
BLI_assert(!ID_IS_LINKED(ob));
|
2019-04-22 01:39:35 +02:00
|
|
|
if (ID_IS_LINKED(ob)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
/* test arraylens */
|
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
totcolp = BKE_object_material_num(ob);
|
|
|
|
matarar = BKE_object_material_array(ob);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 01:39:35 +02:00
|
|
|
if (totcolp == NULL || matarar == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if (act > *totcolp) {
|
|
|
|
matar = MEM_callocN(sizeof(void *) * act, "matarray1");
|
|
|
|
|
|
|
|
if (*totcolp) {
|
|
|
|
memcpy(matar, *matarar, sizeof(void *) * (*totcolp));
|
|
|
|
MEM_freeN(*matarar);
|
|
|
|
}
|
|
|
|
|
|
|
|
*matarar = matar;
|
|
|
|
*totcolp = act;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (act > ob->totcol) {
|
|
|
|
/* Need more space in the material arrays */
|
|
|
|
ob->mat = MEM_recallocN_id(ob->mat, sizeof(void *) * act, "matarray2");
|
|
|
|
ob->matbits = MEM_recallocN_id(ob->matbits, sizeof(char) * act, "matbits1");
|
|
|
|
ob->totcol = act;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine the object/mesh linking */
|
|
|
|
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) {
|
|
|
|
/* copy from previous material */
|
|
|
|
bit = ob->matbits[ob->actcol - 1];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (assign_type) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do it */
|
|
|
|
|
|
|
|
ob->matbits[act - 1] = bit;
|
|
|
|
if (bit == 1) { /* in object */
|
|
|
|
mao = ob->mat[act - 1];
|
2019-04-22 01:39:35 +02:00
|
|
|
if (mao) {
|
2019-04-17 06:17:24 +02:00
|
|
|
id_us_min(&mao->id);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
ob->mat[act - 1] = ma;
|
2020-02-05 11:23:58 +01:00
|
|
|
BKE_object_materials_test(bmain, ob, ob->data);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else { /* in data */
|
|
|
|
mao = (*matarar)[act - 1];
|
2019-04-22 01:39:35 +02:00
|
|
|
if (mao) {
|
2019-04-17 06:17:24 +02:00
|
|
|
id_us_min(&mao->id);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
(*matarar)[act - 1] = ma;
|
2020-02-05 11:23:58 +01:00
|
|
|
BKE_objects_materials_test_all(bmain, ob->data); /* Data may be used by several objects... */
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
2019-04-22 01:39:35 +02:00
|
|
|
if (ma) {
|
2019-04-17 06:17:24 +02:00
|
|
|
id_us_plus(&ma->id);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2002-10-12 13:37:38 +02:00
|
|
|
}
|
|
|
|
|
2015-04-27 23:24:56 +02:00
|
|
|
void BKE_material_remap_object(Object *ob, const unsigned int *remap)
|
|
|
|
{
|
2020-02-05 11:23:58 +01:00
|
|
|
Material ***matar = BKE_object_material_array(ob);
|
|
|
|
const short *totcol_p = BKE_object_material_num(ob);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
BLI_array_permute(ob->mat, ob->totcol, remap);
|
|
|
|
|
|
|
|
if (ob->matbits) {
|
|
|
|
BLI_array_permute(ob->matbits, ob->totcol, remap);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (matar) {
|
|
|
|
BLI_array_permute(*matar, *totcol_p, remap);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ob->type == OB_MESH) {
|
|
|
|
BKE_mesh_material_remap(ob->data, remap, ob->totcol);
|
|
|
|
}
|
|
|
|
else if (ELEM(ob->type, OB_CURVE, OB_SURF, OB_FONT)) {
|
|
|
|
BKE_curve_material_remap(ob->data, remap, ob->totcol);
|
|
|
|
}
|
|
|
|
else if (ob->type == OB_GPENCIL) {
|
|
|
|
BKE_gpencil_material_remap(ob->data, remap, ob->totcol);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* add support for this object data! */
|
|
|
|
BLI_assert(matar == NULL);
|
|
|
|
}
|
2015-04-27 23:24:56 +02:00
|
|
|
}
|
|
|
|
|
2015-12-12 14:34:09 +01:00
|
|
|
/**
|
|
|
|
* Calculate a material remapping from \a ob_src to \a ob_dst.
|
|
|
|
*
|
|
|
|
* \param remap_src_to_dst: An array the size of `ob_src->totcol`
|
|
|
|
* where index values are filled in which map to \a ob_dst materials.
|
|
|
|
*/
|
2019-04-17 06:17:24 +02:00
|
|
|
void BKE_material_remap_object_calc(Object *ob_dst, Object *ob_src, short *remap_src_to_dst)
|
2015-12-12 14:34:09 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ob_src->totcol == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GHash *gh_mat_map = BLI_ghash_ptr_new_ex(__func__, ob_src->totcol);
|
|
|
|
|
|
|
|
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);
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_ghash_reinsert(gh_mat_map, ma_src, POINTER_FROM_INT(i), NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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))) {
|
2019-04-17 06:17:24 +02: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) {
|
|
|
|
remap_src_to_dst[i] = POINTER_AS_INT(*index_src_p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_ghash_free(gh_mat_map, NULL, NULL);
|
2015-12-12 14:34:09 +01:00
|
|
|
}
|
|
|
|
|
2009-10-07 18:32:55 +02:00
|
|
|
/* XXX - this calls many more update calls per object then are needed, could be optimized */
|
2020-02-05 11:25:50 +01:00
|
|
|
void BKE_object_material_array_assign(Main *bmain,
|
|
|
|
struct Object *ob,
|
|
|
|
struct Material ***matar,
|
|
|
|
short totcol)
|
2009-10-07 18:32:55 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int actcol_orig = ob->actcol;
|
|
|
|
short i;
|
2009-10-07 18:32:55 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
while ((ob->totcol > totcol) && BKE_object_material_slot_remove(bmain, ob)) {
|
|
|
|
/* pass */
|
|
|
|
}
|
2009-10-07 18:32:55 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* now we have the right number of slots */
|
2019-04-22 01:39:35 +02:00
|
|
|
for (i = 0; i < totcol; i++) {
|
2020-02-05 11:23:58 +01:00
|
|
|
BKE_object_material_assign(bmain, ob, (*matar)[i], i + 1, 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) {
|
2019-04-17 06:17:24 +02:00
|
|
|
actcol_orig = ob->totcol;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2009-10-07 18:32:55 +02:00
|
|
|
|
2019-04-17 06:17:24 +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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Material ***matarar;
|
|
|
|
short a, *totcolp;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 01:39:35 +02:00
|
|
|
if (ma == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return 0;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
totcolp = BKE_object_material_num(ob);
|
|
|
|
matarar = BKE_object_material_array(ob);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 01:39:35 +02:00
|
|
|
if (totcolp == NULL || matarar == NULL) {
|
2019-04-17 06:17:24 +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) {
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (a < *totcolp) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return a + 1;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +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
|
|
|
{
|
2019-04-22 01:39:35 +02:00
|
|
|
if (ob == NULL) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
if (ob->totcol >= MAXMAT) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
BKE_object_material_assign(bmain, ob, NULL, ob->totcol + 1, BKE_MAT_ASSIGN_USERPREF);
|
2019-04-17 06:17:24 +02:00
|
|
|
ob->actcol = ob->totcol;
|
|
|
|
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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Material *mao, ***matarar;
|
|
|
|
short *totcolp;
|
|
|
|
short a, actcol;
|
|
|
|
|
|
|
|
if (ob == NULL || ob->totcol == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this should never happen and used to crash */
|
|
|
|
if (ob->actcol <= 0) {
|
|
|
|
CLOG_ERROR(&LOG, "invalid material index %d, report a bug!", ob->actcol);
|
|
|
|
BLI_assert(0);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* take a mesh/curve/mball as starting point, remove 1 index,
|
|
|
|
* AND with all objects that share the ob->data
|
|
|
|
*
|
|
|
|
* after that check indices in mesh/curve/mball!!!
|
|
|
|
*/
|
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
totcolp = BKE_object_material_num(ob);
|
|
|
|
matarar = BKE_object_material_array(ob);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if (ELEM(NULL, matarar, *matarar)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* can happen on face selection in editmode */
|
|
|
|
if (ob->actcol > ob->totcol) {
|
|
|
|
ob->actcol = ob->totcol;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we delete the actcol */
|
|
|
|
mao = (*matarar)[ob->actcol - 1];
|
2019-04-22 01:39:35 +02:00
|
|
|
if (mao) {
|
2019-04-17 06:17:24 +02:00
|
|
|
id_us_min(&mao->id);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 01:39:35 +02:00
|
|
|
for (a = ob->actcol; a < ob->totcol; a++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
(*matarar)[a - 1] = (*matarar)[a];
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
(*totcolp)--;
|
|
|
|
|
|
|
|
if (*totcolp == 0) {
|
|
|
|
MEM_freeN(*matarar);
|
|
|
|
*matarar = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
actcol = ob->actcol;
|
|
|
|
|
|
|
|
for (Object *obt = bmain->objects.first; obt; obt = obt->id.next) {
|
|
|
|
if (obt->data == ob->data) {
|
|
|
|
/* Can happen when object material lists are used, see: T52953 */
|
|
|
|
if (actcol > obt->totcol) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* WATCH IT: do not use actcol from ob or from obt (can become zero) */
|
|
|
|
mao = obt->mat[actcol - 1];
|
2019-04-22 01:39:35 +02:00
|
|
|
if (mao) {
|
2019-04-17 06:17:24 +02:00
|
|
|
id_us_min(&mao->id);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
for (a = actcol; a < obt->totcol; a++) {
|
|
|
|
obt->mat[a - 1] = obt->mat[a];
|
|
|
|
obt->matbits[a - 1] = obt->matbits[a];
|
|
|
|
}
|
|
|
|
obt->totcol--;
|
2019-04-22 01:39:35 +02:00
|
|
|
if (obt->actcol > obt->totcol) {
|
2019-04-17 06:17:24 +02:00
|
|
|
obt->actcol = obt->totcol;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if (obt->totcol == 0) {
|
|
|
|
MEM_freeN(obt->mat);
|
|
|
|
MEM_freeN(obt->matbits);
|
|
|
|
obt->mat = NULL;
|
|
|
|
obt->matbits = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check indices from mesh */
|
2019-06-12 15:51:51 +02:00
|
|
|
if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
material_data_index_remove_id((ID *)ob->data, actcol - 1);
|
|
|
|
if (ob->runtime.curve_cache) {
|
|
|
|
BKE_displist_free(&ob->runtime.curve_cache->disp);
|
|
|
|
}
|
|
|
|
}
|
2019-06-12 15:51:51 +02:00
|
|
|
/* check indices from gpencil */
|
|
|
|
else if (ob->type == OB_GPENCIL) {
|
|
|
|
BKE_gpencil_material_index_reassign((bGPdata *)ob->data, ob->totcol, actcol - 1);
|
|
|
|
}
|
2019-04-17 06:17:24 +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)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *inode;
|
|
|
|
bNodeSocket *sock;
|
|
|
|
|
|
|
|
for (sock = node->inputs.first; sock; sock = sock->next) {
|
|
|
|
if (sock->link) {
|
|
|
|
inode = sock->link->fromnode;
|
|
|
|
if (inode->typeinfo->nclass == NODE_CLASS_INPUT && inode->typeinfo->type == SH_NODE_UVMAP) {
|
|
|
|
return inode;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return nodetree_uv_node_recursive(inode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2015-01-28 14:42:47 +01:00
|
|
|
}
|
|
|
|
|
2019-07-31 16:37:03 +02:00
|
|
|
typedef bool (*ForEachTexNodeCallback)(bNode *node, void *userdata);
|
|
|
|
static bool ntree_foreach_texnode_recursive(bNodeTree *nodetree,
|
|
|
|
ForEachTexNodeCallback callback,
|
|
|
|
void *userdata)
|
2018-09-10 18:18:04 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
for (bNode *node = nodetree->nodes.first; node; node = node->next) {
|
|
|
|
if (node->typeinfo->nclass == NODE_CLASS_TEXTURE &&
|
|
|
|
node->typeinfo->type == SH_NODE_TEX_IMAGE && node->id) {
|
2019-07-31 16:37:03 +02:00
|
|
|
if (!callback(node, userdata)) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
else if (ELEM(node->type, NODE_GROUP, NODE_CUSTOM_GROUP) && node->id) {
|
|
|
|
/* recurse into the node group and see if it contains any textures */
|
2019-07-31 16:37:03 +02:00
|
|
|
if (!ntree_foreach_texnode_recursive((bNodeTree *)node->id, callback, userdata)) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
2019-07-31 16:37:03 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-01 01:03:50 +02:00
|
|
|
static bool count_texture_nodes_cb(bNode *UNUSED(node), void *userdata)
|
2019-07-31 16:37:03 +02:00
|
|
|
{
|
|
|
|
(*((int *)userdata))++;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int count_texture_nodes_recursive(bNodeTree *nodetree)
|
|
|
|
{
|
|
|
|
int tex_nodes = 0;
|
|
|
|
ntree_foreach_texnode_recursive(nodetree, count_texture_nodes_cb, &tex_nodes);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
return tex_nodes;
|
2018-09-10 18:18:04 +02:00
|
|
|
}
|
|
|
|
|
2019-07-31 16:37:03 +02:00
|
|
|
struct FillTexPaintSlotsData {
|
|
|
|
bNode *active_node;
|
|
|
|
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
|
|
|
{
|
2019-07-31 16:37:03 +02:00
|
|
|
struct FillTexPaintSlotsData *fill_data = 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
|
|
|
|
2019-07-31 16:37:03 +02:00
|
|
|
ma->texpaintslot[index].ima = (Image *)node->id;
|
|
|
|
ma->texpaintslot[index].interp = ((NodeTexImage *)node->storage)->interpolation;
|
|
|
|
|
|
|
|
/* for new renderer, we need to traverse the treeback in search of a UV node */
|
|
|
|
bNode *uvnode = nodetree_uv_node_recursive(node);
|
|
|
|
|
|
|
|
if (uvnode) {
|
|
|
|
NodeShaderUVMap *storage = (NodeShaderUVMap *)uvnode->storage;
|
|
|
|
ma->texpaintslot[index].uvname = storage->uv_map;
|
|
|
|
/* set a value to index so UI knows that we have a valid pointer for the mesh */
|
|
|
|
ma->texpaintslot[index].valid = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* just invalidate the index here so UV map does not get displayed on the UI */
|
|
|
|
ma->texpaintslot[index].valid = false;
|
2019-04-17 06:17:24 +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,
|
|
|
|
Material *ma,
|
|
|
|
int slot_len)
|
|
|
|
{
|
|
|
|
struct FillTexPaintSlotsData fill_data = {active_node, ma, 0, slot_len};
|
|
|
|
ntree_foreach_texnode_recursive(nodetree, fill_texpaint_slots_cb, &fill_data);
|
2018-09-10 18:18:04 +02:00
|
|
|
}
|
|
|
|
|
2019-03-07 19:39:50 +01:00
|
|
|
void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma)
|
2014-07-21 12:02:05 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int count = 0;
|
2019-03-07 19:39:50 +01:00
|
|
|
|
2019-04-22 01:39:35 +02:00
|
|
|
if (!ma) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* COW needed when adding texture slot on an object with no materials. */
|
|
|
|
DEG_id_tag_update(&ma->id, ID_RECALC_SHADING | ID_RECALC_COPY_ON_WRITE);
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ma->texpaintslot) {
|
|
|
|
MEM_freeN(ma->texpaintslot);
|
|
|
|
ma->tot_slots = 0;
|
|
|
|
ma->texpaintslot = NULL;
|
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (scene->toolsettings->imapaint.mode == IMAGEPAINT_MODE_IMAGE) {
|
|
|
|
ma->paint_active_slot = 0;
|
|
|
|
ma->paint_clone_slot = 0;
|
|
|
|
return;
|
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!(ma->nodetree)) {
|
|
|
|
ma->paint_active_slot = 0;
|
|
|
|
ma->paint_clone_slot = 0;
|
|
|
|
return;
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
count = count_texture_nodes_recursive(ma->nodetree);
|
2019-03-07 19:39:50 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (count == 0) {
|
|
|
|
ma->paint_active_slot = 0;
|
|
|
|
ma->paint_clone_slot = 0;
|
|
|
|
return;
|
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ma->texpaintslot = MEM_callocN(sizeof(*ma->texpaintslot) * count, "texpaint_slots");
|
2019-03-07 19:39:50 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *active_node = nodeGetActiveTexture(ma->nodetree);
|
2019-03-07 19:39:50 +01:00
|
|
|
|
2019-07-31 16:37:03 +02:00
|
|
|
fill_texpaint_slots_recursive(ma->nodetree, active_node, ma, count);
|
2019-03-07 19:39:50 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ma->tot_slots = count;
|
2019-03-07 19:39:50 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ma->paint_active_slot >= count) {
|
|
|
|
ma->paint_active_slot = count - 1;
|
|
|
|
}
|
2019-03-07 19:39:50 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ma->paint_clone_slot >= count) {
|
|
|
|
ma->paint_clone_slot = count - 1;
|
|
|
|
}
|
2019-03-07 19:39:50 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
|
|
|
|
2019-03-07 19:39:50 +01:00
|
|
|
void BKE_texpaint_slots_refresh_object(Scene *scene, struct Object *ob)
|
2014-07-21 12:02:05 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int i;
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (i = 1; i < ob->totcol + 1; i++) {
|
2020-02-05 11:23:58 +01:00
|
|
|
Material *ma = BKE_object_material_get(ob, i);
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_texpaint_slot_refresh_cache(scene, ma);
|
|
|
|
}
|
2014-07-21 12:02:05 +02:00
|
|
|
}
|
|
|
|
|
2019-07-31 16:37:03 +02:00
|
|
|
struct FindTexPaintNodeData {
|
|
|
|
bNode *node;
|
|
|
|
short iter_index;
|
|
|
|
short index;
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool texpaint_slot_node_find_cb(bNode *node, void *userdata)
|
|
|
|
{
|
|
|
|
struct FindTexPaintNodeData *find_data = userdata;
|
|
|
|
if (find_data->iter_index++ == find_data->index) {
|
|
|
|
find_data->node = node;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bNode *BKE_texpaint_slot_material_find_node(Material *ma, short texpaint_slot)
|
|
|
|
{
|
|
|
|
struct FindTexPaintNodeData find_data = {NULL, 0, texpaint_slot};
|
|
|
|
ntree_foreach_texnode_recursive(ma->nodetree, texpaint_slot_node_find_cb, &find_data);
|
|
|
|
|
|
|
|
return find_data.node;
|
|
|
|
}
|
|
|
|
|
2012-05-27 21:40:36 +02:00
|
|
|
/* r_col = current value, col = new value, (fac == 0) is no change */
|
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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
float tmp, facm = 1.0f - fac;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case MA_RAMP_BLEND:
|
|
|
|
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];
|
|
|
|
break;
|
|
|
|
case MA_RAMP_ADD:
|
|
|
|
r_col[0] += fac * col[0];
|
|
|
|
r_col[1] += fac * col[1];
|
|
|
|
r_col[2] += fac * col[2];
|
|
|
|
break;
|
|
|
|
case MA_RAMP_MULT:
|
|
|
|
r_col[0] *= (facm + fac * col[0]);
|
|
|
|
r_col[1] *= (facm + fac * col[1]);
|
|
|
|
r_col[2] *= (facm + fac * col[2]);
|
|
|
|
break;
|
|
|
|
case MA_RAMP_SCREEN:
|
|
|
|
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]);
|
|
|
|
break;
|
|
|
|
case MA_RAMP_OVERLAY:
|
2019-04-22 01:39:35 +02:00
|
|
|
if (r_col[0] < 0.5f) {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[0] *= (facm + 2.0f * fac * col[0]);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +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) {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[1] *= (facm + 2.0f * fac * col[1]);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +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) {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[2] *= (facm + 2.0f * fac * col[2]);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +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
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case MA_RAMP_SUB:
|
|
|
|
r_col[0] -= fac * col[0];
|
|
|
|
r_col[1] -= fac * col[1];
|
|
|
|
r_col[2] -= fac * col[2];
|
|
|
|
break;
|
|
|
|
case MA_RAMP_DIV:
|
2019-04-22 01:39:35 +02:00
|
|
|
if (col[0] != 0.0f) {
|
2019-04-17 06:17:24 +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) {
|
2019-04-17 06:17:24 +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) {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[2] = facm * (r_col[2]) + fac * (r_col[2]) / col[2];
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case MA_RAMP_DIFF:
|
|
|
|
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]);
|
|
|
|
break;
|
|
|
|
case MA_RAMP_DARK:
|
|
|
|
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;
|
|
|
|
break;
|
|
|
|
case MA_RAMP_LIGHT:
|
|
|
|
tmp = fac * col[0];
|
2019-04-22 01:39:35 +02:00
|
|
|
if (tmp > r_col[0]) {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[0] = tmp;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
tmp = fac * col[1];
|
2019-04-22 01:39:35 +02:00
|
|
|
if (tmp > r_col[1]) {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[1] = tmp;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
tmp = fac * col[2];
|
2019-04-22 01:39:35 +02:00
|
|
|
if (tmp > r_col[2]) {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[2] = tmp;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case MA_RAMP_DODGE:
|
|
|
|
if (r_col[0] != 0.0f) {
|
|
|
|
tmp = 1.0f - fac * col[0];
|
2019-04-22 01:39:35 +02:00
|
|
|
if (tmp <= 0.0f) {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[0] = 1.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else if ((tmp = (r_col[0]) / tmp) > 1.0f) {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[0] = 1.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[0] = tmp;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
if (r_col[1] != 0.0f) {
|
|
|
|
tmp = 1.0f - fac * col[1];
|
2019-04-22 01:39:35 +02:00
|
|
|
if (tmp <= 0.0f) {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[1] = 1.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else if ((tmp = (r_col[1]) / tmp) > 1.0f) {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[1] = 1.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[1] = tmp;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
if (r_col[2] != 0.0f) {
|
|
|
|
tmp = 1.0f - fac * col[2];
|
2019-04-22 01:39:35 +02:00
|
|
|
if (tmp <= 0.0f) {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[2] = 1.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else if ((tmp = (r_col[2]) / tmp) > 1.0f) {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[2] = 1.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[2] = tmp;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MA_RAMP_BURN:
|
|
|
|
tmp = facm + fac * col[0];
|
|
|
|
|
2019-04-22 01:39:35 +02:00
|
|
|
if (tmp <= 0.0f) {
|
2019-04-17 06:17:24 +02: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) {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[0] = 0.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else if (tmp > 1.0f) {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[0] = 1.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[0] = tmp;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
tmp = facm + fac * col[1];
|
2019-04-22 01:39:35 +02:00
|
|
|
if (tmp <= 0.0f) {
|
2019-04-17 06:17:24 +02: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) {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[1] = 0.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else if (tmp > 1.0f) {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[1] = 1.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[1] = tmp;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
tmp = facm + fac * col[2];
|
2019-04-22 01:39:35 +02:00
|
|
|
if (tmp <= 0.0f) {
|
2019-04-17 06:17:24 +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) {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[2] = 0.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else if (tmp > 1.0f) {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[2] = 1.0f;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[2] = tmp;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
case MA_RAMP_HUE: {
|
|
|
|
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, 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;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
rgb_to_hsv(col[0], col[1], col[2], &colH, &colS, &colV);
|
|
|
|
hsv_to_rgb(rH, (facm * rS + fac * colS), rV, r_col + 0, r_col + 1, r_col + 2);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MA_RAMP_COLOR: {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MA_RAMP_SOFT: {
|
|
|
|
float scr, scg, scb;
|
|
|
|
|
|
|
|
/* 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]);
|
|
|
|
|
|
|
|
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));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MA_RAMP_LINEAR:
|
2019-04-22 01:39:35 +02:00
|
|
|
if (col[0] > 0.5f) {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[0] = r_col[0] + fac * (2.0f * (col[0] - 0.5f));
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +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) {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[1] = r_col[1] + fac * (2.0f * (col[1] - 0.5f));
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +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) {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[2] = r_col[2] + fac * (2.0f * (col[2] - 0.5f));
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
r_col[2] = r_col[2] + fac * (2.0f * (col[2]) - 1.0f);
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02: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
|
|
|
}
|
|
|
|
|
2012-08-22 11:35:46 +02:00
|
|
|
/**
|
2012-09-26 22:05:38 +02:00
|
|
|
* \brief copy/paste buffer, if we had a proper py api that would be better
|
2012-08-22 11:35:46 +02:00
|
|
|
* \note matcopybuf.nodetree does _NOT_ use ID's
|
|
|
|
* \todo matcopybuf.nodetree's node->id's are NOT validated, this will crash!
|
|
|
|
*/
|
2011-08-28 07:06:30 +02:00
|
|
|
static Material matcopybuf;
|
2012-05-06 17:15:33 +02:00
|
|
|
static short matcopied = 0;
|
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
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
void BKE_material_copybuf_clear(void)
|
2010-01-28 18:31:11 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
memset(&matcopybuf, 0, sizeof(Material));
|
|
|
|
matcopied = 0;
|
2010-01-28 18:31:11 +01:00
|
|
|
}
|
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
void BKE_material_copybuf_free(void)
|
2010-01-28 18:31:11 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (matcopybuf.nodetree) {
|
|
|
|
ntreeFreeLocalTree(matcopybuf.nodetree);
|
|
|
|
MEM_freeN(matcopybuf.nodetree);
|
|
|
|
matcopybuf.nodetree = NULL;
|
|
|
|
}
|
2010-03-09 10:17:45 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
matcopied = 0;
|
2010-01-28 18:31:11 +01:00
|
|
|
}
|
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
void BKE_material_copybuf_copy(Main *bmain, Material *ma)
|
2010-01-28 18:31:11 +01:00
|
|
|
{
|
2019-04-22 01:39:35 +02:00
|
|
|
if (matcopied) {
|
2020-02-05 11:23:58 +01:00
|
|
|
BKE_material_copybuf_free();
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2010-01-28 18:31:11 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
memcpy(&matcopybuf, ma, sizeof(Material));
|
2010-01-28 18:31:11 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ma->nodetree != NULL) {
|
2019-08-22 16:00:59 +02:00
|
|
|
matcopybuf.nodetree = ntreeCopyTree_ex(ma->nodetree, bmain, false);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-01-16 22:59:02 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
matcopybuf.preview = NULL;
|
|
|
|
BLI_listbase_clear(&matcopybuf.gpumaterial);
|
|
|
|
/* TODO Duplicate Engine Settings and set runtime to NULL */
|
|
|
|
matcopied = 1;
|
2010-01-28 18:31:11 +01:00
|
|
|
}
|
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
void BKE_material_copybuf_paste(Main *bmain, Material *ma)
|
2010-01-28 18:31:11 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ID id;
|
2010-01-28 18:31:11 +01:00
|
|
|
|
2019-04-22 01:39:35 +02:00
|
|
|
if (matcopied == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 01:39:35 +02:00
|
|
|
}
|
2010-01-28 18:31:11 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Free gpu material before the ntree */
|
|
|
|
GPU_material_free(&ma->gpumaterial);
|
2018-03-05 00:52:19 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ma->nodetree) {
|
|
|
|
ntreeFreeNestedTree(ma->nodetree);
|
|
|
|
MEM_freeN(ma->nodetree);
|
|
|
|
}
|
2010-01-28 18:31:11 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
id = (ma->id);
|
|
|
|
memcpy(ma, &matcopybuf, sizeof(Material));
|
|
|
|
(ma->id) = id;
|
2010-01-28 18:31:11 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (matcopybuf.nodetree != NULL) {
|
2019-08-22 16:00:59 +02:00
|
|
|
ma->nodetree = ntreeCopyTree_ex(matcopybuf.nodetree, bmain, false);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2010-01-28 18:31:11 +01:00
|
|
|
}
|
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
|
|
|
|
2018-05-02 11:46:56 +02:00
|
|
|
void BKE_material_eval(struct Depsgraph *depsgraph, Material *material)
|
2017-07-20 16:13:08 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
DEG_debug_print_eval(depsgraph, __func__, material->id.name, material);
|
|
|
|
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;
|
|
|
|
static Material default_material_surface;
|
|
|
|
static Material default_material_volume;
|
|
|
|
static Material default_material_gpencil;
|
|
|
|
|
|
|
|
static Material *default_materials[] = {&default_material_empty,
|
|
|
|
&default_material_surface,
|
|
|
|
&default_material_volume,
|
|
|
|
&default_material_gpencil,
|
|
|
|
NULL};
|
|
|
|
|
|
|
|
static void material_default_gpencil_init(Material *ma)
|
|
|
|
{
|
|
|
|
strcpy(ma->id.name, "MADefault GPencil");
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
bNodeTree *ntree = ntreeAddTree(NULL, "Shader Nodetree", ntreeType_Shader->idname);
|
|
|
|
ma->nodetree = ntree;
|
2020-02-27 14:56:01 +01:00
|
|
|
ma->use_nodes = true;
|
2020-02-06 13:05:45 +01:00
|
|
|
|
|
|
|
bNode *principled = nodeAddStaticNode(NULL, ntree, SH_NODE_BSDF_PRINCIPLED);
|
|
|
|
bNodeSocket *base_color = nodeFindSocket(principled, SOCK_IN, "Base Color");
|
|
|
|
copy_v3_v3(((bNodeSocketValueRGBA *)base_color->default_value)->value, &ma->r);
|
|
|
|
|
|
|
|
bNode *output = nodeAddStaticNode(NULL, ntree, SH_NODE_OUTPUT_MATERIAL);
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
bNodeTree *ntree = ntreeAddTree(NULL, "Shader Nodetree", ntreeType_Shader->idname);
|
|
|
|
ma->nodetree = ntree;
|
2020-02-27 14:56:01 +01:00
|
|
|
ma->use_nodes = true;
|
2020-02-06 13:05:45 +01:00
|
|
|
|
|
|
|
bNode *principled = nodeAddStaticNode(NULL, ntree, SH_NODE_VOLUME_PRINCIPLED);
|
|
|
|
bNode *output = nodeAddStaticNode(NULL, ntree, SH_NODE_OUTPUT_MATERIAL);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
Material *BKE_material_default_empty(void)
|
|
|
|
{
|
|
|
|
return &default_material_empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
Material *BKE_material_default_surface(void)
|
|
|
|
{
|
|
|
|
return &default_material_surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
Material *BKE_material_default_volume(void)
|
|
|
|
{
|
|
|
|
return &default_material_volume;
|
|
|
|
}
|
|
|
|
|
|
|
|
Material *BKE_material_default_gpencil(void)
|
|
|
|
{
|
|
|
|
return &default_material_gpencil;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_material_defaults_free_gpu(void)
|
|
|
|
{
|
|
|
|
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. */
|
|
|
|
|
|
|
|
void BKE_materials_init(void)
|
|
|
|
{
|
|
|
|
for (int i = 0; default_materials[i]; i++) {
|
|
|
|
BKE_material_init(default_materials[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
material_default_surface_init(&default_material_surface);
|
|
|
|
material_default_volume_init(&default_material_volume);
|
|
|
|
material_default_gpencil_init(&default_material_gpencil);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_materials_exit(void)
|
|
|
|
{
|
|
|
|
for (int i = 0; default_materials[i]; i++) {
|
|
|
|
BKE_material_free(default_materials[i]);
|
|
|
|
}
|
|
|
|
}
|