|
Blender V5.0
|
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. More...
#include <climits>#include <cstring>#include "BLI_string_ref.hh"#include "MEM_guardedalloc.h"#include "BLI_index_range.hh"#include "BLI_math_geom.h"#include "BLI_math_matrix.h"#include "BLI_math_vector.h"#include "BLI_task.hh"#include "BKE_attribute.hh"#include "BKE_bvhutils.hh"#include "BKE_customdata.hh"#include "BKE_image.hh"#include "BKE_lib_id.hh"#include "BKE_mesh.hh"#include "BKE_mesh_runtime.hh"#include "BKE_mesh_tangent.hh"#include "BKE_node.hh"#include "IMB_imbuf.hh"#include "IMB_imbuf_types.hh"#include "RE_bake.h"#include "RE_texture_margin.h"#include "zbuf.h"Go to the source code of this file.
Classes | |
| struct | BakeDataZSpan |
| struct | TriTessFace |
Functions | |
| static void | store_bake_pixel (void *handle, int x, int y, float u, float v) |
| void | RE_bake_mask_fill (const BakePixel pixel_array[], const size_t pixels_num, char *mask) |
| void | RE_bake_margin (ImBuf *ibuf, char *mask, const int margin, const char margin_type, const Mesh *mesh, const blender::StringRef uv_layer, const float uv_offset[2]) |
| static void | calc_point_from_barycentric_cage (TriTessFace *triangles_low, TriTessFace *triangles_cage, const float mat_low[4][4], const float mat_cage[4][4], int primitive_id, float u, float v, float r_co[3], float r_dir[3]) |
| static void | calc_point_from_barycentric_extrusion (TriTessFace *triangles, const float mat[4][4], const float imat[4][4], int primitive_id, float u, float v, float cage_extrusion, float r_co[3], float r_dir[3], const bool is_cage) |
| static void | barycentric_differentials_from_position (const float co[3], const float v1[3], const float v2[3], const float v3[3], const float dxco[3], const float dyco[3], const float facenor[3], const bool differentials, float *u, float *v, float *dx_u, float *dx_v, float *dy_u, float *dy_v) |
| static bool | cast_ray_highpoly (blender::bke::BVHTreeFromMesh *treeData, TriTessFace *triangle_low, TriTessFace *triangles[], BakePixel *pixel_array_low, BakePixel *pixel_array, const float mat_low[4][4], BakeHighPolyData *highpoly, const int highpoly_num, blender::MutableSpan< BVHTreeRayHit > hits, const float co[3], const float dir[3], const int pixel_id, const float max_ray_distance) |
| static TriTessFace * | mesh_calc_tri_tessface (Mesh *mesh, bool tangent, Mesh *mesh_eval) |
| bool | RE_bake_pixels_populate_from_objects (Mesh *me_low, BakePixel pixel_array_from[], BakePixel pixel_array_to[], BakeHighPolyData highpoly[], const int highpoly_num, const size_t pixels_num, const bool is_custom_cage, const float cage_extrusion, const float max_ray_distance, const float mat_low[4][4], const float mat_cage[4][4], Mesh *me_cage) |
| static void | bake_differentials (BakeDataZSpan *bd, const float *uv1, const float *uv2, const float *uv3) |
| void | RE_bake_pixels_populate (Mesh *mesh, BakePixel pixel_array[], const size_t pixels_num, const BakeTargets *targets, const blender::StringRef uv_layer) |
| static void | normal_compress (float out[3], const float in[3], const eBakeNormalSwizzle normal_swizzle[3]) |
| void | RE_bake_normal_world_to_tangent (const BakePixel pixel_array[], const size_t pixels_num, const int depth, float result[], Mesh *mesh, const eBakeNormalSwizzle normal_swizzle[3], const float mat[4][4]) |
| void | RE_bake_normal_world_to_object (const BakePixel pixel_array[], const size_t pixels_num, const int depth, float result[], Object *ob, const eBakeNormalSwizzle normal_swizzle[3]) |
| void | RE_bake_normal_world_to_world (const BakePixel pixel_array[], const size_t pixels_num, const int depth, float result[], const eBakeNormalSwizzle normal_swizzle[3]) |
| void | RE_bake_ibuf_clear (Image *image, const bool is_tangent) |
| int | RE_pass_depth (const eScenePassType pass_type) |
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 Bake API is fully implemented with Python rna functions. The operator expects/call a function:
def bake(scene, object, pass_type, object_id, pixel_array, pixels_num, depth, result)
pixel_array is a Python object storing BakePixel elements:
In python you have access to:
For a complete implementation example look at the Cycles Bake commit.
Definition in file bake.cc.
|
static |
Definition at line 686 of file bake.cc.
References A, BakeDataZSpan::du_dx, BakeDataZSpan::du_dy, BakeDataZSpan::dv_dx, BakeDataZSpan::dv_dy, and fabsf.
Referenced by RE_bake_pixels_populate().
|
static |
Definition at line 270 of file bake.cc.
References axis_dominant_v3(), v, and v2.
Referenced by cast_ray_highpoly().
|
static |
This function returns the coordinate and normal of a barycentric u,v for a face defined by the primitive_id index. The returned normal is actually the direction from the same barycentric coordinate in the cage to the base mesh The returned coordinate is the point in the cage mesh
Definition at line 174 of file bake.cc.
References copy_v3_v3(), data, i, interp_barycentric_tri_v3(), mul_m4_v3(), normalize_v3(), sub_v3_v3v3(), and v.
Referenced by RE_bake_pixels_populate_from_objects().
|
static |
This function returns the coordinate and normal of a barycentric u,v for a face defined by the primitive_id index. The returned coordinate is extruded along the normal by cage_extrusion
Definition at line 217 of file bake.cc.
References add_v3_v3(), copy_v3_v3(), data, interp_barycentric_tri_v3(), TriTessFace::is_smooth, mul_m4_v3(), mul_transposed_mat3_m4_v3(), mul_v3_v3fl(), negate_v3(), TriTessFace::normal, normalize_v3(), TriTessFace::positions, v, and TriTessFace::vert_normals.
Referenced by RE_bake_pixels_populate_from_objects().
|
static |
This function populates pixel_array and returns TRUE if things are correct
Definition at line 315 of file bake.cc.
References barycentric_differentials_from_position(), BLI_assert, BLI_bvhtree_ray_cast(), BVH_RAYCAST_DIST_MAX, dot_v3v3(), BakePixel::du_dx, BakePixel::du_dy, BakePixel::dv_dx, BakePixel::dv_dy, FLT_MAX, i, len_squared_v3v3(), madd_v3_v3fl(), mul_mat3_m4_v3(), mul_v3_m4v3(), mul_v3_mat3_m4v3(), mul_v3_v3fl(), TriTessFace::normal, normalize_v3(), BakePixel::object_id, TriTessFace::positions, BakePixel::primitive_id, raycast_callback(), BakePixel::seed, sub_v3_v3v3(), tree, and BakePixel::uv.
Referenced by RE_bake_pixels_populate_from_objects().
|
static |
This function populates an array of verts for the triangles of a mesh Tangent and Normals are also stored
Definition at line 444 of file bake.cc.
References Geometry::attributes, BKE_mesh_face_normals_are_dirty(), blender::bke::mesh::calc_uv_tangents(), CD_PROP_FLOAT2, copy_v3_v3(), blender::bke::Corner, Mesh::corner_data, blender::bke::mesh::corner_tris_calc(), blender::bke::mesh::corner_tris_calc_with_normals(), Mesh::corners_num, CustomData_get_active_layer_name(), blender::bke::Face, blender::bke::mesh::face_normal_calc(), faces, Mesh::faces_num, i, blender::Span< T >::is_empty(), TriTessFace::is_smooth, blender::bke::AttributeAccessor::lookup(), blender::bke::AttributeAccessor::lookup_or_default(), TriTessFace::loop_normal, MEM_calloc_arrayN(), MEM_freeN(), MEM_mallocN(), poly_to_tri_count(), TriTessFace::positions, result, blender::Span< T >::slice(), TriTessFace::tspace, UINT_MAX, and TriTessFace::vert_normals.
Referenced by RE_bake_normal_world_to_tangent(), and RE_bake_pixels_populate_from_objects().
|
static |
Definition at line 807 of file bake.cc.
References i, in, out, and sign().
Referenced by RE_bake_normal_world_to_object(), RE_bake_normal_world_to_tangent(), and RE_bake_normal_world_to_world().
| void RE_bake_ibuf_clear | ( | Image * | image, |
| const bool | is_tangent ) |
Definition at line 1028 of file bake.cc.
References BKE_image_acquire_ibuf(), BKE_image_release_ibuf(), BLI_assert, IMB_rectfill(), lock, ImBuf::planes, and R_IMF_PLANES_RGBA.
Referenced by blender::ed::object::bake_targets_clear().
| void RE_bake_margin | ( | ImBuf * | ibuf, |
| char * | mask, | ||
| const int | margin, | ||
| const char | margin_type, | ||
| const Mesh * | mesh, | ||
| const blender::StringRef | uv_layer, | ||
| const float | uv_offset[2] ) |
Definition at line 141 of file bake.cc.
References IMB_filter_extend(), IMB_rectfill_alpha(), mask(), ImBuf::planes, R_BAKE_ADJACENT_FACES, R_BAKE_EXTEND, R_IMF_PLANES_RGBA, and RE_generate_texturemargin_adjacentfaces().
Referenced by blender::ed::object::write_external_bake_pixels(), and blender::ed::object::write_internal_bake_pixels().
| void RE_bake_mask_fill | ( | const BakePixel | pixel_array[], |
| const size_t | pixels_num, | ||
| char * | mask ) |
Definition at line 126 of file bake.cc.
References FILTER_MASK_USED, i, and mask().
Referenced by blender::ed::object::write_external_bake_pixels(), and blender::ed::object::write_internal_bake_pixels().
| void RE_bake_normal_world_to_object | ( | const BakePixel | pixel_array[], |
| const size_t | pixels_num, | ||
| const int | depth, | ||
| float | result[], | ||
| Object * | ob, | ||
| const eBakeNormalSwizzle | normal_swizzle[3] ) |
Definition at line 972 of file bake.cc.
References copy_v3_v3(), i, invert_m4_m4(), mul_mat3_m4_v3(), nor, normal_compress(), normalize_v3(), and result.
Referenced by blender::ed::object::bake().
| void RE_bake_normal_world_to_tangent | ( | const BakePixel | pixel_array[], |
| size_t | pixels_num, | ||
| int | depth, | ||
| float | result[], | ||
| struct Mesh * | mesh, | ||
| const eBakeNormalSwizzle | normal_swizzle[3], | ||
| const float | mat[4][4] ) |
This function converts an object space normal map to a tangent space normal map for a given low poly mesh.
Definition at line 847 of file bake.cc.
References BKE_id_free(), BKE_mesh_copy_for_eval(), BLI_assert, copy_v3_fl3(), copy_v3_v3(), copy_v4_fl4(), cross_v3_v3v3(), i, interp_barycentric_tri_v3(), invert_m3_m3(), TriTessFace::is_smooth, TriTessFace::loop_normal, MEM_freeN(), mesh_calc_tri_tessface(), mul_m3_v3(), mul_transposed_mat3_m4_v3(), mul_v3_fl(), nor, TriTessFace::normal, normal_compress(), normalize_v3(), normals, BakePixel::primitive_id, result, sign(), TriTessFace::tspace, BakePixel::uv, v, TriTessFace::vert_normals, w(), and blender::VecBase< T, Size >::xyz().
Referenced by blender::ed::object::bake().
| void RE_bake_normal_world_to_world | ( | const BakePixel | pixel_array[], |
| const size_t | pixels_num, | ||
| const int | depth, | ||
| float | result[], | ||
| const eBakeNormalSwizzle | normal_swizzle[3] ) |
Definition at line 1004 of file bake.cc.
References copy_v3_v3(), i, nor, normal_compress(), and result.
Referenced by blender::ed::object::bake().
| void RE_bake_pixels_populate | ( | Mesh * | mesh, |
| BakePixel | pixel_array[], | ||
| const size_t | pixels_num, | ||
| const BakeTargets * | targets, | ||
| const blender::StringRef | uv_layer ) |
Definition at line 711 of file bake.cc.
References Geometry::attributes, bake_differentials(), BakeDataZSpan::bk_image, CD_PROP_FLOAT2, clamp_i(), blender::bke::Corner, Mesh::corner_data, blender::bke::mesh::corner_tris_calc(), Mesh::corners_num, CustomData_get_active_layer_name(), blender::bke::Face, Mesh::faces_num, BakeImage::height, i, BakeImage::image, BakeTargets::images, BakeTargets::images_num, blender::Span< T >::is_empty(), blender::StringRefBase::is_empty(), blender::bke::AttributeAccessor::lookup(), BakeTargets::material_to_image, BakeTargets::materials_num, MEM_calloc_arrayN(), MEM_freeN(), MEM_malloc_arrayN(), BakePixel::object_id, BakeDataZSpan::pixel_array, poly_to_tri_count(), BakeDataZSpan::primitive_id, BakePixel::primitive_id, store_bake_pixel(), BakeImage::uv_offset, BakeImage::width, zbuf_alloc_span(), zbuf_free_span(), BakeDataZSpan::zspan, and zspan_scanconvert().
Referenced by blender::ed::object::bake_targets_populate_pixels().
| bool RE_bake_pixels_populate_from_objects | ( | Mesh * | me_low, |
| BakePixel | pixel_array_from[], | ||
| BakePixel | pixel_array_to[], | ||
| BakeHighPolyData | highpoly[], | ||
| const int | highpoly_num, | ||
| const size_t | pixels_num, | ||
| const bool | is_custom_cage, | ||
| const float | cage_extrusion, | ||
| const float | max_ray_distance, | ||
| const float | mat_low[4][4], | ||
| const float | mat_cage[4][4], | ||
| Mesh * | me_cage ) |
Definition at line 545 of file bake.cc.
References BKE_id_free(), BKE_mesh_copy_for_eval(), BKE_mesh_runtime_corner_tris_len(), calc_point_from_barycentric_cage(), calc_point_from_barycentric_extrusion(), cast_ray_highpoly(), Array< T, InlineBufferCapacity, Allocator >::data(), i, invert_m4_m4(), MEM_calloc_arrayN(), MEM_freeN(), MEM_malloc_arrayN(), BakeHighPolyData::mesh, mesh_calc_tri_tessface(), blender::threading::parallel_for(), BakePixel::primitive_id, printf, result, tree, BakePixel::uv, and v.
Referenced by blender::ed::object::bake().
| int RE_pass_depth | ( | const eScenePassType | pass_type | ) |
Definition at line 1053 of file bake.cc.
References SCE_PASS_AO, SCE_PASS_COMBINED, SCE_PASS_DEPTH, SCE_PASS_DIFFUSE_COLOR, SCE_PASS_DIFFUSE_DIRECT, SCE_PASS_DIFFUSE_INDIRECT, SCE_PASS_EMIT, SCE_PASS_ENVIRONMENT, SCE_PASS_GLOSSY_COLOR, SCE_PASS_GLOSSY_DIRECT, SCE_PASS_GLOSSY_INDIRECT, SCE_PASS_INDEXMA, SCE_PASS_INDEXOB, SCE_PASS_MIST, SCE_PASS_NORMAL, SCE_PASS_POSITION, SCE_PASS_SHADOW, SCE_PASS_SUBSURFACE_COLOR, SCE_PASS_SUBSURFACE_DIRECT, SCE_PASS_SUBSURFACE_INDIRECT, SCE_PASS_TRANSM_COLOR, SCE_PASS_TRANSM_DIRECT, SCE_PASS_TRANSM_INDIRECT, SCE_PASS_UV, and SCE_PASS_VECTOR.
Referenced by blender::ed::object::bake_targets_init().
Definition at line 101 of file bake.cc.
References BakeDataZSpan::bk_image, copy_v2_fl2(), BakeDataZSpan::du_dx, BakePixel::du_dx, BakeDataZSpan::du_dy, BakePixel::du_dy, BakeDataZSpan::dv_dx, BakePixel::dv_dx, BakeDataZSpan::dv_dy, BakePixel::dv_dy, i, BakePixel::object_id, BakeImage::offset, BakeDataZSpan::pixel_array, BakeDataZSpan::primitive_id, BakePixel::primitive_id, BakePixel::seed, BakePixel::uv, v, BakeImage::width, x, and y.
Referenced by RE_bake_pixels_populate().