Blender V5.0
multires_bake.cc File Reference
#include "RE_multires_bake.h"
#include <atomic>
#include "DNA_mesh_types.h"
#include "DNA_modifier_types.h"
#include "BLI_array.hh"
#include "BLI_listbase.h"
#include "BLI_math_base.hh"
#include "BLI_math_geom.h"
#include "BLI_math_matrix.hh"
#include "BLI_math_vector.hh"
#include "BLI_span.hh"
#include "BLI_task.hh"
#include "BLI_threads.h"
#include "BKE_attribute.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_tangent.hh"
#include "BKE_multires.hh"
#include "BKE_subdiv.hh"
#include "BKE_subdiv_ccg.hh"
#include "BKE_subdiv_eval.hh"
#include "BKE_subdiv_foreach.hh"
#include "BKE_subdiv_mesh.hh"
#include "IMB_imbuf.hh"
#include "IMB_imbuf_types.hh"
#include "DEG_depsgraph.hh"
#include "RE_texture_margin.h"

Go to the source code of this file.

Namespaces

namespace  blender
namespace  blender::render

Functions

void RE_multires_bake_images (MultiresBakeRender &bake)

Detailed Description

Baker from the Multires

This file is an implementation of a special baking mode which bakes data (normals, displacement) from the highest multi-resolution level to the current viewport subdivision level.

The initial historical reasoning for having such baker was:

  • Lower memory footprint than the regular baker.
  • Performance (due to lower overhead compared to the regular baker at that time).
  • Ease of use: no need to have explicit object to define cage. Over the time some of these points became less relevant, but the ease of use is still there.

The general idea of the algorithm is pretty simple:

  • Rasterize UV of the mesh at the bake level.
  • For every UV pixel that is rasterized, figure out attributes on the bake level mesh and the highest subdivision multi-resolution level (such as normal, position).
  • Do the math (like convert normal to the tangent space),
  • Write pixel to the image.

SubdivCCG is used to access attributes at the highest multi-resolution subdivision level.

The core rasterization logic works on triangles and those triangles are fed to the rasterizer in a way that makes it easy to sample attributes in the SubdivCCG:

  • Triangle knows which CCG index it corresponds to (triangle never covers multiple grids).
  • It also knows UV coordinates of its vertices within that grid.

The way triangles are calculated when baking to the base level is pretty straightforward:

  • Triangles are actually calculated from a quad.
  • Quad vertices align with the grid vertices. This means that the top level loop iterates over face corners, calculates quad for the grids, and passes it to the triangle rasterization.

When baking to a non-0 subdivision level a special trick is used to know grid index and its UV coordinates in the base mesh: for every loop in the bake-level mesh the algorithm calculates this information using subdiv's foreach logic. This assumes that the bake level mesh is calculated using the same foreach logic.

Use low resolution mesh

This is a special option for the displacement baker.

When it is ON: displacement is calculated between the multi-resolution at the highest subdivision level and the bake-level mesh.

When it is OFF: displacement is calculated between the multi-resolution at the highest subdivision level and a mesh which is created from the bake level mesh by subdividing it further to reach the same subdivision level of the highest multi-resolution level. Additionally, the texture UV, and UV tangents are used from this "special" mesh.

Possible optimizations

  • Reuse mesh from the viewport as bake-level mesh.

    It could be a bit challenging since mesh could be in sculpt mode, where it has own SubdivCCG and does not have UV map on the subdivided state. Additionally, it will make it harder to calculate tangent space as well.

Definition in file multires_bake.cc.

Function Documentation

◆ RE_multires_bake_images()

void RE_multires_bake_images ( MultiresBakeRender & bake)