Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/subdiv_ccg.c
| Show First 20 Lines • Show All 228 Lines • ▼ Show 20 Lines | static void subdiv_ccg_eval_grid_element(CCGEvalGridsData *data, | ||||
| subdiv_ccg_eval_grid_element_mask(data, ptex_face_index, u, v, element); | subdiv_ccg_eval_grid_element_mask(data, ptex_face_index, u, v, element); | ||||
| } | } | ||||
| static void subdiv_ccg_eval_regular_grid(CCGEvalGridsData *data, const int face_index) | static void subdiv_ccg_eval_regular_grid(CCGEvalGridsData *data, const int face_index) | ||||
| { | { | ||||
| SubdivCCG *subdiv_ccg = data->subdiv_ccg; | SubdivCCG *subdiv_ccg = data->subdiv_ccg; | ||||
| const int ptex_face_index = data->face_ptex_offset[face_index]; | const int ptex_face_index = data->face_ptex_offset[face_index]; | ||||
| const int grid_size = subdiv_ccg->grid_size; | const int grid_size = subdiv_ccg->grid_size; | ||||
| const float grid_size_1_inv = 1.0f / (float)(grid_size - 1); | const float grid_size_1_inv = 1.0f / (grid_size - 1); | ||||
| const int element_size = element_size_bytes_get(subdiv_ccg); | const int element_size = element_size_bytes_get(subdiv_ccg); | ||||
| SubdivCCGFace *faces = subdiv_ccg->faces; | SubdivCCGFace *faces = subdiv_ccg->faces; | ||||
| SubdivCCGFace **grid_faces = subdiv_ccg->grid_faces; | SubdivCCGFace **grid_faces = subdiv_ccg->grid_faces; | ||||
| const SubdivCCGFace *face = &faces[face_index]; | const SubdivCCGFace *face = &faces[face_index]; | ||||
| for (int corner = 0; corner < face->num_grids; corner++) { | for (int corner = 0; corner < face->num_grids; corner++) { | ||||
| const int grid_index = face->start_grid_index + corner; | const int grid_index = face->start_grid_index + corner; | ||||
| unsigned char *grid = (unsigned char *)subdiv_ccg->grids[grid_index]; | unsigned char *grid = (unsigned char *)subdiv_ccg->grids[grid_index]; | ||||
| for (int y = 0; y < grid_size; y++) { | for (int y = 0; y < grid_size; y++) { | ||||
| const float grid_v = (float)y * grid_size_1_inv; | const float grid_v = y * grid_size_1_inv; | ||||
| for (int x = 0; x < grid_size; x++) { | for (int x = 0; x < grid_size; x++) { | ||||
| const float grid_u = (float)x * grid_size_1_inv; | const float grid_u = x * grid_size_1_inv; | ||||
| float u, v; | float u, v; | ||||
| BKE_subdiv_rotate_grid_to_quad(corner, grid_u, grid_v, &u, &v); | BKE_subdiv_rotate_grid_to_quad(corner, grid_u, grid_v, &u, &v); | ||||
| const size_t grid_element_index = (size_t)y * grid_size + x; | const size_t grid_element_index = (size_t)y * grid_size + x; | ||||
| const size_t grid_element_offset = grid_element_index * element_size; | const size_t grid_element_offset = grid_element_index * element_size; | ||||
| subdiv_ccg_eval_grid_element(data, ptex_face_index, u, v, &grid[grid_element_offset]); | subdiv_ccg_eval_grid_element(data, ptex_face_index, u, v, &grid[grid_element_offset]); | ||||
| } | } | ||||
| } | } | ||||
| /* Assign grid's face. */ | /* Assign grid's face. */ | ||||
| grid_faces[grid_index] = &faces[face_index]; | grid_faces[grid_index] = &faces[face_index]; | ||||
| /* Assign material flags. */ | /* Assign material flags. */ | ||||
| subdiv_ccg->grid_flag_mats[grid_index] = data->material_flags_evaluator->eval_material_flags( | subdiv_ccg->grid_flag_mats[grid_index] = data->material_flags_evaluator->eval_material_flags( | ||||
| data->material_flags_evaluator, face_index); | data->material_flags_evaluator, face_index); | ||||
| } | } | ||||
| } | } | ||||
| static void subdiv_ccg_eval_special_grid(CCGEvalGridsData *data, const int face_index) | static void subdiv_ccg_eval_special_grid(CCGEvalGridsData *data, const int face_index) | ||||
| { | { | ||||
| SubdivCCG *subdiv_ccg = data->subdiv_ccg; | SubdivCCG *subdiv_ccg = data->subdiv_ccg; | ||||
| const int grid_size = subdiv_ccg->grid_size; | const int grid_size = subdiv_ccg->grid_size; | ||||
| const float grid_size_1_inv = 1.0f / (float)(grid_size - 1); | const float grid_size_1_inv = 1.0f / (grid_size - 1); | ||||
| const int element_size = element_size_bytes_get(subdiv_ccg); | const int element_size = element_size_bytes_get(subdiv_ccg); | ||||
| SubdivCCGFace *faces = subdiv_ccg->faces; | SubdivCCGFace *faces = subdiv_ccg->faces; | ||||
| SubdivCCGFace **grid_faces = subdiv_ccg->grid_faces; | SubdivCCGFace **grid_faces = subdiv_ccg->grid_faces; | ||||
| const SubdivCCGFace *face = &faces[face_index]; | const SubdivCCGFace *face = &faces[face_index]; | ||||
| for (int corner = 0; corner < face->num_grids; corner++) { | for (int corner = 0; corner < face->num_grids; corner++) { | ||||
| const int grid_index = face->start_grid_index + corner; | const int grid_index = face->start_grid_index + corner; | ||||
| const int ptex_face_index = data->face_ptex_offset[face_index] + corner; | const int ptex_face_index = data->face_ptex_offset[face_index] + corner; | ||||
| unsigned char *grid = (unsigned char *)subdiv_ccg->grids[grid_index]; | unsigned char *grid = (unsigned char *)subdiv_ccg->grids[grid_index]; | ||||
| for (int y = 0; y < grid_size; y++) { | for (int y = 0; y < grid_size; y++) { | ||||
| const float u = 1.0f - ((float)y * grid_size_1_inv); | const float u = 1.0f - (y * grid_size_1_inv); | ||||
| for (int x = 0; x < grid_size; x++) { | for (int x = 0; x < grid_size; x++) { | ||||
| const float v = 1.0f - ((float)x * grid_size_1_inv); | const float v = 1.0f - (x * grid_size_1_inv); | ||||
| const size_t grid_element_index = (size_t)y * grid_size + x; | const size_t grid_element_index = (size_t)y * grid_size + x; | ||||
| const size_t grid_element_offset = grid_element_index * element_size; | const size_t grid_element_offset = grid_element_index * element_size; | ||||
| subdiv_ccg_eval_grid_element(data, ptex_face_index, u, v, &grid[grid_element_offset]); | subdiv_ccg_eval_grid_element(data, ptex_face_index, u, v, &grid[grid_element_offset]); | ||||
| } | } | ||||
| } | } | ||||
| /* Assign grid's face. */ | /* Assign grid's face. */ | ||||
| grid_faces[grid_index] = &faces[face_index]; | grid_faces[grid_index] = &faces[face_index]; | ||||
| /* Assign material flags. */ | /* Assign material flags. */ | ||||
| ▲ Show 20 Lines • Show All 472 Lines • ▼ Show 20 Lines | for (int x = 0; x < grid_size; x++) { | ||||
| counter++; | counter++; | ||||
| } | } | ||||
| } | } | ||||
| if (y >= 1 && x < grid_size_1) { | if (y >= 1 && x < grid_size_1) { | ||||
| add_v3_v3(normal_acc, face_normals[(y - 1) * grid_size_1 + x]); | add_v3_v3(normal_acc, face_normals[(y - 1) * grid_size_1 + x]); | ||||
| counter++; | counter++; | ||||
| } | } | ||||
| /* Normalize and store. */ | /* Normalize and store. */ | ||||
| mul_v3_v3fl(CCG_grid_elem_no(key, grid, x, y), normal_acc, 1.0f / (float)counter); | mul_v3_v3fl(CCG_grid_elem_no(key, grid, x, y), normal_acc, 1.0f / counter); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void subdiv_ccg_recalc_inner_normal_task(void *__restrict userdata_v, | static void subdiv_ccg_recalc_inner_normal_task(void *__restrict userdata_v, | ||||
| const int grid_index, | const int grid_index, | ||||
| const TaskParallelTLS *__restrict tls_v) | const TaskParallelTLS *__restrict tls_v) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 226 Lines • ▼ Show 20 Lines | static void subdiv_ccg_average_inner_face_grids(SubdivCCG *subdiv_ccg, | ||||
| * Guarantees correct and smooth averaging in the center. */ | * Guarantees correct and smooth averaging in the center. */ | ||||
| GridElementAccumulator center_accumulator; | GridElementAccumulator center_accumulator; | ||||
| element_accumulator_init(¢er_accumulator); | element_accumulator_init(¢er_accumulator); | ||||
| for (int corner = 0; corner < num_face_grids; corner++) { | for (int corner = 0; corner < num_face_grids; corner++) { | ||||
| CCGElem *grid = grids[face->start_grid_index + corner]; | CCGElem *grid = grids[face->start_grid_index + corner]; | ||||
| CCGElem *grid_center_element = CCG_grid_elem(key, grid, 0, 0); | CCGElem *grid_center_element = CCG_grid_elem(key, grid, 0, 0); | ||||
| element_accumulator_add(¢er_accumulator, subdiv_ccg, key, grid_center_element); | element_accumulator_add(¢er_accumulator, subdiv_ccg, key, grid_center_element); | ||||
| } | } | ||||
| element_accumulator_mul_fl(¢er_accumulator, 1.0f / (float)num_face_grids); | element_accumulator_mul_fl(¢er_accumulator, 1.0f / num_face_grids); | ||||
| for (int corner = 0; corner < num_face_grids; corner++) { | for (int corner = 0; corner < num_face_grids; corner++) { | ||||
| CCGElem *grid = grids[face->start_grid_index + corner]; | CCGElem *grid = grids[face->start_grid_index + corner]; | ||||
| CCGElem *grid_center_element = CCG_grid_elem(key, grid, 0, 0); | CCGElem *grid_center_element = CCG_grid_elem(key, grid, 0, 0); | ||||
| element_accumulator_copy(subdiv_ccg, key, grid_center_element, ¢er_accumulator); | element_accumulator_copy(subdiv_ccg, key, grid_center_element, ¢er_accumulator); | ||||
| } | } | ||||
| } | } | ||||
| static void subdiv_ccg_average_inner_grids_task(void *__restrict userdata_v, | static void subdiv_ccg_average_inner_grids_task(void *__restrict userdata_v, | ||||
| Show All 40 Lines | static void subdiv_ccg_average_grids_boundary(SubdivCCG *subdiv_ccg, | ||||
| for (int face_index = 0; face_index < num_adjacent_faces; face_index++) { | for (int face_index = 0; face_index < num_adjacent_faces; face_index++) { | ||||
| for (int i = 1; i < grid_size2 - 1; i++) { | for (int i = 1; i < grid_size2 - 1; i++) { | ||||
| CCGElem *grid_element = subdiv_ccg_coord_to_elem( | CCGElem *grid_element = subdiv_ccg_coord_to_elem( | ||||
| key, subdiv_ccg, &adjacent_edge->boundary_coords[face_index][i]); | key, subdiv_ccg, &adjacent_edge->boundary_coords[face_index][i]); | ||||
| element_accumulator_add(&tls->accumulators[i], subdiv_ccg, key, grid_element); | element_accumulator_add(&tls->accumulators[i], subdiv_ccg, key, grid_element); | ||||
| } | } | ||||
| } | } | ||||
| for (int i = 1; i < grid_size2 - 1; i++) { | for (int i = 1; i < grid_size2 - 1; i++) { | ||||
| element_accumulator_mul_fl(&tls->accumulators[i], 1.0f / (float)num_adjacent_faces); | element_accumulator_mul_fl(&tls->accumulators[i], 1.0f / num_adjacent_faces); | ||||
| } | } | ||||
| /* Copy averaged value to all the other faces. */ | /* Copy averaged value to all the other faces. */ | ||||
| for (int face_index = 0; face_index < num_adjacent_faces; face_index++) { | for (int face_index = 0; face_index < num_adjacent_faces; face_index++) { | ||||
| for (int i = 1; i < grid_size2 - 1; i++) { | for (int i = 1; i < grid_size2 - 1; i++) { | ||||
| CCGElem *grid_element = subdiv_ccg_coord_to_elem( | CCGElem *grid_element = subdiv_ccg_coord_to_elem( | ||||
| key, subdiv_ccg, &adjacent_edge->boundary_coords[face_index][i]); | key, subdiv_ccg, &adjacent_edge->boundary_coords[face_index][i]); | ||||
| element_accumulator_copy(subdiv_ccg, key, grid_element, &tls->accumulators[i]); | element_accumulator_copy(subdiv_ccg, key, grid_element, &tls->accumulators[i]); | ||||
| } | } | ||||
| Show All 35 Lines | static void subdiv_ccg_average_grids_corners(SubdivCCG *subdiv_ccg, | ||||
| } | } | ||||
| GridElementAccumulator accumulator; | GridElementAccumulator accumulator; | ||||
| element_accumulator_init(&accumulator); | element_accumulator_init(&accumulator); | ||||
| for (int face_index = 0; face_index < num_adjacent_faces; face_index++) { | for (int face_index = 0; face_index < num_adjacent_faces; face_index++) { | ||||
| CCGElem *grid_element = subdiv_ccg_coord_to_elem( | CCGElem *grid_element = subdiv_ccg_coord_to_elem( | ||||
| key, subdiv_ccg, &adjacent_vertex->corner_coords[face_index]); | key, subdiv_ccg, &adjacent_vertex->corner_coords[face_index]); | ||||
| element_accumulator_add(&accumulator, subdiv_ccg, key, grid_element); | element_accumulator_add(&accumulator, subdiv_ccg, key, grid_element); | ||||
| } | } | ||||
| element_accumulator_mul_fl(&accumulator, 1.0f / (float)num_adjacent_faces); | element_accumulator_mul_fl(&accumulator, 1.0f / num_adjacent_faces); | ||||
| /* Copy averaged value to all the other faces. */ | /* Copy averaged value to all the other faces. */ | ||||
| for (int face_index = 0; face_index < num_adjacent_faces; face_index++) { | for (int face_index = 0; face_index < num_adjacent_faces; face_index++) { | ||||
| CCGElem *grid_element = subdiv_ccg_coord_to_elem( | CCGElem *grid_element = subdiv_ccg_coord_to_elem( | ||||
| key, subdiv_ccg, &adjacent_vertex->corner_coords[face_index]); | key, subdiv_ccg, &adjacent_vertex->corner_coords[face_index]); | ||||
| element_accumulator_copy(subdiv_ccg, key, grid_element, &accumulator); | element_accumulator_copy(subdiv_ccg, key, grid_element, &accumulator); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 807 Lines • Show Last 20 Lines | |||||