2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2009-12-30 14:37:25 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
2009-12-30 14:37:25 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2004 by Blender Foundation
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
|
*
|
2011-06-05 20:54:04 +00:00
|
|
|
* Contributor(s): Morten Mikkelsen,
|
|
|
|
|
* Sergey Sharybin
|
2009-12-30 14:37:25 +00:00
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
2011-02-27 20:29:51 +00:00
|
|
|
/** \file blender/editors/object/object_bake.c
|
|
|
|
|
* \ingroup edobj
|
|
|
|
|
*/
|
|
|
|
|
|
2009-12-30 14:37:25 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
|
#include "DNA_space_types.h"
|
|
|
|
|
#include "DNA_world_types.h"
|
2011-06-05 20:54:04 +00:00
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
|
#include "DNA_meshdata_types.h"
|
2009-12-30 14:37:25 +00:00
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
|
#include "BLI_threads.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2011-06-05 20:54:04 +00:00
|
|
|
#include "BLI_math.h"
|
|
|
|
|
#include "BLI_math_geom.h"
|
2009-12-30 14:37:25 +00:00
|
|
|
|
|
|
|
|
#include "BKE_blender.h"
|
2011-11-04 01:15:04 +00:00
|
|
|
#include "BKE_screen.h"
|
2009-12-30 14:37:25 +00:00
|
|
|
#include "BKE_context.h"
|
|
|
|
|
#include "BKE_global.h"
|
|
|
|
|
#include "BKE_image.h"
|
|
|
|
|
#include "BKE_main.h"
|
2010-09-23 18:26:33 +00:00
|
|
|
#include "BKE_multires.h"
|
2009-12-30 14:37:25 +00:00
|
|
|
#include "BKE_report.h"
|
2011-06-05 20:54:04 +00:00
|
|
|
#include "BKE_cdderivedmesh.h"
|
|
|
|
|
#include "BKE_modifier.h"
|
|
|
|
|
#include "BKE_DerivedMesh.h"
|
2013-04-24 13:53:09 +00:00
|
|
|
#include "BKE_depsgraph.h"
|
|
|
|
|
#include "BKE_mesh.h"
|
2013-05-08 13:23:17 +00:00
|
|
|
#include "BKE_scene.h"
|
2009-12-30 14:37:25 +00:00
|
|
|
|
|
|
|
|
#include "RE_pipeline.h"
|
|
|
|
|
#include "RE_shader_ext.h"
|
2012-12-18 17:46:26 +00:00
|
|
|
#include "RE_multires_bake.h"
|
2009-12-30 14:37:25 +00:00
|
|
|
|
|
|
|
|
#include "PIL_time.h"
|
|
|
|
|
|
|
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
|
#include "IMB_imbuf.h"
|
Color Management, Stage 2: Switch color pipeline to use OpenColorIO
Replace old color pipeline which was supporting linear/sRGB color spaces
only with OpenColorIO-based pipeline.
This introduces two configurable color spaces:
- Input color space for images and movie clips. This space is used to convert
images/movies from color space in which file is saved to Blender's linear
space (for float images, byte images are not internally converted, only input
space is stored for such images and used later).
This setting could be found in image/clip data block settings.
- Display color space which defines space in which particular display is working.
This settings could be found in scene's Color Management panel.
When render result is being displayed on the screen, apart from converting image
to display space, some additional conversions could happen.
This conversions are:
- View, which defines tone curve applying before display transformation.
These are different ways to view the image on the same display device.
For example it could be used to emulate film view on sRGB display.
- Exposure affects on image exposure before tone map is applied.
- Gamma is post-display gamma correction, could be used to match particular
display gamma.
- RGB curves are user-defined curves which are applying before display
transformation, could be used for different purposes.
All this settings by default are only applying on render result and does not
affect on other images. If some particular image needs to be affected by this
transformation, "View as Render" setting of image data block should be set to
truth. Movie clips are always affected by all display transformations.
This commit also introduces configurable color space in which sequencer is
working. This setting could be found in scene's Color Management panel and
it should be used if such stuff as grading needs to be done in color space
different from sRGB (i.e. when Film view on sRGB display is use, using VD16
space as sequencer's internal space would make grading working in space
which is close to the space using for display).
Some technical notes:
- Image buffer's float buffer is now always in linear space, even if it was
created from 16bit byte images.
- Space of byte buffer is stored in image buffer's rect_colorspace property.
- Profile of image buffer was removed since it's not longer meaningful.
- OpenGL and GLSL is supposed to always work in sRGB space. It is possible
to support other spaces, but it's quite large project which isn't so
much important.
- Legacy Color Management option disabled is emulated by using None display.
It could have some regressions, but there's no clear way to avoid them.
- If OpenColorIO is disabled on build time, it should make blender behaving
in the same way as previous release with color management enabled.
More details could be found at this page (more details would be added soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Color_Management
--
Thanks to Xavier Thomas, Lukas Toene for initial work on OpenColorIO
integration and to Brecht van Lommel for some further development and code/
usecase review!
2012-09-15 10:05:07 +00:00
|
|
|
#include "IMB_colormanagement.h"
|
2009-12-30 14:37:25 +00:00
|
|
|
|
|
|
|
|
#include "GPU_draw.h" /* GPU_free_image */
|
|
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
2010-09-23 18:26:33 +00:00
|
|
|
#include "ED_object.h"
|
Bake API - bpy.ops.object.bake()
New operator that can calls a bake function to the current render engine when available. This commit provides no feature for the users, but allows external engines to be accessed by the operator and be integrated with the baking api.
The API itself is simple. Blender sends a populated array of BakePixels to the renderer, and gets back an array of floats with the result.
The Blender Internal (and multires) system is still running independent, but we eventually will pipe it through the API as well. Cycles baking will come next as a separated commit
Python Operator:
----------------
The operator can be called with some arguments, or a user interface can be created for it. In that case the arguments can be ommited and the interface can expose the settings from bpy.context.scene.render.bake
bpy.ops.object.bake(type='COMBINED', filepath="", width=512, height=512, margin=16, use_selected_to_active=False, cage_extrusion=0, cage="", normal_space='TANGENT', normal_r='POS_X', normal_g='POS_Y', normal_b='POS_Z', save_mode='INTERNAL', use_clear=False, use_split_materials=False, use_automatic_name=False)
Note: external save mode is currently disabled.
Supported Features:
------------------
* Margin - Baked result is extended this many pixels beyond the border of each UV "island," to soften seams in the texture.
* Selected to Active - bake shading on the surface of selected object to the active object. The rays are cast from the lowpoly object inwards towards the highpoly object. If the highpoly object is not entirely involved by the lowpoly object, you can tweak the rays start point with Cage Extrusion. For even more control of the cage you can use a Cage object.
* Cage Extrusion - distance to use for the inward ray cast when using selected to active
* Custom Cage - object to use as cage (instead of the lowpoly object).
* Normal swizzle - change the axis that gets mapped to RGB
* Normal space - save as tangent or object normal spaces
Supported Passes:
-----------------
Any pass that is supported by Blender renderlayer system. Though it's up to the external engine to provide a valid enum with its supported passes. Normal passes get a special treatment since we post-process them to converted and "swizzled"
Development Notes for External Engines:
---------------------------------------
(read them in bake_api.c)
* For a complete implementation example look at the Cycles Bake commit (next).
Review: D421
Reviewed by: Campbell Barton, Brecht van Lommel, Sergey Sharybin, Thomas Dinge
Normal map pipeline "consulting" by Andy Davies (metalliandy)
Original design by Brecht van Lommel.
The entire commit history can be found on the branch: bake-cycles
2014-01-02 19:05:07 -02:00
|
|
|
#include "ED_screen.h"
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2011-02-14 17:55:27 +00:00
|
|
|
#include "object_intern.h"
|
|
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
/* ****************** multires BAKING ********************** */
|
|
|
|
|
|
|
|
|
|
/* holder of per-object data needed for bake job
|
2012-03-03 16:31:46 +00:00
|
|
|
* needed to make job totally thread-safe */
|
2011-06-05 20:54:04 +00:00
|
|
|
typedef struct MultiresBakerJobData {
|
|
|
|
|
struct MultiresBakerJobData *next, *prev;
|
|
|
|
|
DerivedMesh *lores_dm, *hires_dm;
|
2013-10-09 15:51:14 +00:00
|
|
|
bool simple;
|
|
|
|
|
int lvl, tot_lvl;
|
2012-12-26 20:38:20 +00:00
|
|
|
ListBase images;
|
2011-06-05 20:54:04 +00:00
|
|
|
} MultiresBakerJobData;
|
|
|
|
|
|
|
|
|
|
/* data passing to multires-baker job */
|
|
|
|
|
typedef struct {
|
|
|
|
|
ListBase data;
|
2013-10-09 15:51:14 +00:00
|
|
|
bool bake_clear; /* Clear the images before baking */
|
|
|
|
|
int bake_filter; /* Bake-filter, aka margin */
|
|
|
|
|
short mode; /* mode of baking (displacement, normals, AO) */
|
|
|
|
|
bool use_lores_mesh; /* Use low-resolution mesh when baking displacement maps */
|
|
|
|
|
int number_of_rays; /* Number of rays to be cast when doing AO baking */
|
|
|
|
|
float bias; /* Bias between object and start ray point when doing AO baking */
|
|
|
|
|
int raytrace_structure; /* Optimization structure to be used for AO baking */
|
|
|
|
|
int octree_resolution; /* Reslution of octotree when using octotree optimization structure */
|
|
|
|
|
int threads; /* Number of threads to be used for baking */
|
|
|
|
|
float user_scale; /* User scale used to scale displacement when baking derivative map. */
|
2011-06-05 20:54:04 +00:00
|
|
|
} MultiresBakeJob;
|
|
|
|
|
|
2013-07-31 03:44:45 +00:00
|
|
|
static bool multiresbake_check(bContext *C, wmOperator *op)
|
2011-09-28 05:53:40 +00:00
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2011-06-05 20:54:04 +00:00
|
|
|
Object *ob;
|
|
|
|
|
Mesh *me;
|
|
|
|
|
MultiresModifierData *mmd;
|
2013-07-31 03:44:45 +00:00
|
|
|
bool ok = true;
|
|
|
|
|
int a;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-04-30 16:22:40 +00:00
|
|
|
CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases)
|
|
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
ob = base->object;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ob->type != OB_MESH) {
|
2012-10-14 15:29:09 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "Baking of multires data only works with an active mesh object");
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2013-07-31 03:44:45 +00:00
|
|
|
ok = false;
|
2011-06-05 20:54:04 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
me = (Mesh *)ob->data;
|
|
|
|
|
mmd = get_multires_modifier(scene, ob, 0);
|
2011-06-05 20:54:04 +00:00
|
|
|
|
|
|
|
|
/* Multi-resolution should be and be last in the stack */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ok && mmd) {
|
2011-06-05 20:54:04 +00:00
|
|
|
ModifierData *md;
|
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
ok = mmd->totlvl > 0;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
for (md = (ModifierData *)mmd->modifier.next; md && ok; md = md->next) {
|
2011-06-05 20:54:04 +00:00
|
|
|
if (modifier_isEnabled(scene, md, eModifierMode_Realtime)) {
|
2013-07-31 03:44:45 +00:00
|
|
|
ok = false;
|
2011-06-05 20:54:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
else {
|
2013-07-31 03:44:45 +00:00
|
|
|
ok = false;
|
2013-03-09 03:46:30 +00:00
|
|
|
}
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!ok) {
|
2011-06-05 20:54:04 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "Multires data baking requires multi-resolution object");
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!me->mtpoly) {
|
2011-06-05 20:54:04 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "Mesh should be unwrapped before multires data baking");
|
|
|
|
|
|
2013-07-31 03:44:45 +00:00
|
|
|
ok = false;
|
2012-02-19 22:55:37 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
a = me->totpoly;
|
2011-06-05 20:54:04 +00:00
|
|
|
while (ok && a--) {
|
2012-02-19 22:55:37 +00:00
|
|
|
Image *ima = me->mtpoly[a].tpage;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!ima) {
|
2011-06-05 20:54:04 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "You should have active texture to use multires baker");
|
|
|
|
|
|
2013-07-31 03:44:45 +00:00
|
|
|
ok = false;
|
2012-02-19 22:55:37 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-11-15 15:59:58 +00:00
|
|
|
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL);
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!ibuf) {
|
2012-10-13 13:40:05 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "Baking should happen to image with image buffer");
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2013-07-31 03:44:45 +00:00
|
|
|
ok = false;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-04-28 15:42:27 +00:00
|
|
|
if (ibuf->rect == NULL && ibuf->rect_float == NULL)
|
2013-07-31 03:44:45 +00:00
|
|
|
ok = false;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
if (ibuf->rect_float && !(ibuf->channels == 0 || ibuf->channels == 4))
|
2013-07-31 03:44:45 +00:00
|
|
|
ok = false;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!ok)
|
2011-06-05 20:54:04 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "Baking to unsupported image type");
|
|
|
|
|
}
|
2012-11-15 15:59:58 +00:00
|
|
|
|
|
|
|
|
BKE_image_release_ibuf(ima, ibuf, NULL);
|
2011-06-05 20:54:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!ok)
|
2011-06-05 20:54:04 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
CTX_DATA_END;
|
|
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static DerivedMesh *multiresbake_create_loresdm(Scene *scene, Object *ob, int *lvl)
|
|
|
|
|
{
|
|
|
|
|
DerivedMesh *dm;
|
2012-04-28 15:42:27 +00:00
|
|
|
MultiresModifierData *mmd = get_multires_modifier(scene, ob, 0);
|
|
|
|
|
Mesh *me = (Mesh *)ob->data;
|
2013-10-29 16:43:56 +00:00
|
|
|
MultiresModifierData tmp_mmd = *mmd;
|
2013-12-26 08:26:41 +11:00
|
|
|
DerivedMesh *cddm = CDDM_from_mesh(me);
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2013-10-29 16:43:56 +00:00
|
|
|
if (mmd->lvl > 0) {
|
|
|
|
|
*lvl = mmd->lvl;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2013-10-29 16:43:56 +00:00
|
|
|
*lvl = 1;
|
|
|
|
|
tmp_mmd.simple = true;
|
|
|
|
|
}
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2013-10-29 16:43:56 +00:00
|
|
|
DM_set_only_copy(cddm, CD_MASK_BAREMESH | CD_MASK_MTFACE);
|
2012-12-18 17:46:42 +00:00
|
|
|
|
2013-10-29 16:43:56 +00:00
|
|
|
tmp_mmd.lvl = *lvl;
|
|
|
|
|
tmp_mmd.sculptlvl = *lvl;
|
|
|
|
|
dm = multires_make_derived_from_derived(cddm, &tmp_mmd, ob, 0);
|
|
|
|
|
cddm->release(cddm);
|
2011-06-05 20:54:04 +00:00
|
|
|
|
|
|
|
|
return dm;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-09 15:51:14 +00:00
|
|
|
static DerivedMesh *multiresbake_create_hiresdm(Scene *scene, Object *ob, int *lvl, bool *simple)
|
2011-06-05 20:54:04 +00:00
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
Mesh *me = (Mesh *)ob->data;
|
|
|
|
|
MultiresModifierData *mmd = get_multires_modifier(scene, ob, 0);
|
|
|
|
|
MultiresModifierData tmp_mmd = *mmd;
|
2013-12-26 08:26:41 +11:00
|
|
|
DerivedMesh *cddm = CDDM_from_mesh(me);
|
2011-06-05 20:54:04 +00:00
|
|
|
DerivedMesh *dm;
|
|
|
|
|
|
2012-12-18 17:46:42 +00:00
|
|
|
DM_set_only_copy(cddm, CD_MASK_BAREMESH);
|
|
|
|
|
|
|
|
|
|
/* TODO: DM_set_only_copy wouldn't set mask for loop and poly data,
|
|
|
|
|
* but we really need BAREMESH only to save lots of memory
|
|
|
|
|
*/
|
|
|
|
|
CustomData_set_only_copy(&cddm->loopData, CD_MASK_BAREMESH);
|
|
|
|
|
CustomData_set_only_copy(&cddm->polyData, CD_MASK_BAREMESH);
|
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
*lvl = mmd->totlvl;
|
2013-10-09 15:51:14 +00:00
|
|
|
*simple = mmd->simple != 0;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
tmp_mmd.lvl = mmd->totlvl;
|
|
|
|
|
tmp_mmd.sculptlvl = mmd->totlvl;
|
2012-10-26 11:30:00 +00:00
|
|
|
dm = multires_make_derived_from_derived(cddm, &tmp_mmd, ob, 0);
|
2011-06-05 20:54:04 +00:00
|
|
|
cddm->release(cddm);
|
|
|
|
|
|
|
|
|
|
return dm;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 15:06:13 +00:00
|
|
|
typedef enum ClearFlag {
|
2013-09-20 10:14:54 +00:00
|
|
|
CLEAR_TANGENT_NORMAL = 1,
|
|
|
|
|
CLEAR_DISPLACEMENT = 2
|
2013-02-20 15:06:13 +00:00
|
|
|
} ClearFlag;
|
|
|
|
|
|
|
|
|
|
|
2013-09-20 10:14:58 +00:00
|
|
|
static void clear_single_image(Image *image, ClearFlag flag)
|
2011-06-05 20:54:04 +00:00
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
const float vec_alpha[4] = {0.0f, 0.0f, 0.0f, 0.0f};
|
|
|
|
|
const float vec_solid[4] = {0.0f, 0.0f, 0.0f, 1.0f};
|
2013-02-20 15:06:13 +00:00
|
|
|
const float nor_alpha[4] = {0.5f, 0.5f, 1.0f, 0.0f};
|
|
|
|
|
const float nor_solid[4] = {0.5f, 0.5f, 1.0f, 1.0f};
|
2013-09-20 10:14:54 +00:00
|
|
|
const float disp_alpha[4] = {0.5f, 0.5f, 0.5f, 0.0f};
|
|
|
|
|
const float disp_solid[4] = {0.5f, 0.5f, 0.5f, 1.0f};
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2013-09-20 10:14:58 +00:00
|
|
|
if ((image->id.flag & LIB_DOIT) == 0) {
|
|
|
|
|
ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
if (flag == CLEAR_TANGENT_NORMAL)
|
|
|
|
|
IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? nor_alpha : nor_solid);
|
|
|
|
|
else if (flag == CLEAR_DISPLACEMENT)
|
|
|
|
|
IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? disp_alpha : disp_solid);
|
|
|
|
|
else
|
|
|
|
|
IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? vec_alpha : vec_solid);
|
|
|
|
|
|
|
|
|
|
image->id.flag |= LIB_DOIT;
|
|
|
|
|
|
|
|
|
|
BKE_image_release_ibuf(image, ibuf, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void clear_images(MTFace *mtface, int totface, ClearFlag flag)
|
|
|
|
|
{
|
|
|
|
|
int a;
|
|
|
|
|
|
|
|
|
|
for (a = 0; a < totface; a++) {
|
2012-04-28 15:42:27 +00:00
|
|
|
mtface[a].tpage->id.flag &= ~LIB_DOIT;
|
2013-09-20 10:14:58 +00:00
|
|
|
}
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
for (a = 0; a < totface; a++) {
|
2013-09-20 10:14:58 +00:00
|
|
|
clear_single_image(mtface[a].tpage, flag);
|
|
|
|
|
}
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2013-09-20 10:14:58 +00:00
|
|
|
for (a = 0; a < totface; a++) {
|
|
|
|
|
mtface[a].tpage->id.flag &= ~LIB_DOIT;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2013-09-20 10:14:58 +00:00
|
|
|
static void clear_images_poly(MTexPoly *mtpoly, int totpoly, ClearFlag flag)
|
|
|
|
|
{
|
|
|
|
|
int a;
|
2013-02-20 15:06:13 +00:00
|
|
|
|
2013-09-20 10:14:58 +00:00
|
|
|
for (a = 0; a < totpoly; a++) {
|
|
|
|
|
mtpoly[a].tpage->id.flag &= ~LIB_DOIT;
|
|
|
|
|
}
|
2012-11-15 15:59:58 +00:00
|
|
|
|
2013-09-20 10:14:58 +00:00
|
|
|
for (a = 0; a < totpoly; a++) {
|
|
|
|
|
clear_single_image(mtpoly[a].tpage, flag);
|
2011-06-05 20:54:04 +00:00
|
|
|
}
|
|
|
|
|
|
2013-09-20 10:14:58 +00:00
|
|
|
for (a = 0; a < totpoly; a++) {
|
|
|
|
|
mtpoly[a].tpage->id.flag &= ~LIB_DOIT;
|
|
|
|
|
}
|
2011-06-05 20:54:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int multiresbake_image_exec_locked(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
Object *ob;
|
2012-04-28 15:42:27 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
|
int objects_baked = 0;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!multiresbake_check(C, op))
|
2011-06-05 20:54:04 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
if (scene->r.bake_flag & R_BAKE_CLEAR) { /* clear images */
|
2012-04-30 16:22:40 +00:00
|
|
|
CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases)
|
|
|
|
|
{
|
2011-06-05 20:54:04 +00:00
|
|
|
Mesh *me;
|
2013-09-20 10:14:54 +00:00
|
|
|
ClearFlag clear_flag = 0;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
ob = base->object;
|
|
|
|
|
me = (Mesh *)ob->data;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2013-09-20 10:14:54 +00:00
|
|
|
if (scene->r.bake_mode == RE_BAKE_NORMALS) {
|
|
|
|
|
clear_flag = CLEAR_TANGENT_NORMAL;
|
|
|
|
|
}
|
2013-10-09 15:51:14 +00:00
|
|
|
else if (ELEM(scene->r.bake_mode, RE_BAKE_DISPLACEMENT, RE_BAKE_DERIVATIVE)) {
|
2013-09-20 10:14:54 +00:00
|
|
|
clear_flag = CLEAR_DISPLACEMENT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clear_images(me->mtface, me->totface, clear_flag);
|
2013-09-20 10:14:58 +00:00
|
|
|
clear_images_poly(me->mtpoly, me->totpoly, clear_flag);
|
2011-06-05 20:54:04 +00:00
|
|
|
}
|
|
|
|
|
CTX_DATA_END;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-30 16:22:40 +00:00
|
|
|
CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases)
|
|
|
|
|
{
|
2013-03-22 05:34:10 +00:00
|
|
|
MultiresBakeRender bkr = {NULL};
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
ob = base->object;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2011-11-30 11:04:57 +00:00
|
|
|
multires_force_update(ob);
|
|
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
/* copy data stored in job descriptor */
|
2012-04-28 15:42:27 +00:00
|
|
|
bkr.bake_filter = scene->r.bake_filter;
|
|
|
|
|
bkr.mode = scene->r.bake_mode;
|
|
|
|
|
bkr.use_lores_mesh = scene->r.bake_flag & R_BAKE_LORES_MESH;
|
2012-12-18 17:46:42 +00:00
|
|
|
bkr.bias = scene->r.bake_biasdist;
|
2012-12-19 12:30:39 +00:00
|
|
|
bkr.number_of_rays = scene->r.bake_samples;
|
2012-12-18 17:46:42 +00:00
|
|
|
bkr.raytrace_structure = scene->r.raytrace_structure;
|
2012-12-18 17:46:54 +00:00
|
|
|
bkr.octree_resolution = scene->r.ocres;
|
2013-05-08 13:23:17 +00:00
|
|
|
bkr.threads = BKE_scene_num_threads(scene);
|
2013-10-09 15:51:14 +00:00
|
|
|
bkr.user_scale = (scene->r.bake_flag & R_BAKE_USERSCALE) ? scene->r.bake_user_scale : -1.0f;
|
|
|
|
|
//bkr.reports= op->reports;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
|
|
|
|
/* create low-resolution DM (to bake to) and hi-resolution DM (to bake from) */
|
2012-04-28 15:42:27 +00:00
|
|
|
bkr.hires_dm = multiresbake_create_hiresdm(scene, ob, &bkr.tot_lvl, &bkr.simple);
|
2012-12-18 17:46:42 +00:00
|
|
|
bkr.lores_dm = multiresbake_create_loresdm(scene, ob, &bkr.lvl);
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-12-18 17:46:26 +00:00
|
|
|
RE_multires_bake_images(&bkr);
|
2011-06-05 20:54:04 +00:00
|
|
|
|
|
|
|
|
BLI_freelistN(&bkr.image);
|
|
|
|
|
|
|
|
|
|
bkr.lores_dm->release(bkr.lores_dm);
|
|
|
|
|
bkr.hires_dm->release(bkr.hires_dm);
|
2011-12-29 16:05:09 +00:00
|
|
|
|
|
|
|
|
objects_baked++;
|
2011-06-05 20:54:04 +00:00
|
|
|
}
|
|
|
|
|
CTX_DATA_END;
|
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!objects_baked)
|
2011-12-29 16:05:09 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "No objects found to bake from");
|
|
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Multiresbake adopted for job-system executing */
|
|
|
|
|
static void init_multiresbake_job(bContext *C, MultiresBakeJob *bkj)
|
|
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2011-06-05 20:54:04 +00:00
|
|
|
Object *ob;
|
|
|
|
|
|
|
|
|
|
/* backup scene settings, so their changing in UI would take no effect on baker */
|
2012-04-28 15:42:27 +00:00
|
|
|
bkj->bake_filter = scene->r.bake_filter;
|
|
|
|
|
bkj->mode = scene->r.bake_mode;
|
|
|
|
|
bkj->use_lores_mesh = scene->r.bake_flag & R_BAKE_LORES_MESH;
|
|
|
|
|
bkj->bake_clear = scene->r.bake_flag & R_BAKE_CLEAR;
|
2012-12-18 17:46:42 +00:00
|
|
|
bkj->bias = scene->r.bake_biasdist;
|
2012-12-19 12:30:39 +00:00
|
|
|
bkj->number_of_rays = scene->r.bake_samples;
|
2012-12-18 17:46:42 +00:00
|
|
|
bkj->raytrace_structure = scene->r.raytrace_structure;
|
2012-12-18 17:46:54 +00:00
|
|
|
bkj->octree_resolution = scene->r.ocres;
|
2013-05-08 13:23:17 +00:00
|
|
|
bkj->threads = BKE_scene_num_threads(scene);
|
2013-10-09 15:51:14 +00:00
|
|
|
bkj->user_scale = (scene->r.bake_flag & R_BAKE_USERSCALE) ? scene->r.bake_user_scale : -1.0f;
|
|
|
|
|
//bkj->reports = op->reports;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-04-30 16:22:40 +00:00
|
|
|
CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases)
|
|
|
|
|
{
|
2011-06-05 20:54:04 +00:00
|
|
|
MultiresBakerJobData *data;
|
2011-12-29 16:05:09 +00:00
|
|
|
int lvl;
|
2012-12-18 17:46:42 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
ob = base->object;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2011-11-30 11:04:57 +00:00
|
|
|
multires_force_update(ob);
|
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
data = MEM_callocN(sizeof(MultiresBakerJobData), "multiresBaker derivedMesh_data");
|
2012-12-18 17:46:42 +00:00
|
|
|
|
|
|
|
|
/* create low-resolution DM (to bake to) and hi-resolution DM (to bake from) */
|
2011-06-05 20:54:04 +00:00
|
|
|
data->hires_dm = multiresbake_create_hiresdm(scene, ob, &data->tot_lvl, &data->simple);
|
2012-12-18 17:46:42 +00:00
|
|
|
data->lores_dm = multiresbake_create_loresdm(scene, ob, &lvl);
|
|
|
|
|
data->lvl = lvl;
|
2011-12-29 16:05:09 +00:00
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
BLI_addtail(&bkj->data, data);
|
|
|
|
|
}
|
|
|
|
|
CTX_DATA_END;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void multiresbake_startjob(void *bkv, short *stop, short *do_update, float *progress)
|
|
|
|
|
{
|
|
|
|
|
MultiresBakerJobData *data;
|
2012-04-28 15:42:27 +00:00
|
|
|
MultiresBakeJob *bkj = bkv;
|
|
|
|
|
int baked_objects = 0, tot_obj;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2014-11-16 13:57:58 +01:00
|
|
|
tot_obj = BLI_listbase_count(&bkj->data);
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (bkj->bake_clear) { /* clear images */
|
2012-04-28 15:42:27 +00:00
|
|
|
for (data = bkj->data.first; data; data = data->next) {
|
|
|
|
|
DerivedMesh *dm = data->lores_dm;
|
|
|
|
|
MTFace *mtface = CustomData_get_layer(&dm->faceData, CD_MTFACE);
|
2013-09-20 10:14:54 +00:00
|
|
|
ClearFlag clear_flag = 0;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2013-09-20 10:14:54 +00:00
|
|
|
if (bkj->mode == RE_BAKE_NORMALS) {
|
|
|
|
|
clear_flag = CLEAR_TANGENT_NORMAL;
|
|
|
|
|
}
|
2013-10-09 15:51:14 +00:00
|
|
|
else if (ELEM(bkj->mode, RE_BAKE_DISPLACEMENT, RE_BAKE_DERIVATIVE)) {
|
2013-09-20 10:14:54 +00:00
|
|
|
clear_flag = CLEAR_DISPLACEMENT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clear_images(mtface, dm->getNumTessFaces(dm), clear_flag);
|
2011-06-05 20:54:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
for (data = bkj->data.first; data; data = data->next) {
|
2013-03-22 05:34:10 +00:00
|
|
|
MultiresBakeRender bkr = {NULL};
|
2011-06-05 20:54:04 +00:00
|
|
|
|
|
|
|
|
/* copy data stored in job descriptor */
|
2012-04-28 15:42:27 +00:00
|
|
|
bkr.bake_filter = bkj->bake_filter;
|
|
|
|
|
bkr.mode = bkj->mode;
|
|
|
|
|
bkr.use_lores_mesh = bkj->use_lores_mesh;
|
2013-10-09 15:51:14 +00:00
|
|
|
bkr.user_scale = bkj->user_scale;
|
|
|
|
|
//bkr.reports = bkj->reports;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
|
|
|
|
/* create low-resolution DM (to bake to) and hi-resolution DM (to bake from) */
|
2012-04-28 15:42:27 +00:00
|
|
|
bkr.lores_dm = data->lores_dm;
|
|
|
|
|
bkr.hires_dm = data->hires_dm;
|
|
|
|
|
bkr.tot_lvl = data->tot_lvl;
|
|
|
|
|
bkr.lvl = data->lvl;
|
|
|
|
|
bkr.simple = data->simple;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
|
|
|
|
/* needed for proper progress bar */
|
2012-04-28 15:42:27 +00:00
|
|
|
bkr.tot_obj = tot_obj;
|
|
|
|
|
bkr.baked_objects = baked_objects;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
bkr.stop = stop;
|
|
|
|
|
bkr.do_update = do_update;
|
|
|
|
|
bkr.progress = progress;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-12-18 17:46:42 +00:00
|
|
|
bkr.bias = bkj->bias;
|
|
|
|
|
bkr.number_of_rays = bkj->number_of_rays;
|
|
|
|
|
bkr.raytrace_structure = bkj->raytrace_structure;
|
2012-12-18 17:46:54 +00:00
|
|
|
bkr.octree_resolution = bkj->octree_resolution;
|
2012-12-19 08:13:41 +00:00
|
|
|
bkr.threads = bkj->threads;
|
2012-12-18 17:46:42 +00:00
|
|
|
|
2012-12-18 17:46:26 +00:00
|
|
|
RE_multires_bake_images(&bkr);
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-12-26 20:38:20 +00:00
|
|
|
data->images = bkr.image;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
|
|
|
|
baked_objects++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void multiresbake_freejob(void *bkv)
|
|
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
MultiresBakeJob *bkj = bkv;
|
2011-06-05 20:54:04 +00:00
|
|
|
MultiresBakerJobData *data, *next;
|
2012-12-26 20:38:20 +00:00
|
|
|
LinkData *link;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
data = bkj->data.first;
|
2011-06-05 20:54:04 +00:00
|
|
|
while (data) {
|
2012-04-28 15:42:27 +00:00
|
|
|
next = data->next;
|
2011-06-05 20:54:04 +00:00
|
|
|
data->lores_dm->release(data->lores_dm);
|
|
|
|
|
data->hires_dm->release(data->hires_dm);
|
2012-12-26 20:38:20 +00:00
|
|
|
|
|
|
|
|
/* delete here, since this delete will be called from main thread */
|
|
|
|
|
for (link = data->images.first; link; link = link->next) {
|
|
|
|
|
Image *ima = (Image *)link->data;
|
|
|
|
|
GPU_free_image(ima);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BLI_freelistN(&data->images);
|
|
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
MEM_freeN(data);
|
2012-04-28 15:42:27 +00:00
|
|
|
data = next;
|
2011-06-05 20:54:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MEM_freeN(bkj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int multiresbake_image_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2011-06-05 20:54:04 +00:00
|
|
|
MultiresBakeJob *bkr;
|
2012-08-15 10:03:29 +00:00
|
|
|
wmJob *wm_job;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!multiresbake_check(C, op))
|
2011-06-05 20:54:04 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
bkr = MEM_callocN(sizeof(MultiresBakeJob), "MultiresBakeJob data");
|
2011-06-05 20:54:04 +00:00
|
|
|
init_multiresbake_job(C, bkr);
|
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!bkr->data.first) {
|
2011-12-29 16:05:09 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "No objects found to bake from");
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
/* setup job */
|
2012-08-15 10:03:29 +00:00
|
|
|
wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), scene, "Multires Bake",
|
|
|
|
|
WM_JOB_EXCL_RENDER | WM_JOB_PRIORITY | WM_JOB_PROGRESS, WM_JOB_TYPE_OBJECT_BAKE_TEXTURE);
|
|
|
|
|
WM_jobs_customdata_set(wm_job, bkr, multiresbake_freejob);
|
2013-10-17 18:29:01 +00:00
|
|
|
WM_jobs_timer(wm_job, 0.5, NC_IMAGE, 0); /* TODO - only draw bake image, can we enforce this */
|
2012-08-15 10:03:29 +00:00
|
|
|
WM_jobs_callbacks(wm_job, multiresbake_startjob, NULL, NULL, NULL);
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
G.is_break = false;
|
2011-06-05 20:54:04 +00:00
|
|
|
|
2012-08-15 10:03:29 +00:00
|
|
|
WM_jobs_start(CTX_wm_manager(C), wm_job);
|
2011-06-05 20:54:04 +00:00
|
|
|
WM_cursor_wait(0);
|
|
|
|
|
|
|
|
|
|
/* add modal handler for ESC */
|
|
|
|
|
WM_event_add_modal_handler(C, op);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-30 14:37:25 +00:00
|
|
|
/* ****************** render BAKING ********************** */
|
|
|
|
|
|
|
|
|
|
/* threaded break test */
|
2010-10-15 05:18:45 +00:00
|
|
|
static int thread_break(void *UNUSED(arg))
|
2009-12-30 14:37:25 +00:00
|
|
|
{
|
2012-08-08 18:37:06 +00:00
|
|
|
return G.is_break;
|
2009-12-30 14:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef struct BakeRender {
|
|
|
|
|
Render *re;
|
2010-08-01 20:36:24 +00:00
|
|
|
Main *main;
|
2009-12-30 14:37:25 +00:00
|
|
|
Scene *scene;
|
|
|
|
|
struct Object *actob;
|
2012-01-20 07:43:46 +00:00
|
|
|
int result, ready;
|
2009-12-30 14:37:25 +00:00
|
|
|
|
|
|
|
|
ReportList *reports;
|
|
|
|
|
|
|
|
|
|
short *stop;
|
|
|
|
|
short *do_update;
|
2010-05-27 08:22:16 +00:00
|
|
|
float *progress;
|
|
|
|
|
|
2009-12-30 14:37:25 +00:00
|
|
|
ListBase threads;
|
|
|
|
|
|
|
|
|
|
/* backup */
|
|
|
|
|
short prev_wo_amb_occ;
|
|
|
|
|
short prev_r_raytrace;
|
|
|
|
|
|
|
|
|
|
/* for redrawing */
|
|
|
|
|
ScrArea *sa;
|
|
|
|
|
} BakeRender;
|
|
|
|
|
|
|
|
|
|
/* use by exec and invoke */
|
2011-02-14 17:55:27 +00:00
|
|
|
static int test_bake_internal(bContext *C, ReportList *reports)
|
2009-12-30 14:37:25 +00:00
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
if ((scene->r.bake_flag & R_BAKE_TO_ACTIVE) && CTX_data_active_object(C) == NULL) {
|
2009-12-30 14:37:25 +00:00
|
|
|
BKE_report(reports, RPT_ERROR, "No active object");
|
|
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (scene->r.bake_mode == RE_BAKE_AO && scene->world == NULL) {
|
2009-12-30 14:37:25 +00:00
|
|
|
BKE_report(reports, RPT_ERROR, "No world set up");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void init_bake_internal(BakeRender *bkr, bContext *C)
|
|
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2012-09-23 06:38:09 +00:00
|
|
|
bScreen *sc = CTX_wm_screen(C);
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2010-09-23 18:26:33 +00:00
|
|
|
/* get editmode results */
|
2013-03-21 14:12:04 +00:00
|
|
|
ED_object_editmode_load(CTX_data_edit_object(C));
|
2010-09-23 18:26:33 +00:00
|
|
|
|
2012-09-23 06:38:09 +00:00
|
|
|
bkr->sa = sc ? BKE_screen_find_big_area(sc, SPACE_IMAGE, 10) : NULL; /* can be NULL */
|
2012-04-28 15:42:27 +00:00
|
|
|
bkr->main = CTX_data_main(C);
|
|
|
|
|
bkr->scene = scene;
|
|
|
|
|
bkr->actob = (scene->r.bake_flag & R_BAKE_TO_ACTIVE) ? OBACT : NULL;
|
|
|
|
|
bkr->re = RE_NewRender("_Bake View_");
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
if (scene->r.bake_mode == RE_BAKE_AO) {
|
2009-12-30 14:37:25 +00:00
|
|
|
/* If raytracing or AO is disabled, switch it on temporarily for baking. */
|
|
|
|
|
bkr->prev_wo_amb_occ = (scene->world->mode & WO_AMB_OCC) != 0;
|
|
|
|
|
scene->world->mode |= WO_AMB_OCC;
|
|
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
if (scene->r.bake_mode == RE_BAKE_AO || bkr->actob) {
|
2009-12-30 14:37:25 +00:00
|
|
|
bkr->prev_r_raytrace = (scene->r.mode & R_RAYTRACE) != 0;
|
|
|
|
|
scene->r.mode |= R_RAYTRACE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void finish_bake_internal(BakeRender *bkr)
|
|
|
|
|
{
|
2012-09-12 03:11:29 +00:00
|
|
|
Image *ima;
|
|
|
|
|
|
2009-12-30 14:37:25 +00:00
|
|
|
RE_Database_Free(bkr->re);
|
|
|
|
|
|
|
|
|
|
/* restore raytrace and AO */
|
2012-04-28 15:42:27 +00:00
|
|
|
if (bkr->scene->r.bake_mode == RE_BAKE_AO)
|
2012-03-24 06:38:07 +00:00
|
|
|
if (bkr->prev_wo_amb_occ == 0)
|
2009-12-30 14:37:25 +00:00
|
|
|
bkr->scene->world->mode &= ~WO_AMB_OCC;
|
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
if (bkr->scene->r.bake_mode == RE_BAKE_AO || bkr->actob)
|
2012-03-24 06:38:07 +00:00
|
|
|
if (bkr->prev_r_raytrace == 0)
|
2009-12-30 14:37:25 +00:00
|
|
|
bkr->scene->r.mode &= ~R_RAYTRACE;
|
|
|
|
|
|
2012-09-12 03:11:29 +00:00
|
|
|
/* force OpenGL reload and mipmap recalc */
|
2013-04-24 13:53:09 +00:00
|
|
|
if ((bkr->scene->r.bake_flag & R_BAKE_VCOL) == 0) {
|
|
|
|
|
for (ima = G.main->image.first; ima; ima = ima->id.next) {
|
|
|
|
|
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL);
|
2012-09-12 03:11:29 +00:00
|
|
|
|
2013-04-24 13:53:09 +00:00
|
|
|
/* some of the images could have been changed during bake,
|
|
|
|
|
* so recreate mipmaps regardless bake result status
|
|
|
|
|
*/
|
|
|
|
|
if (ima->ok == IMA_OK_LOADED) {
|
|
|
|
|
if (ibuf) {
|
|
|
|
|
if (ibuf->userflags & IB_BITMAPDIRTY) {
|
|
|
|
|
GPU_free_image(ima);
|
|
|
|
|
imb_freemipmapImBuf(ibuf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* invalidate display buffers for changed images */
|
|
|
|
|
if (ibuf->userflags & IB_BITMAPDIRTY)
|
|
|
|
|
ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID;
|
2009-12-30 14:37:25 +00:00
|
|
|
}
|
2013-04-24 13:53:09 +00:00
|
|
|
}
|
2012-10-14 06:59:01 +00:00
|
|
|
|
2013-04-24 13:53:09 +00:00
|
|
|
/* freed when baking is done, but if its canceled we need to free here */
|
|
|
|
|
if (ibuf) {
|
|
|
|
|
if (ibuf->userdata) {
|
|
|
|
|
BakeImBufuserData *userdata = (BakeImBufuserData *) ibuf->userdata;
|
|
|
|
|
if (userdata->mask_buffer)
|
|
|
|
|
MEM_freeN(userdata->mask_buffer);
|
|
|
|
|
if (userdata->displacement_buffer)
|
|
|
|
|
MEM_freeN(userdata->displacement_buffer);
|
|
|
|
|
MEM_freeN(userdata);
|
|
|
|
|
ibuf->userdata = NULL;
|
|
|
|
|
}
|
2009-12-30 14:37:25 +00:00
|
|
|
}
|
2013-04-24 13:53:09 +00:00
|
|
|
|
|
|
|
|
BKE_image_release_ibuf(ima, ibuf, NULL);
|
2014-09-19 15:36:49 +02:00
|
|
|
DAG_id_tag_update(&ima->id, 0);
|
2009-12-30 14:37:25 +00:00
|
|
|
}
|
2013-04-24 13:53:09 +00:00
|
|
|
}
|
2012-09-12 03:11:29 +00:00
|
|
|
|
2013-04-24 13:53:09 +00:00
|
|
|
if (bkr->scene->r.bake_flag & R_BAKE_VCOL) {
|
|
|
|
|
/* update all tagged meshes */
|
2013-04-29 00:49:44 +00:00
|
|
|
Mesh *me;
|
2013-04-24 13:53:09 +00:00
|
|
|
BLI_assert(BLI_thread_is_main());
|
2013-04-29 00:49:44 +00:00
|
|
|
for (me = G.main->mesh.first; me; me = me->id.next) {
|
|
|
|
|
if (me->id.flag & LIB_DOIT) {
|
|
|
|
|
DAG_id_tag_update(&me->id, OB_RECALC_DATA);
|
|
|
|
|
BKE_mesh_tessface_clear(me);
|
2012-09-12 23:19:08 +00:00
|
|
|
}
|
2012-09-12 03:11:29 +00:00
|
|
|
}
|
2009-12-30 14:37:25 +00:00
|
|
|
}
|
2013-04-24 13:53:09 +00:00
|
|
|
|
2009-12-30 14:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void *do_bake_render(void *bake_v)
|
|
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
BakeRender *bkr = bake_v;
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
bkr->result = RE_bake_shade_all_selected(bkr->re, bkr->scene->r.bake_mode, bkr->actob, NULL, bkr->progress);
|
|
|
|
|
bkr->ready = 1;
|
2009-12-30 14:37:25 +00:00
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-27 08:22:16 +00:00
|
|
|
static void bake_startjob(void *bkv, short *stop, short *do_update, float *progress)
|
2009-12-30 14:37:25 +00:00
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
BakeRender *bkr = bkv;
|
|
|
|
|
Scene *scene = bkr->scene;
|
|
|
|
|
Main *bmain = bkr->main;
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
bkr->stop = stop;
|
|
|
|
|
bkr->do_update = do_update;
|
|
|
|
|
bkr->progress = progress;
|
2009-12-30 14:37:25 +00:00
|
|
|
|
|
|
|
|
RE_test_break_cb(bkr->re, NULL, thread_break);
|
2014-04-01 11:34:00 +11:00
|
|
|
G.is_break = false; /* blender_test_break uses this global */
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2010-08-01 20:36:24 +00:00
|
|
|
RE_Database_Baking(bkr->re, bmain, scene, scene->lay, scene->r.bake_mode, bkr->actob);
|
2009-12-30 14:37:25 +00:00
|
|
|
|
|
|
|
|
/* baking itself is threaded, cannot use test_break in threads. we also update optional imagewindow */
|
2012-04-28 15:42:27 +00:00
|
|
|
bkr->result = RE_bake_shade_all_selected(bkr->re, scene->r.bake_mode, bkr->actob, bkr->do_update, bkr->progress);
|
2009-12-30 14:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void bake_update(void *bkv)
|
|
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
BakeRender *bkr = bkv;
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
if (bkr->sa && bkr->sa->spacetype == SPACE_IMAGE) { /* in case the user changed while baking */
|
|
|
|
|
SpaceImage *sima = bkr->sa->spacedata.first;
|
2012-03-24 06:38:07 +00:00
|
|
|
if (sima)
|
2012-04-28 15:42:27 +00:00
|
|
|
sima->image = RE_bake_shade_get_image();
|
2009-12-30 14:37:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void bake_freejob(void *bkv)
|
|
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
BakeRender *bkr = bkv;
|
2009-12-30 14:37:25 +00:00
|
|
|
finish_bake_internal(bkr);
|
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
if (bkr->result == BAKE_RESULT_NO_OBJECTS)
|
2012-01-20 07:43:46 +00:00
|
|
|
BKE_report(bkr->reports, RPT_ERROR, "No objects or images found to bake to");
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (bkr->result == BAKE_RESULT_FEEDBACK_LOOP)
|
2013-06-13 14:17:02 +00:00
|
|
|
BKE_report(bkr->reports, RPT_WARNING, "Circular reference in texture stack");
|
2012-01-20 07:43:46 +00:00
|
|
|
|
2009-12-30 14:37:25 +00:00
|
|
|
MEM_freeN(bkr);
|
2014-04-01 11:34:00 +11:00
|
|
|
G.is_rendering = false;
|
2009-12-30 14:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* catch esc */
|
2013-03-13 09:03:46 +00:00
|
|
|
static int objects_bake_render_modal(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
|
2009-12-30 14:37:25 +00:00
|
|
|
{
|
|
|
|
|
/* no running blender, remove handler and pass through */
|
2012-08-15 10:23:06 +00:00
|
|
|
if (0 == WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C), WM_JOB_TYPE_OBJECT_BAKE_TEXTURE))
|
2012-04-28 15:42:27 +00:00
|
|
|
return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH;
|
2009-12-30 14:37:25 +00:00
|
|
|
|
|
|
|
|
/* running render */
|
|
|
|
|
switch (event->type) {
|
|
|
|
|
case ESCKEY:
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
|
}
|
|
|
|
|
return OPERATOR_PASS_THROUGH;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-03 18:55:59 +11:00
|
|
|
static bool is_multires_bake(Scene *scene)
|
2011-06-05 20:54:04 +00:00
|
|
|
{
|
2014-07-20 01:30:29 +10:00
|
|
|
if (ELEM(scene->r.bake_mode, RE_BAKE_NORMALS, RE_BAKE_DISPLACEMENT, RE_BAKE_DERIVATIVE, RE_BAKE_AO))
|
2011-06-05 20:54:04 +00:00
|
|
|
return scene->r.bake_flag & R_BAKE_MULTIRES;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-13 09:03:46 +00:00
|
|
|
static int objects_bake_render_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(_event))
|
2009-12-30 14:37:25 +00:00
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
|
int result = OPERATOR_CANCELLED;
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (is_multires_bake(scene)) {
|
2012-04-28 15:42:27 +00:00
|
|
|
result = multiresbake_image_exec(C, op);
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2011-06-05 20:54:04 +00:00
|
|
|
/* only one render job at a time */
|
2012-08-15 10:23:06 +00:00
|
|
|
if (WM_jobs_test(CTX_wm_manager(C), scene, WM_JOB_TYPE_OBJECT_BAKE_TEXTURE))
|
2011-06-05 20:54:04 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
if (test_bake_internal(C, op->reports) == 0) {
|
2011-06-05 20:54:04 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2012-04-28 15:42:27 +00:00
|
|
|
BakeRender *bkr = MEM_callocN(sizeof(BakeRender), "render bake");
|
2012-08-15 10:03:29 +00:00
|
|
|
wmJob *wm_job;
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
init_bake_internal(bkr, C);
|
2012-04-28 15:42:27 +00:00
|
|
|
bkr->reports = op->reports;
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
/* setup job */
|
2012-08-15 10:03:29 +00:00
|
|
|
wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), scene, "Texture Bake",
|
|
|
|
|
WM_JOB_EXCL_RENDER | WM_JOB_PRIORITY | WM_JOB_PROGRESS, WM_JOB_TYPE_OBJECT_BAKE_TEXTURE);
|
|
|
|
|
WM_jobs_customdata_set(wm_job, bkr, bake_freejob);
|
2013-10-17 18:29:01 +00:00
|
|
|
WM_jobs_timer(wm_job, 0.5, NC_IMAGE, 0); /* TODO - only draw bake image, can we enforce this */
|
2012-08-15 10:03:29 +00:00
|
|
|
WM_jobs_callbacks(wm_job, bake_startjob, NULL, bake_update, NULL);
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
G.is_break = false;
|
|
|
|
|
G.is_rendering = true;
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2012-08-15 10:03:29 +00:00
|
|
|
WM_jobs_start(CTX_wm_manager(C), wm_job);
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
WM_cursor_wait(0);
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
/* add modal handler for ESC */
|
|
|
|
|
WM_event_add_modal_handler(C, op);
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
result = OPERATOR_RUNNING_MODAL;
|
2009-12-30 14:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_RESULT, scene);
|
2011-06-05 20:54:04 +00:00
|
|
|
|
|
|
|
|
return result;
|
2009-12-30 14:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int bake_image_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
|
int result = OPERATOR_CANCELLED;
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (is_multires_bake(scene)) {
|
2012-04-28 15:42:27 +00:00
|
|
|
result = multiresbake_image_exec_locked(C, op);
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-04-28 15:42:27 +00:00
|
|
|
if (test_bake_internal(C, op->reports) == 0) {
|
2011-06-05 20:54:04 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ListBase threads;
|
2012-04-28 15:42:27 +00:00
|
|
|
BakeRender bkr = {NULL};
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
init_bake_internal(&bkr, C);
|
2012-04-28 15:42:27 +00:00
|
|
|
bkr.reports = op->reports;
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
RE_test_break_cb(bkr.re, NULL, thread_break);
|
2014-04-01 11:34:00 +11:00
|
|
|
G.is_break = false; /* blender_test_break uses this global */
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
RE_Database_Baking(bkr.re, bmain, scene, scene->lay, scene->r.bake_mode, (scene->r.bake_flag & R_BAKE_TO_ACTIVE) ? OBACT : NULL);
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
/* baking itself is threaded, cannot use test_break in threads */
|
|
|
|
|
BLI_init_threads(&threads, do_bake_render, 1);
|
2012-04-28 15:42:27 +00:00
|
|
|
bkr.ready = 0;
|
2011-06-05 20:54:04 +00:00
|
|
|
BLI_insert_thread(&threads, &bkr);
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
while (bkr.ready == 0) {
|
2011-06-05 20:54:04 +00:00
|
|
|
PIL_sleep_ms(50);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (bkr.ready)
|
2011-06-05 20:54:04 +00:00
|
|
|
break;
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
/* used to redraw in 2.4x but this is just for exec in 2.5 */
|
|
|
|
|
if (!G.background)
|
|
|
|
|
blender_test_break();
|
|
|
|
|
}
|
|
|
|
|
BLI_end_threads(&threads);
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
if (bkr.result == BAKE_RESULT_NO_OBJECTS)
|
2012-01-20 07:43:46 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "No valid images found to bake to");
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (bkr.result == BAKE_RESULT_FEEDBACK_LOOP)
|
2013-06-13 14:17:02 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "Circular reference in texture stack");
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2011-06-05 20:54:04 +00:00
|
|
|
finish_bake_internal(&bkr);
|
2009-12-30 14:37:25 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
result = OPERATOR_FINISHED;
|
2011-06-05 20:54:04 +00:00
|
|
|
}
|
2009-12-30 14:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_RESULT, scene);
|
2011-06-05 20:54:04 +00:00
|
|
|
|
|
|
|
|
return result;
|
2009-12-30 14:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OBJECT_OT_bake_image(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Bake";
|
|
|
|
|
ot->description = "Bake image textures of selected objects";
|
|
|
|
|
ot->idname = "OBJECT_OT_bake_image";
|
2009-12-30 14:37:25 +00:00
|
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = bake_image_exec;
|
|
|
|
|
ot->invoke = objects_bake_render_invoke;
|
|
|
|
|
ot->modal = objects_bake_render_modal;
|
Bake API - bpy.ops.object.bake()
New operator that can calls a bake function to the current render engine when available. This commit provides no feature for the users, but allows external engines to be accessed by the operator and be integrated with the baking api.
The API itself is simple. Blender sends a populated array of BakePixels to the renderer, and gets back an array of floats with the result.
The Blender Internal (and multires) system is still running independent, but we eventually will pipe it through the API as well. Cycles baking will come next as a separated commit
Python Operator:
----------------
The operator can be called with some arguments, or a user interface can be created for it. In that case the arguments can be ommited and the interface can expose the settings from bpy.context.scene.render.bake
bpy.ops.object.bake(type='COMBINED', filepath="", width=512, height=512, margin=16, use_selected_to_active=False, cage_extrusion=0, cage="", normal_space='TANGENT', normal_r='POS_X', normal_g='POS_Y', normal_b='POS_Z', save_mode='INTERNAL', use_clear=False, use_split_materials=False, use_automatic_name=False)
Note: external save mode is currently disabled.
Supported Features:
------------------
* Margin - Baked result is extended this many pixels beyond the border of each UV "island," to soften seams in the texture.
* Selected to Active - bake shading on the surface of selected object to the active object. The rays are cast from the lowpoly object inwards towards the highpoly object. If the highpoly object is not entirely involved by the lowpoly object, you can tweak the rays start point with Cage Extrusion. For even more control of the cage you can use a Cage object.
* Cage Extrusion - distance to use for the inward ray cast when using selected to active
* Custom Cage - object to use as cage (instead of the lowpoly object).
* Normal swizzle - change the axis that gets mapped to RGB
* Normal space - save as tangent or object normal spaces
Supported Passes:
-----------------
Any pass that is supported by Blender renderlayer system. Though it's up to the external engine to provide a valid enum with its supported passes. Normal passes get a special treatment since we post-process them to converted and "swizzled"
Development Notes for External Engines:
---------------------------------------
(read them in bake_api.c)
* For a complete implementation example look at the Cycles Bake commit (next).
Review: D421
Reviewed by: Campbell Barton, Brecht van Lommel, Sergey Sharybin, Thomas Dinge
Normal map pipeline "consulting" by Andy Davies (metalliandy)
Original design by Brecht van Lommel.
The entire commit history can be found on the branch: bake-cycles
2014-01-02 19:05:07 -02:00
|
|
|
ot->poll = ED_operator_object_active;
|
2009-12-30 14:37:25 +00:00
|
|
|
}
|