2011-02-18 13:05:18 +00:00
|
|
|
/*
|
2002-10-12 11:37:38 +00: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 19:13:47 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00: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 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#ifndef __BKE_MATERIAL_H__
|
|
|
|
#define __BKE_MATERIAL_H__
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
|
|
|
* \brief General operations, lookup, etc. for materials.
|
2011-02-18 13:05:18 +00:00
|
|
|
*/
|
2002-10-12 11:37:38 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2019-01-28 21:08:24 +11:00
|
|
|
struct ID;
|
2010-08-01 12:47:49 +00:00
|
|
|
struct Main;
|
2002-10-12 11:37:38 +00:00
|
|
|
struct Material;
|
|
|
|
struct Object;
|
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 05:11:37 +00:00
|
|
|
struct Scene;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-06-24 14:07:48 +00:00
|
|
|
/* materials */
|
|
|
|
|
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 22:05:47 +00:00
|
|
|
void init_def_material(void);
|
2015-12-28 00:33:07 +01:00
|
|
|
void BKE_material_free(struct Material *ma);
|
2018-05-29 15:49:21 +02:00
|
|
|
void test_object_materials(struct Main *bmain, struct Object *ob, struct ID *id);
|
2016-07-08 14:36:25 +02:00
|
|
|
void test_all_objects_materials(struct Main *bmain, struct ID *id);
|
2016-08-12 14:59:11 +02:00
|
|
|
void BKE_material_resize_object(struct Main *bmain, struct Object *ob, const short totcol, bool do_id_user);
|
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(struct Material *ma);
|
2015-04-28 07:24:56 +10:00
|
|
|
void BKE_material_remap_object(struct Object *ob, const unsigned int *remap);
|
2015-12-13 00:34:09 +11:00
|
|
|
void BKE_material_remap_object_calc(struct Object *ob_dst, struct Object *ob_src, short *remap_src_to_dst);
|
2013-02-05 12:46:15 +00:00
|
|
|
struct Material *BKE_material_add(struct Main *bmain, const char *name);
|
2018-07-31 10:22:19 +02:00
|
|
|
struct Material *BKE_material_add_gpencil(struct Main *bmain, const char *name);
|
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(struct Main *bmain, struct Material *ma_dst, const struct Material *ma_src, const int flag);
|
2017-06-14 22:36:30 +02:00
|
|
|
struct Material *BKE_material_copy(struct Main *bmain, const struct Material *ma);
|
2018-01-11 09:55:41 +11:00
|
|
|
struct Material *BKE_material_localize(struct Material *ma);
|
2009-10-19 14:03:02 +00:00
|
|
|
struct Material *give_node_material(struct Material *ma); /* returns node material or self */
|
2016-07-20 19:49:45 +02:00
|
|
|
void BKE_material_make_local(struct Main *bmain, struct Material *ma, const bool lib_local);
|
2018-07-31 10:22:19 +02:00
|
|
|
void BKE_material_init_gpencil_settings(struct Material *ma);
|
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 14:32:21 +00:00
|
|
|
|
2013-04-03 15:04:24 +00:00
|
|
|
/* UNUSED */
|
|
|
|
// void automatname(struct Material *);
|
2009-06-24 14:07:48 +00:00
|
|
|
|
|
|
|
/* material slots */
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
struct Material ***give_matarar(struct Object *ob);
|
|
|
|
short *give_totcolp(struct Object *ob);
|
2010-09-03 07:25:37 +00:00
|
|
|
struct Material ***give_matarar_id(struct ID *id); /* same but for ID's */
|
|
|
|
short *give_totcolp_id(struct ID *id);
|
|
|
|
|
2012-08-12 17:12:07 +00:00
|
|
|
enum {
|
2015-08-06 18:04:13 +10:00
|
|
|
/* use existing link option */
|
|
|
|
BKE_MAT_ASSIGN_EXISTING,
|
2012-08-12 17:12:07 +00:00
|
|
|
BKE_MAT_ASSIGN_USERPREF,
|
|
|
|
BKE_MAT_ASSIGN_OBDATA,
|
2019-02-03 14:01:45 +11:00
|
|
|
BKE_MAT_ASSIGN_OBJECT,
|
2012-08-12 17:12:07 +00:00
|
|
|
};
|
|
|
|
|
2019-01-03 12:15:03 +11:00
|
|
|
struct Material **give_current_material_p(struct Object *ob, short act);
|
|
|
|
struct Material *give_current_material(struct Object *ob, short act);
|
2018-05-29 15:49:21 +02:00
|
|
|
void assign_material_id(struct Main *bmain, struct ID *id, struct Material *ma, short act);
|
|
|
|
void assign_material(struct Main *bmain, struct Object *ob, struct Material *ma, short act, int assign_type);
|
|
|
|
void assign_matarar(struct Main *bmain, struct Object *ob, struct Material ***matar, short totcol);
|
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 14:32:21 +00:00
|
|
|
|
2016-07-21 05:56:12 +10:00
|
|
|
short BKE_object_material_slot_find_index(struct Object *ob, struct Material *ma);
|
2018-05-29 15:49:21 +02:00
|
|
|
bool BKE_object_material_slot_add(struct Main *bmain, struct Object *ob);
|
|
|
|
bool BKE_object_material_slot_remove(struct Main *bmain, struct Object *ob);
|
2009-06-24 14:07:48 +00:00
|
|
|
|
2018-07-31 10:22:19 +02:00
|
|
|
struct MaterialGPencilStyle *BKE_material_gpencil_settings_get(struct Object *ob, short act);
|
|
|
|
|
2019-03-07 19:39:50 +01:00
|
|
|
void BKE_texpaint_slot_refresh_cache(struct Scene *scene, struct Material *ma);
|
|
|
|
void BKE_texpaint_slots_refresh_object(struct Scene *scene, struct Object *ob);
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2010-09-03 07:25:37 +00:00
|
|
|
/* rna api */
|
2016-08-12 14:59:11 +02:00
|
|
|
void BKE_material_resize_id(struct Main *bmain, struct ID *id, short totcol, bool do_id_user);
|
|
|
|
void BKE_material_append_id(struct Main *bmain, struct ID *id, struct Material *ma);
|
|
|
|
struct Material *BKE_material_pop_id(struct Main *bmain, struct ID *id, int index, bool update_data); /* index is an int because of RNA */
|
|
|
|
void BKE_material_clear_id(struct Main *bmain, struct ID *id, bool update_data);
|
2009-06-24 14:07:48 +00:00
|
|
|
/* rendering */
|
2007-11-28 18:43:09 +00:00
|
|
|
|
2012-05-12 20:39:39 +00: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 22:05:47 +00:00
|
|
|
|
2010-01-28 17:31:11 +00:00
|
|
|
/* copy/paste */
|
|
|
|
void clear_matcopybuf(void);
|
|
|
|
void free_matcopybuf(void);
|
2018-05-29 15:49:21 +02:00
|
|
|
void copy_matcopybuf(struct Main *bmain, struct Material *ma);
|
|
|
|
void paste_matcopybuf(struct Main *bmain, struct Material *ma);
|
2010-01-28 17:31:11 +00:00
|
|
|
|
2017-07-20 16:13:08 +02:00
|
|
|
/* Evaluation. */
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
struct Depsgraph;
|
2017-07-20 16:13:08 +02:00
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
void BKE_material_eval(struct Depsgraph *depsgraph, struct Material *material);
|
2017-07-20 16:13:08 +02:00
|
|
|
|
2019-02-23 19:17:30 +11:00
|
|
|
extern struct Material defmaterial;
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|