Blender V4.3
hair_volume.cc File Reference
#include <algorithm>
#include "MEM_guardedalloc.h"
#include "BLI_math_matrix.h"
#include "BLI_math_vector.h"
#include "BLI_utildefines.h"
#include "DNA_texture_types.h"
#include "BKE_effect.h"
#include "eigen_utils.h"
#include "implicit.h"

Go to the source code of this file.

Classes

struct  HairGridVert
 
struct  HairGrid
 

Macros

#define HAIR_GRID_INDEX_AXIS(vec, res, gmin, scale, axis)    min_ii(max_ii(int((vec[axis] - gmin[axis]) * scale), 0), res[axis] - 2)
 
#define MARGIN_i0   (i < 1)
 
#define MARGIN_j0   (j < 1)
 
#define MARGIN_k0   (k < 1)
 
#define MARGIN_i1   (i >= resA[0] - 1)
 
#define MARGIN_j1   (j >= resA[1] - 1)
 
#define MARGIN_k1   (k >= resA[2] - 1)
 
#define NEIGHBOR_MARGIN_i0   (i < 2)
 
#define NEIGHBOR_MARGIN_j0   (j < 2)
 
#define NEIGHBOR_MARGIN_k0   (k < 2)
 
#define NEIGHBOR_MARGIN_i1   (i >= resA[0] - 2)
 
#define NEIGHBOR_MARGIN_j1   (j >= resA[1] - 2)
 
#define NEIGHBOR_MARGIN_k1   (k >= resA[2] - 2)
 

Functions

BLI_INLINE int floor_int (float value)
 
BLI_INLINE float floor_mod (float value)
 
BLI_INLINE int hair_grid_size (const int res[3])
 
BLI_INLINE int hair_grid_offset (const float vec[3], const int res[3], const float gmin[3], float scale)
 
BLI_INLINE int hair_grid_interp_weights (const int res[3], const float gmin[3], float scale, const float vec[3], float uvw[3])
 
BLI_INLINE void hair_grid_interpolate (const HairGridVert *grid, const int res[3], const float gmin[3], float scale, const float vec[3], float *density, float velocity[3], float vel_smooth[3], float density_gradient[3], float velocity_gradient[3][3])
 
void SIM_hair_volume_vertex_grid_forces (HairGrid *grid, const float x[3], const float v[3], float smoothfac, float pressurefac, float minpressure, float f[3], float dfdx[3][3], float dfdv[3][3])
 
void SIM_hair_volume_grid_interpolate (HairGrid *grid, const float x[3], float *density, float velocity[3], float velocity_smooth[3], float density_gradient[3], float velocity_gradient[3][3])
 
void SIM_hair_volume_grid_velocity (HairGrid *grid, const float x[3], const float v[3], float fluid_factor, float r_v[3])
 
void SIM_hair_volume_grid_clear (HairGrid *grid)
 
BLI_INLINE bool hair_grid_point_valid (const float vec[3], const float gmin[3], const float gmax[3])
 
BLI_INLINE float dist_tent_v3f3 (const float a[3], float x, float y, float z)
 
BLI_INLINE float weights_sum (const float weights[8])
 
BLI_INLINE int hair_grid_weights (const int res[3], const float gmin[3], float scale, const float vec[3], float weights[8])
 
BLI_INLINE void grid_to_world (HairGrid *grid, float vecw[3], const float vec[3])
 
void SIM_hair_volume_add_vertex (HairGrid *grid, const float x[3], const float v[3])
 
BLI_INLINE void hair_volume_eval_grid_vertex_sample (HairGridVert *vert, const float loc[3], float radius, float dist_scale, const float x[3], const float v[3])
 
void SIM_hair_volume_add_segment (HairGrid *grid, const float[3], const float[3], const float x2[3], const float v2[3], const float x3[3], const float v3[3], const float[3], const float[3], const float[3], const float[3], const float[3])
 
void SIM_hair_volume_normalize_vertex_grid (HairGrid *grid)
 
BLI_INLINE float hair_volume_density_divergence (float density, float target_density, float strength)
 
bool SIM_hair_volume_solve_divergence (HairGrid *grid, float, float target_density, float target_strength)
 
HairGridSIM_hair_volume_create_vertex_grid (float cellsize, const float gmin[3], const float gmax[3])
 
void SIM_hair_volume_free_vertex_grid (HairGrid *grid)
 
void SIM_hair_volume_grid_geometry (HairGrid *grid, float *cellsize, int res[3], float gmin[3], float gmax[3])
 

Variables

static float I [3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}
 
static const float density_threshold = 0.001f
 

Macro Definition Documentation

◆ HAIR_GRID_INDEX_AXIS

#define HAIR_GRID_INDEX_AXIS ( vec,
res,
gmin,
scale,
axis )    min_ii(max_ii(int((vec[axis] - gmin[axis]) * scale), 0), res[axis] - 2)

Definition at line 74 of file hair_volume.cc.

Referenced by hair_grid_interp_weights(), hair_grid_offset(), and hair_grid_weights().

◆ MARGIN_i0

#define MARGIN_i0   (i < 1)

◆ MARGIN_i1

#define MARGIN_i1   (i >= resA[0] - 1)

◆ MARGIN_j0

#define MARGIN_j0   (j < 1)

◆ MARGIN_j1

#define MARGIN_j1   (j >= resA[1] - 1)

◆ MARGIN_k0

#define MARGIN_k0   (k < 1)

◆ MARGIN_k1

#define MARGIN_k1   (k >= resA[2] - 1)

◆ NEIGHBOR_MARGIN_i0

#define NEIGHBOR_MARGIN_i0   (i < 2)

◆ NEIGHBOR_MARGIN_i1

#define NEIGHBOR_MARGIN_i1   (i >= resA[0] - 2)

◆ NEIGHBOR_MARGIN_j0

#define NEIGHBOR_MARGIN_j0   (j < 2)

◆ NEIGHBOR_MARGIN_j1

#define NEIGHBOR_MARGIN_j1   (j >= resA[1] - 2)

◆ NEIGHBOR_MARGIN_k0

#define NEIGHBOR_MARGIN_k0   (k < 2)

◆ NEIGHBOR_MARGIN_k1

#define NEIGHBOR_MARGIN_k1   (k >= resA[2] - 2)

Function Documentation

◆ dist_tent_v3f3()

BLI_INLINE float dist_tent_v3f3 ( const float a[3],
float x,
float y,
float z )

Definition at line 302 of file hair_volume.cc.

References fabsf, w(), and z().

Referenced by hair_grid_weights().

◆ floor_int()

BLI_INLINE int floor_int ( float value)

Definition at line 44 of file hair_volume.cc.

References int.

Referenced by SIM_hair_volume_add_segment(), and SIM_hair_volume_create_vertex_grid().

◆ floor_mod()

BLI_INLINE float floor_mod ( float value)

Definition at line 49 of file hair_volume.cc.

References floorf.

◆ grid_to_world()

BLI_INLINE void grid_to_world ( HairGrid * grid,
float vecw[3],
const float vec[3] )

◆ hair_grid_interp_weights()

BLI_INLINE int hair_grid_interp_weights ( const int res[3],
const float gmin[3],
float scale,
const float vec[3],
float uvw[3] )

Definition at line 89 of file hair_volume.cc.

References BLI_assert, and HAIR_GRID_INDEX_AXIS.

Referenced by hair_grid_interpolate().

◆ hair_grid_interpolate()

BLI_INLINE void hair_grid_interpolate ( const HairGridVert * grid,
const int res[3],
const float gmin[3],
float scale,
const float vec[3],
float * density,
float velocity[3],
float vel_smooth[3],
float density_gradient[3],
float velocity_gradient[3][3] )

◆ hair_grid_offset()

BLI_INLINE int hair_grid_offset ( const float vec[3],
const int res[3],
const float gmin[3],
float scale )

Definition at line 77 of file hair_volume.cc.

References HAIR_GRID_INDEX_AXIS.

◆ hair_grid_point_valid()

BLI_INLINE bool hair_grid_point_valid ( const float vec[3],
const float gmin[3],
const float gmax[3] )

Definition at line 296 of file hair_volume.cc.

Referenced by SIM_hair_volume_add_vertex().

◆ hair_grid_size()

◆ hair_grid_weights()

BLI_INLINE int hair_grid_weights ( const int res[3],
const float gmin[3],
float scale,
const float vec[3],
float weights[8] )

Definition at line 319 of file hair_volume.cc.

References dist_tent_v3f3(), and HAIR_GRID_INDEX_AXIS.

Referenced by SIM_hair_volume_add_vertex().

◆ hair_volume_density_divergence()

BLI_INLINE float hair_volume_density_divergence ( float density,
float target_density,
float strength )

Definition at line 697 of file hair_volume.cc.

References density_threshold, and logf.

Referenced by SIM_hair_volume_solve_divergence().

◆ hair_volume_eval_grid_vertex_sample()

BLI_INLINE void hair_volume_eval_grid_vertex_sample ( HairGridVert * vert,
const float loc[3],
float radius,
float dist_scale,
const float x[3],
const float v[3] )

◆ SIM_hair_volume_add_segment()

void SIM_hair_volume_add_segment ( HairGrid * grid,
const float x1[3],
const float v1[3],
const float x2[3],
const float v2[3],
const float x3[3],
const float v3[3],
const float x4[3],
const float v4[3],
const float dir1[3],
const float dir2[3],
const float dir3[3] )

◆ SIM_hair_volume_add_vertex()

void SIM_hair_volume_add_vertex ( HairGrid * grid,
const float x[3],
const float v[3] )

Definition at line 355 of file hair_volume.cc.

References hair_grid_point_valid(), hair_grid_weights(), madd_v3_v3fl(), and v.

Referenced by cloth_continuum_fill_grid().

◆ SIM_hair_volume_create_vertex_grid()

HairGrid * SIM_hair_volume_create_vertex_grid ( float cellsize,
const float gmin[3],
const float gmax[3] )

◆ SIM_hair_volume_free_vertex_grid()

void SIM_hair_volume_free_vertex_grid ( HairGrid * grid)

Definition at line 1164 of file hair_volume.cc.

References MEM_freeN().

Referenced by cloth_continuum_step().

◆ SIM_hair_volume_grid_clear()

void SIM_hair_volume_grid_clear ( HairGrid * grid)

Definition at line 284 of file hair_volume.cc.

References hair_grid_size(), size(), and zero_v3().

◆ SIM_hair_volume_grid_geometry()

void SIM_hair_volume_grid_geometry ( HairGrid * grid,
float * cellsize,
int res[3],
float gmin[3],
float gmax[3] )

Definition at line 1174 of file hair_volume.cc.

References copy_v3_v3(), and copy_v3_v3_int().

Referenced by cloth_continuum_fill_grid(), and cloth_continuum_step().

◆ SIM_hair_volume_grid_interpolate()

void SIM_hair_volume_grid_interpolate ( HairGrid * grid,
const float x[3],
float * density,
float velocity[3],
float velocity_smooth[3],
float density_gradient[3],
float velocity_gradient[3][3] )

Definition at line 237 of file hair_volume.cc.

References hair_grid_interpolate().

Referenced by cloth_continuum_step().

◆ SIM_hair_volume_grid_velocity()

void SIM_hair_volume_grid_velocity ( struct HairGrid * grid,
const float x[3],
const float v[3],
float fluid_factor,
float r_v[3] )

Effect of fluid simulation grid on velocities. fluid_factor controls blending between PIC (Particle-in-Cell) and FLIP (Fluid-Implicit-Particle) methods (0 = only PIC, 1 = only FLIP)

Definition at line 257 of file hair_volume.cc.

References add_v3_v3(), copy_v3_v3(), hair_grid_interpolate(), interp_v3_v3v3(), sub_v3_v3v3(), and v.

Referenced by cloth_continuum_step().

◆ SIM_hair_volume_normalize_vertex_grid()

void SIM_hair_volume_normalize_vertex_grid ( HairGrid * grid)

Definition at line 678 of file hair_volume.cc.

References hair_grid_size(), mul_v3_fl(), and size().

Referenced by cloth_continuum_fill_grid().

◆ SIM_hair_volume_solve_divergence()

◆ SIM_hair_volume_vertex_grid_forces()

void SIM_hair_volume_vertex_grid_forces ( struct HairGrid * grid,
const float x[3],
const float v[3],
float smoothfac,
float pressurefac,
float minpressure,
float f[3],
float dfdx[3][3],
float dfdv[3][3] )

WARNING: expressing grid effects on velocity as a force is not very stable, due to discontinuities in interpolated values! Better use hybrid approaches such as described in "Detail Preserving Continuum Simulation of Straight Hair" (McAdams, Selle 2009)

Definition at line 198 of file hair_volume.cc.

References hair_grid_interpolate(), I, madd_v3_v3fl(), mul_m3_fl(), mul_v3_fl(), mul_v3_v3fl(), normalize_v3(), sub_m3_m3m3(), sub_v3_v3(), v, zero_m3(), and zero_v3().

◆ weights_sum()

BLI_INLINE float weights_sum ( const float weights[8])

Definition at line 308 of file hair_volume.cc.

Referenced by blender::compositor::karis_brightness_weighted_sum().

Variable Documentation

◆ density_threshold

const float density_threshold = 0.001f
static

◆ I

float I[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}
static

Definition at line 42 of file hair_volume.cc.

Referenced by SIM_hair_volume_vertex_grid_forces().