2011-02-18 14:05:18 +01: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.
|
|
|
|
*/
|
|
|
|
|
2012-02-17 19:59:41 +01:00
|
|
|
#ifndef __BKE_MATERIAL_H__
|
|
|
|
#define __BKE_MATERIAL_H__
|
2002-10-12 13:37:38 +02:00
|
|
|
|
2019-02-17 22:08:12 +01:00
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
|
|
|
* \brief General operations, lookup, etc. for materials.
|
2011-02-18 14:05:18 +01:00
|
|
|
*/
|
2002-10-12 13:37:38 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2019-01-28 11:08:24 +01:00
|
|
|
struct ID;
|
2010-08-01 14:47:49 +02:00
|
|
|
struct Main;
|
2002-10-12 13:37:38 +02: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 07:11:37 +02:00
|
|
|
struct Scene;
|
2019-08-14 17:34:58 +02:00
|
|
|
struct bNode;
|
2002-10-12 13:37:38 +02:00
|
|
|
|
2020-02-06 13:05:45 +01:00
|
|
|
/* Module */
|
2009-06-24 16:07:48 +02:00
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
void BKE_materials_init(void);
|
|
|
|
void BKE_materials_exit(void);
|
2020-02-06 13:05:45 +01:00
|
|
|
|
|
|
|
/* Materials */
|
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
void BKE_object_materials_test(struct Main *bmain, struct Object *ob, struct ID *id);
|
|
|
|
void BKE_objects_materials_test_all(struct Main *bmain, struct ID *id);
|
2020-03-04 22:08:23 +01:00
|
|
|
void BKE_object_material_resize(struct Main *bmain,
|
2019-04-17 06:17:24 +02:00
|
|
|
struct Object *ob,
|
|
|
|
const short totcol,
|
|
|
|
bool do_id_user);
|
2020-03-04 22:08:23 +01:00
|
|
|
void BKE_object_material_remap(struct Object *ob, const unsigned int *remap);
|
|
|
|
void BKE_object_material_remap_calc(struct Object *ob_dst,
|
2019-04-17 06:17:24 +02:00
|
|
|
struct Object *ob_src,
|
|
|
|
short *remap_src_to_dst);
|
2013-02-05 13:46:15 +01:00
|
|
|
struct Material *BKE_material_add(struct Main *bmain, const char *name);
|
2020-02-05 11:23:58 +01:00
|
|
|
struct Material *BKE_gpencil_material_add(struct Main *bmain, const char *name);
|
2017-06-14 22:36:30 +02:00
|
|
|
struct Material *BKE_material_copy(struct Main *bmain, const struct Material *ma);
|
2018-01-10 23:55:41 +01:00
|
|
|
struct Material *BKE_material_localize(struct Material *ma);
|
2020-02-05 11:23:58 +01:00
|
|
|
void BKE_gpencil_material_attr_init(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 15:32:21 +01:00
|
|
|
|
2013-04-03 17:04:24 +02:00
|
|
|
/* UNUSED */
|
|
|
|
// void automatname(struct Material *);
|
2009-06-24 16:07:48 +02:00
|
|
|
|
|
|
|
/* material slots */
|
|
|
|
|
2020-03-04 22:08:23 +01:00
|
|
|
struct Material ***BKE_object_material_array_p(struct Object *ob);
|
|
|
|
short *BKE_object_material_len_p(struct Object *ob);
|
|
|
|
struct Material ***BKE_id_material_array_p(struct ID *id); /* same but for ID's */
|
|
|
|
short *BKE_id_material_len_p(struct ID *id);
|
2010-09-03 09:25:37 +02:00
|
|
|
|
2012-08-12 19:12:07 +02:00
|
|
|
enum {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* use existing link option */
|
|
|
|
BKE_MAT_ASSIGN_EXISTING,
|
|
|
|
BKE_MAT_ASSIGN_USERPREF,
|
|
|
|
BKE_MAT_ASSIGN_OBDATA,
|
|
|
|
BKE_MAT_ASSIGN_OBJECT,
|
2012-08-12 19:12:07 +02:00
|
|
|
};
|
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
struct Material **BKE_object_material_get_p(struct Object *ob, short act);
|
|
|
|
struct Material *BKE_object_material_get(struct Object *ob, short act);
|
|
|
|
void BKE_id_material_assign(struct Main *bmain, struct ID *id, struct Material *ma, short act);
|
|
|
|
void BKE_object_material_assign(
|
2019-04-17 06:17:24 +02:00
|
|
|
struct Main *bmain, struct Object *ob, struct Material *ma, short act, int assign_type);
|
2020-02-05 11:25:50 +01:00
|
|
|
void BKE_object_material_array_assign(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 15:32:21 +01:00
|
|
|
|
2016-07-20 21:56:12 +02:00
|
|
|
short BKE_object_material_slot_find_index(struct Object *ob, struct Material *ma);
|
2019-04-17 06:17:24 +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);
|
2019-07-31 21:04:52 +02:00
|
|
|
bool BKE_object_material_slot_used(struct ID *id, short actcol);
|
2009-06-24 16:07:48 +02:00
|
|
|
|
2020-02-05 11:23:58 +01:00
|
|
|
struct Material *BKE_gpencil_material(struct Object *ob, short act);
|
|
|
|
struct MaterialGPencilStyle *BKE_gpencil_material_settings(struct Object *ob, short act);
|
2018-07-31 10:22:19 +02:00
|
|
|
|
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);
|
2019-07-31 16:37:03 +02:00
|
|
|
struct bNode *BKE_texpaint_slot_material_find_node(struct Material *ma, short texpaint_slot);
|
2014-07-21 12:02:05 +02:00
|
|
|
|
2010-09-03 09:25:37 +02:00
|
|
|
/* rna api */
|
2020-03-04 22:08:23 +01:00
|
|
|
void BKE_id_material_resize(struct Main *bmain, struct ID *id, short totcol, bool do_id_user);
|
|
|
|
void BKE_id_material_append(struct Main *bmain, struct ID *id, struct Material *ma);
|
|
|
|
struct Material *BKE_id_material_pop(struct Main *bmain,
|
2019-04-17 06:17:24 +02:00
|
|
|
struct ID *id,
|
2019-08-14 15:29:46 +02:00
|
|
|
/* index is an int because of RNA. */
|
2019-08-16 14:36:57 +02:00
|
|
|
int index);
|
2020-03-04 22:08:23 +01:00
|
|
|
void BKE_id_material_clear(struct Main *bmain, struct ID *id);
|
2009-06-24 16:07:48 +02:00
|
|
|
/* rendering */
|
2007-11-28 19:43:09 +01:00
|
|
|
|
2012-05-12 22:39:39 +02: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
|
|
|
|
2010-01-28 18:31:11 +01:00
|
|
|
/* copy/paste */
|
2020-02-05 11:23:58 +01:00
|
|
|
void BKE_material_copybuf_clear(void);
|
|
|
|
void BKE_material_copybuf_free(void);
|
|
|
|
void BKE_material_copybuf_copy(struct Main *bmain, struct Material *ma);
|
|
|
|
void BKE_material_copybuf_paste(struct Main *bmain, struct Material *ma);
|
2010-01-28 18:31:11 +01:00
|
|
|
|
2020-02-06 13:05:45 +01:00
|
|
|
/* Default Materials */
|
|
|
|
|
|
|
|
struct Material *BKE_material_default_empty(void);
|
|
|
|
struct Material *BKE_material_default_surface(void);
|
|
|
|
struct Material *BKE_material_default_volume(void);
|
|
|
|
struct Material *BKE_material_default_gpencil(void);
|
|
|
|
|
|
|
|
void BKE_material_defaults_free_gpu(void);
|
|
|
|
|
2019-06-04 16:48:47 +02:00
|
|
|
/* Dependency graph evaluation. */
|
2017-07-20 16:13:08 +02:00
|
|
|
|
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
|
|
|
|
2002-10-12 13:37:38 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|