Blender V4.3
multires_bake.cc File Reference
#include <cstring>
#include "MEM_guardedalloc.h"
#include "DNA_scene_types.h"
#include "BLI_listbase.h"
#include "BLI_math_color.h"
#include "BLI_math_geom.h"
#include "BLI_math_matrix.h"
#include "BLI_threads.h"
#include "BKE_attribute.hh"
#include "BKE_ccg.hh"
#include "BKE_customdata.hh"
#include "BKE_global.hh"
#include "BKE_image.hh"
#include "BKE_lib_id.hh"
#include "BKE_mesh.hh"
#include "BKE_mesh_legacy_derived_mesh.hh"
#include "BKE_mesh_tangent.hh"
#include "BKE_modifier.hh"
#include "BKE_multires.hh"
#include "BKE_subsurf.hh"
#include "DEG_depsgraph.hh"
#include "RE_multires_bake.h"
#include "RE_pipeline.h"
#include "RE_texture_margin.h"
#include "IMB_imbuf.hh"
#include "IMB_imbuf_types.hh"

Go to the source code of this file.

Classes

struct  MultiresBakeResult
 
struct  MResolvePixelData
 
struct  MBakeRast
 
struct  MHeightBakeData
 
struct  MNormalBakeData
 
struct  BakeImBufuserData
 
struct  MultiresBakeQueue
 
struct  MultiresBakeThread
 

Typedefs

using MPassKnownData
 
using MInitBakeData = void *(*)(MultiresBakeRender *bkr, ImBuf *ibuf)
 
using MFreeBakeData = void (*)(void *bake_data)
 
using MFlushPixel = void (*)(const MResolvePixelData *data, const int x, const int y)
 

Functions

static void multiresbake_get_normal (const MResolvePixelData *data, const int tri_num, const int vert_index, float r_normal[3])
 
static void init_bake_rast (MBakeRast *bake_rast, const ImBuf *ibuf, const MResolvePixelData *data, MFlushPixel flush_pixel, bool *do_update)
 
static void flush_pixel (const MResolvePixelData *data, const int x, const int y)
 
static void set_rast_triangle (const MBakeRast *bake_rast, const int x, const int y)
 
static void rasterize_half (const MBakeRast *bake_rast, const float s0_s, const float t0_s, const float s1_s, const float t1_s, const float s0_l, const float t0_l, const float s1_l, const float t1_l, const int y0_in, const int y1_in, const int is_mid_right)
 
static void bake_rasterize (const MBakeRast *bake_rast, const float st0_in[2], const float st1_in[2], const float st2_in[2])
 
static int multiresbake_test_break (MultiresBakeRender *bkr)
 
static int multires_bake_queue_next_tri (MultiresBakeQueue *queue)
 
static void * do_multires_bake_thread (void *data_v)
 
static void init_ccgdm_arrays (DerivedMesh *dm)
 
static void do_multires_bake (MultiresBakeRender *bkr, Image *ima, ImageTile *tile, ImBuf *ibuf, bool require_tangent, MPassKnownData passKnownData, MInitBakeData initBakeData, MFreeBakeData freeBakeData, MultiresBakeResult *result)
 
static void interp_bilinear_grid (const CCGKey &key, CCGElem *grid, float crn_x, float crn_y, int mode, float res[3])
 
static void get_ccgdm_data (const blender::OffsetIndices< int > lores_polys, DerivedMesh *hidm, const int *index_mp_to_orig, const int lvl, const int face_index, const float u, const float v, float co[3], float n[3])
 
static void interp_bilinear_mpoly (const blender::Span< blender::float3 > vert_positions, const blender::Span< blender::float3 > vert_normals, const blender::Span< int > corner_verts, const blender::IndexRange face, const float u, const float v, const int mode, float res[3])
 
static void interp_barycentric_corner_tri (const blender::Span< blender::float3 > vert_positions, const blender::Span< blender::float3 > vert_normals, const blender::Span< int > corner_verts, const blender::int3 &corner_tri, const float u, const float v, const int mode, float res[3])
 
static void * init_heights_data (MultiresBakeRender *bkr, ImBuf *ibuf)
 
static void free_heights_data (void *bake_data)
 
static void apply_heights_callback (const blender::Span< blender::float3 > vert_positions, const blender::Span< blender::float3 > vert_normals, const blender::OffsetIndices< int > faces, const blender::Span< int > corner_verts, const blender::Span< blender::int3 > corner_tris, const blender::Span< int > tri_faces, const blender::Span< blender::float2 > uv_map, DerivedMesh *hires_dm, void *thread_data_v, void *bake_data, ImBuf *ibuf, const int tri_index, const int lvl, const float st[2], float[3][3], const int x, const int y)
 
static void * init_normal_data (MultiresBakeRender *bkr, ImBuf *)
 
static void free_normal_data (void *bake_data)
 
static void apply_tangmat_callback (const blender::Span< blender::float3 >, const blender::Span< blender::float3 >, const blender::OffsetIndices< int > faces, const blender::Span< int >, const blender::Span< blender::int3 > corner_tris, const blender::Span< int > tri_faces, const blender::Span< blender::float2 > uv_map, DerivedMesh *hires_dm, void *, void *bake_data, ImBuf *ibuf, const int tri_index, const int lvl, const float st[2], float tangmat[3][3], const int x, const int y)
 
static void bake_ibuf_filter (ImBuf *ibuf, char *mask, const int margin, const char margin_type, DerivedMesh *dm, const float uv_offset[2])
 
static void bake_ibuf_normalize_displacement (ImBuf *ibuf, const float *displacement, const char *mask, float displacement_min, float displacement_max)
 
static void count_images (MultiresBakeRender *bkr)
 
static void bake_images (MultiresBakeRender *bkr, MultiresBakeResult *result)
 
static void finish_images (MultiresBakeRender *bkr, MultiresBakeResult *result)
 
void RE_multires_bake_images (MultiresBakeRender *bkr)
 

Typedef Documentation

◆ MFlushPixel

using MFlushPixel = void (*)(const MResolvePixelData *data, const int x, const int y)

Definition at line 100 of file multires_bake.cc.

◆ MFreeBakeData

using MFreeBakeData = void (*)(void *bake_data)

Definition at line 62 of file multires_bake.cc.

◆ MInitBakeData

using MInitBakeData = void *(*)(MultiresBakeRender *bkr, ImBuf *ibuf)

Definition at line 61 of file multires_bake.cc.

◆ MPassKnownData

Initial value:
void (*)(blender::Span<blender::float3> vert_positions,
blender::Span<int> corner_verts,
blender::Span<int> tri_faces,
DerivedMesh *hires_dm,
void *thread_data,
void *bake_data,
ImBuf *ibuf,
const int face_index,
const int lvl,
const float st[2],
float tangmat[3][3],
const int x,
const int y)
static char faces[256]

Definition at line 43 of file multires_bake.cc.

Function Documentation

◆ apply_heights_callback()

static void apply_heights_callback ( const blender::Span< blender::float3 > vert_positions,
const blender::Span< blender::float3 > vert_normals,
const blender::OffsetIndices< int > faces,
const blender::Span< int > corner_verts,
const blender::Span< blender::int3 > corner_tris,
const blender::Span< int > tri_faces,
const blender::Span< blender::float2 > uv_map,
DerivedMesh * hires_dm,
void * thread_data_v,
void * bake_data,
ImBuf * ibuf,
const int tri_index,
const int lvl,
const float st[2],
float [3][3],
const int x,
const int y )
static

◆ apply_tangmat_callback()

static void apply_tangmat_callback ( const blender::Span< blender::float3 > ,
const blender::Span< blender::float3 > ,
const blender::OffsetIndices< int > faces,
const blender::Span< int > ,
const blender::Span< blender::int3 > corner_tris,
const blender::Span< int > tri_faces,
const blender::Span< blender::float2 > uv_map,
DerivedMesh * hires_dm,
void * ,
void * bake_data,
ImBuf * ibuf,
const int tri_index,
const int lvl,
const float st[2],
float tangmat[3][3],
const int x,
const int y )
static

MultiresBake callback for normals' baking.

General idea:

  • Find coord and normal of point with specified UV in hi-res mesh.
  • Multiply it by tangmat.
  • Vector in color space would be norm(vec) / 2 + (0.5, 0.5, 0.5).

Definition at line 991 of file multires_bake.cc.

References add_v3_v3(), ImBuf::byte_buffer, clamp_v2(), ImBufByteBuffer::data, ImBufFloatBuffer::data, ImBuf::float_buffer, get_ccgdm_data(), mul_v3_m3v3(), normalize_v3_length(), MNormalBakeData::orig_index_mp_to_orig, resolve_quad_uv_v2(), resolve_tri_uv_v2(), rgb_float_to_uchar(), ImBuf::x, and x.

Referenced by bake_images().

◆ bake_ibuf_filter()

static void bake_ibuf_filter ( ImBuf * ibuf,
char * mask,
const int margin,
const char margin_type,
DerivedMesh * dm,
const float uv_offset[2] )
static

◆ bake_ibuf_normalize_displacement()

static void bake_ibuf_normalize_displacement ( ImBuf * ibuf,
const float * displacement,
const char * mask,
float displacement_min,
float displacement_max )
static

◆ bake_images()

◆ bake_rasterize()

static void bake_rasterize ( const MBakeRast * bake_rast,
const float st0_in[2],
const float st1_in[2],
const float st2_in[2] )
static

Definition at line 294 of file multires_bake.cc.

References ceilf, MBakeRast::h, int, rasterize_half(), MBakeRast::w, and w().

Referenced by do_multires_bake_thread().

◆ count_images()

◆ do_multires_bake()

static void do_multires_bake ( MultiresBakeRender * bkr,
Image * ima,
ImageTile * tile,
ImBuf * ibuf,
bool require_tangent,
MPassKnownData passKnownData,
MInitBakeData initBakeData,
MFreeBakeData freeBakeData,
MultiresBakeResult * result )
static

◆ do_multires_bake_thread()

◆ finish_images()

◆ flush_pixel()

static void flush_pixel ( const MResolvePixelData * data,
const int x,
const int y )
static

◆ free_heights_data()

static void free_heights_data ( void * bake_data)
static

Definition at line 851 of file multires_bake.cc.

References MEM_freeN(), DerivedMesh::release, and MHeightBakeData::ssdm.

Referenced by bake_images().

◆ free_normal_data()

static void free_normal_data ( void * bake_data)
static

Definition at line 976 of file multires_bake.cc.

References MEM_freeN().

Referenced by bake_images().

◆ get_ccgdm_data()

static void get_ccgdm_data ( const blender::OffsetIndices< int > lores_polys,
DerivedMesh * hidm,
const int * index_mp_to_orig,
const int lvl,
const int face_index,
const float u,
const float v,
float co[3],
float n[3] )
static

◆ init_bake_rast()

static void init_bake_rast ( MBakeRast * bake_rast,
const ImBuf * ibuf,
const MResolvePixelData * data,
MFlushPixel flush_pixel,
bool * do_update )
static

◆ init_ccgdm_arrays()

static void init_ccgdm_arrays ( DerivedMesh * dm)
static

◆ init_heights_data()

◆ init_normal_data()

static void * init_normal_data ( MultiresBakeRender * bkr,
ImBuf *  )
static

◆ interp_barycentric_corner_tri()

static void interp_barycentric_corner_tri ( const blender::Span< blender::float3 > vert_positions,
const blender::Span< blender::float3 > vert_normals,
const blender::Span< int > corner_verts,
const blender::int3 & corner_tri,
const float u,
const float v,
const int mode,
float res[3] )
static

Definition at line 786 of file multires_bake.cc.

References copy_v3_v3(), interp_barycentric_tri_v3(), and v.

Referenced by apply_heights_callback().

◆ interp_bilinear_grid()

static void interp_bilinear_grid ( const CCGKey & key,
CCGElem * grid,
float crn_x,
float crn_y,
int mode,
float res[3] )
static

◆ interp_bilinear_mpoly()

static void interp_bilinear_mpoly ( const blender::Span< blender::float3 > vert_positions,
const blender::Span< blender::float3 > vert_normals,
const blender::Span< int > corner_verts,
const blender::IndexRange face,
const float u,
const float v,
const int mode,
float res[3] )
static

Definition at line 759 of file multires_bake.cc.

References copy_v3_v3(), interp_bilinear_quad_v3(), and v.

Referenced by apply_heights_callback().

◆ multires_bake_queue_next_tri()

static int multires_bake_queue_next_tri ( MultiresBakeQueue * queue)
static

Definition at line 374 of file multires_bake.cc.

References BLI_spin_lock(), and BLI_spin_unlock().

Referenced by do_multires_bake_thread().

◆ multiresbake_get_normal()

static void multiresbake_get_normal ( const MResolvePixelData * data,
const int tri_num,
const int vert_index,
float r_normal[3] )
static

Definition at line 125 of file multires_bake.cc.

References copy_v3_v3().

Referenced by flush_pixel().

◆ multiresbake_test_break()

static int multiresbake_test_break ( MultiresBakeRender * bkr)
static

Definition at line 340 of file multires_bake.cc.

References G, and MultiresBakeRender::stop.

Referenced by do_multires_bake_thread().

◆ rasterize_half()

static void rasterize_half ( const MBakeRast * bake_rast,
const float s0_s,
const float t0_s,
const float s1_s,
const float t1_s,
const float s0_l,
const float t0_l,
const float s1_l,
const float t1_l,
const int y0_in,
const int y1_in,
const int is_mid_right )
static

Definition at line 244 of file multires_bake.cc.

References ceilf, fabsf, MBakeRast::h, int, set_rast_triangle(), MBakeRast::w, w(), x, and y.

Referenced by bake_rasterize().

◆ RE_multires_bake_images()

◆ set_rast_triangle()

static void set_rast_triangle ( const MBakeRast * bake_rast,
const int x,
const int y )
static