Blender V4.3
lineart_shadow.cc File Reference
#include "MOD_lineart.hh"
#include "lineart_intern.hh"
#include "BKE_global.hh"
#include "BKE_grease_pencil.hh"
#include "BKE_grease_pencil_legacy_convert.hh"
#include "BKE_object.hh"
#include "BLI_math_matrix.h"
#include "BLI_math_rotation.h"
#include "BLI_task.h"
#include "BLI_time.h"
#include "DNA_light_types.h"
#include "DNA_modifier_types.h"
#include "MEM_guardedalloc.h"

Go to the source code of this file.

Classes

struct  LineartShadowFinalizeData
 

Macros

#define DISCARD_NONSENSE_SEGMENTS
 
#define GET_RATIO(n)
 

Functions

LineartElementLinkNodelineart_find_matching_eln (ListBase *shadow_elns, int obindex)
 
LineartEdgelineart_find_matching_edge (LineartElementLinkNode *shadow_eln, uint64_t edge_identifier)
 
static bool lineart_contour_viewed_from_dark_side (LineartData *ld, LineartEdge *e)
 
void lineart_register_shadow_cuts (LineartData *ld, LineartEdge *e, LineartEdge *shadow_edge)
 
void lineart_register_intersection_shadow_cuts (LineartData *ld, ListBase *shadow_elns)
 
static LineartShadowSegmentlineart_give_shadow_segment (LineartData *ld)
 
static void lineart_shadow_segment_slice_get (double *fb_co_1, double *fb_co_2, double *gloc_1, double *gloc_2, double ratio, double at_1, double at_2, double *r_fb_co, double *r_gloc)
 
static bool lineart_do_closest_segment (bool is_persp, double *s1_fb_co_1, double *s1_fb_co_2, double *s2_fb_co_1, double *s2_fb_co_2, double *s1_gloc_1, double *s1_gloc_2, double *s2_gloc_1, double *s2_gloc_2, double *r_fb_co_1, double *r_fb_co_2, double *r_gloc_1, double *r_gloc_2, double *r_new_in_the_middle, double *r_new_in_the_middle_global, double *r_new_at, bool *is_side_2r, bool *use_new_ref)
 
static void lineart_shadow_create_shadow_edge_array (LineartData *ld, bool transform_edge_cuts, bool do_light_contour)
 
static void lineart_shadow_edge_cut (LineartData *ld, LineartShadowEdge *e, double start, double end, double *start_gloc, double *end_gloc, double *start_fb_co, double *end_fb_co, bool facing_light, uint32_t target_reference)
 
static bool lineart_shadow_cast_onto_triangle (LineartData *ld, LineartTriangle *tri, LineartShadowEdge *sedge, double *r_at_1, double *r_at_2, double *r_fb_co_1, double *r_fb_co_2, double *r_gloc_1, double *r_gloc_2, bool *r_facing_light)
 
static void lineart_shadow_cast (LineartData *ld, bool transform_edge_cuts, bool do_light_contour)
 
static bool lineart_shadow_cast_generate_edges (LineartData *ld, bool do_original_edges, LineartElementLinkNode **r_veln, LineartElementLinkNode **r_eeln)
 
static void lineart_shadow_register_silhouette (LineartData *ld)
 
static void lineart_shadow_register_enclosed_shapes (LineartData *ld, LineartData *shadow_ld)
 
bool lineart_main_try_generate_shadow_v3 (Depsgraph *depsgraph, Scene *scene, LineartData *original_ld, GreasePencilLineartModifierData *lmd, LineartStaticMemPool *shadow_data_pool, LineartElementLinkNode **r_veln, LineartElementLinkNode **r_eeln, ListBase *r_calculated_edges_eln_list, LineartData **r_shadow_ld_if_reproject)
 
bool lineart_main_try_generate_shadow (Depsgraph *depsgraph, Scene *scene, LineartData *original_ld, LineartGpencilModifierData *lmd_legacy, LineartStaticMemPool *shadow_data_pool, LineartElementLinkNode **r_veln, LineartElementLinkNode **r_eeln, ListBase *r_calculated_edges_eln_list, LineartData **r_shadow_ld_if_reproject)
 
static void lineart_shadow_transform_task (void *__restrict userdata, const int element_index, const TaskParallelTLS *__restrict)
 
static void lineart_shadow_finalize_shadow_edges_task (void *__restrict userdata, const int i, const TaskParallelTLS *__restrict)
 
void lineart_main_transform_and_add_shadow (LineartData *ld, LineartElementLinkNode *veln, LineartElementLinkNode *eeln)
 
void lineart_main_make_enclosed_shapes (LineartData *ld, LineartData *shadow_ld)
 

Macro Definition Documentation

◆ DISCARD_NONSENSE_SEGMENTS

#define DISCARD_NONSENSE_SEGMENTS
Value:
if (es->occlusion != 0 || \
(es->next && LRT_DOUBLE_CLOSE_ENOUGH(es->ratio, ((LineartEdgeSegment *)es->next)->ratio))) \
{ \
continue; \
}
#define LRT_DOUBLE_CLOSE_ENOUGH(a, b)
#define LRT_ITER_ALL_LINES_NEXT

Referenced by lineart_shadow_create_shadow_edge_array().

◆ GET_RATIO

#define GET_RATIO ( n)
Value:
(fabs(orig_e->v2->fbcoord[0] - orig_e->v1->fbcoord[0]) > \
fabs(orig_e->v2->fbcoord[1] - orig_e->v1->fbcoord[1])) ? \
((g##n##v[0] - orig_e->v1->fbcoord[0]) / \
(orig_e->v2->fbcoord[0] - orig_e->v1->fbcoord[0])) : \
((g##n##v[1] - orig_e->v1->fbcoord[1]) / (orig_e->v2->fbcoord[1] - orig_e->v1->fbcoord[1]))
ATTR_WARN_UNUSED_RESULT const BMVert * v
ccl_device_inline float2 fabs(const float2 a)

Referenced by lineart_shadow_register_enclosed_shapes().

Function Documentation

◆ lineart_contour_viewed_from_dark_side()

◆ lineart_do_closest_segment()

static bool lineart_do_closest_segment ( bool is_persp,
double * s1_fb_co_1,
double * s1_fb_co_2,
double * s2_fb_co_1,
double * s2_fb_co_2,
double * s1_gloc_1,
double * s1_gloc_2,
double * s2_gloc_1,
double * s2_gloc_2,
double * r_fb_co_1,
double * r_fb_co_2,
double * r_gloc_1,
double * r_gloc_2,
double * r_new_in_the_middle,
double * r_new_in_the_middle_global,
double * r_new_at,
bool * is_side_2r,
bool * use_new_ref )
static

This function tries to get the closest projected segments along two end points. The x,y of s1, s2 are aligned in frame-buffer coordinates, only z,w are different. We will get the closest z/w as well as the corresponding global coordinates.

(far side)
l-------r [s1] ^
_-r [s2] | In this situation it will essentially return the coordinates of s2.
_-` |
l-` |
(far side)
_-r [s2] ^
_-` | In this case the return coordinates would be `s2l` and `s1r`,
l-----_c`-----r [s1] | and `r_new` will be assigned coordinates of `c`.
_-` |
l-` |

Returns true when a new cut (c) is needed in the middle, otherwise returns false, and *r_new_xxx are not touched.

Definition at line 222 of file lineart_shadow.cc.

References copy_v3_v3_db(), copy_v4_v4_db(), interp_v3_v3v3_db(), interpd(), and ratiod().

Referenced by lineart_shadow_edge_cut().

◆ lineart_find_matching_edge()

LineartEdge * lineart_find_matching_edge ( LineartElementLinkNode * shadow_eln,
uint64_t edge_identifier )

◆ lineart_find_matching_eln()

◆ lineart_give_shadow_segment()

◆ lineart_main_make_enclosed_shapes()

◆ lineart_main_transform_and_add_shadow()

◆ lineart_main_try_generate_shadow()

bool lineart_main_try_generate_shadow ( struct Depsgraph * depsgraph,
struct Scene * scene,
struct LineartData * original_ld,
struct LineartGpencilModifierData * lmd_legacy,
struct LineartStaticMemPool * shadow_data_pool,
struct LineartElementLinkNode ** r_veln,
struct LineartElementLinkNode ** r_eeln,
struct ListBase * r_calculated_edges_eln_list,
struct LineartData ** r_shadow_ld_if_reproject )

This call would internally duplicate #original_ld, override necessary configurations for shadow computations. It will return:

1) Generated shadow edges in format of LineartElementLinkNode which can be directly loaded into later main view camera occlusion stage. 2) Shadow render buffer if 3rd stage reprojection is need for silhouette/lit/shaded region selection. Otherwise the shadow render buffer is deleted before this function returns.

Definition at line 1314 of file lineart_shadow.cc.

References depsgraph, lineart_main_try_generate_shadow_v3(), blender::bke::greasepencil::convert::lineart_unwrap_v3(), blender::bke::greasepencil::convert::lineart_wrap_v3(), and ret.

◆ lineart_main_try_generate_shadow_v3()

bool lineart_main_try_generate_shadow_v3 ( Depsgraph * depsgraph,
Scene * scene,
LineartData * original_ld,
GreasePencilLineartModifierData * lmd,
LineartStaticMemPool * shadow_data_pool,
LineartElementLinkNode ** r_veln,
LineartElementLinkNode ** r_eeln,
ListBase * r_calculated_edges_eln_list,
LineartData ** r_shadow_ld_if_reproject )

Definition at line 1146 of file lineart_shadow.cc.

References LineartData::_conf::allow_duplicated_types, BLI_spin_init(), BLI_time_now_seconds(), LineartData::_conf::cam_is_persp, LineartData::_conf::cam_is_persp_secondary, LineartData::_conf::cam_obmat, LineartData::_conf::cam_obmat_secondary, LineartData::_conf::camera_pos, LineartData::_conf::camera_pos_secondary, LineartData::conf, copy_m4_m4(), copy_m4_m4_db(), copy_v3_v3_db(), copy_v3db_v3fl(), Object::data, DEG2RAD, depsgraph, LineartData::_conf::do_shadow_cast, LineartData::edge_data_pool, LineartData::_conf::far_clip, ListBase::first, GreasePencilLineartModifierData::flags, G, LineartData::geom, LineartData::h, invert_m4_m4(), LA_SUN, GreasePencilLineartModifierData::light_contour_object, LineartData::_geom::line_buffer_pointers, lineart_destroy_render_data_keep_init(), lineart_main_add_triangles(), lineart_main_bounding_area_make_initial(), lineart_main_bounding_areas_connect_post(), lineart_main_cull_triangles(), lineart_main_discard_out_of_frame_edges(), lineart_main_free_adjacent_data(), lineart_main_get_view_vector(), lineart_main_link_lines(), lineart_main_load_geometries(), lineart_main_occlusion_begin(), lineart_main_perspective_division(), lineart_matrix_ortho_44d(), lineart_matrix_perspective_44d(), lineart_shadow_cast(), lineart_shadow_cast_generate_edges(), LineartData::lock_cuts, LineartStaticMemPool::lock_mem, LineartData::lock_task, LRT_TILE_RECURSIVE_ORTHO, LRT_TILE_RECURSIVE_PERSPECTIVE, LineartData::_conf::max_occlusion_level, MEM_freeN(), MEM_mallocN, MOD_LINEART_ALLOW_DUPLI_OBJECTS, mul_m4db_m4db_m4fl(), LineartData::_conf::near_clip, OB_LAMP, LineartModifierRuntime::object_dependencies, printf, LineartData::qtree, LineartData::_qtree::recursive_level, LineartData::render_data_pool, GreasePencilLineartModifierData::runtime, GreasePencilLineartModifierData::shadow_camera_far, GreasePencilLineartModifierData::shadow_camera_near, GreasePencilLineartModifierData::shadow_camera_size, LineartData::shadow_data_pool, LineartData::_conf::shadow_enclose_shapes, LineartData::_conf::shadow_selection, Light::type, Object::type, unit_m4_db(), LineartData::_conf::use_back_face_culling, LineartData::_conf::use_contour, LineartData::_conf::use_contour_secondary, LineartData::_conf::use_crease, LineartData::_conf::use_edge_marks, LineartData::_conf::use_intersections, LineartData::_conf::use_light_contour, LineartData::_conf::use_loose, LineartData::_conf::use_material, LineartData::_conf::use_shadow, LineartData::_geom::vertex_buffer_pointers, LineartData::_conf::view, LineartData::_conf::view_projection, and LineartData::w.

Referenced by lineart_main_try_generate_shadow(), and MOD_lineart_compute_feature_lines_v3().

◆ lineart_register_intersection_shadow_cuts()

◆ lineart_register_shadow_cuts()

void lineart_register_shadow_cuts ( struct LineartData * ld,
struct LineartEdge * e,
struct LineartEdge * shadow_edge )

Cuts the original edge based on the occlusion results under light-camera, if segment is occluded in light-camera, then that segment on the original edge must be shaded.

Definition at line 96 of file lineart_shadow.cc.

References e, lineart_contour_viewed_from_dark_side(), lineart_edge_cut(), LISTBASE_FOREACH, LRT_SHADOW_MASK_ILLUMINATED, LRT_SHADOW_MASK_SHADED, and LineartEdge::segments.

Referenced by lineart_geometry_object_load(), and lineart_register_intersection_shadow_cuts().

◆ lineart_shadow_cast()

◆ lineart_shadow_cast_generate_edges()

◆ lineart_shadow_cast_onto_triangle()

◆ lineart_shadow_create_shadow_edge_array()

◆ lineart_shadow_edge_cut()

◆ lineart_shadow_finalize_shadow_edges_task()

static void lineart_shadow_finalize_shadow_edges_task ( void *__restrict userdata,
const int i,
const TaskParallelTLS * __restrict )
static

◆ lineart_shadow_register_enclosed_shapes()

◆ lineart_shadow_register_silhouette()

◆ lineart_shadow_segment_slice_get()

static void lineart_shadow_segment_slice_get ( double * fb_co_1,
double * fb_co_2,
double * gloc_1,
double * gloc_2,
double ratio,
double at_1,
double at_2,
double * r_fb_co,
double * r_gloc )
static

Definition at line 175 of file lineart_shadow.cc.

References interp_v3_v3v3_db(), and interpd().

Referenced by lineart_shadow_edge_cut().

◆ lineart_shadow_transform_task()

static void lineart_shadow_transform_task ( void *__restrict userdata,
const int element_index,
const TaskParallelTLS * __restrict )
static