Changeset View
Changeset View
Standalone View
Standalone View
source/blender/render/intern/source/occlusion.c
| Show First 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | typedef struct OcclusionTree { | ||||
| float error; | float error; | ||||
| float distfac; | float distfac; | ||||
| int dothreadedbuild; | int dothreadedbuild; | ||||
| int totbuildthread; | int totbuildthread; | ||||
| int doindirect; | int doindirect; | ||||
| OcclusionCache *cache; | OcclusionCache *cache; | ||||
| int num_threads; | |||||
| } OcclusionTree; | } OcclusionTree; | ||||
| typedef struct OcclusionThread { | typedef struct OcclusionThread { | ||||
| Render *re; | Render *re; | ||||
| StrandSurface *mesh; | StrandSurface *mesh; | ||||
| float (*faceao)[3]; | float (*faceao)[3]; | ||||
| float (*faceenv)[3]; | float (*faceenv)[3]; | ||||
| float (*faceindirect)[3]; | float (*faceindirect)[3]; | ||||
| ▲ Show 20 Lines • Show All 510 Lines • ▼ Show 20 Lines | for (b = 0; b < TOTCHILD; b++) { | ||||
| else if (node->child[b].node) { | else if (node->child[b].node) { | ||||
| occ_build_sh_normalize(node->child[b].node); | occ_build_sh_normalize(node->child[b].node); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static OcclusionTree *occ_tree_build(Render *re) | static OcclusionTree *occ_tree_build(Render *re) | ||||
| { | { | ||||
| const int num_threads = re->r.threads; | |||||
| OcclusionTree *tree; | OcclusionTree *tree; | ||||
| ObjectInstanceRen *obi; | ObjectInstanceRen *obi; | ||||
| ObjectRen *obr; | ObjectRen *obr; | ||||
| Material *ma; | Material *ma; | ||||
| VlakRen *vlr = NULL; | VlakRen *vlr = NULL; | ||||
| int a, b, c, totface; | int a, b, c, totface; | ||||
| /* count */ | /* count */ | ||||
| Show All 22 Lines | static OcclusionTree *occ_tree_build(Render *re) | ||||
| tree->distfac = (re->wrld.aomode & WO_AODIST) ? re->wrld.aodistfac : 0.0f; | tree->distfac = (re->wrld.aomode & WO_AODIST) ? re->wrld.aodistfac : 0.0f; | ||||
| tree->doindirect = (re->wrld.ao_indirect_energy > 0.0f && re->wrld.ao_indirect_bounces > 0); | tree->doindirect = (re->wrld.ao_indirect_energy > 0.0f && re->wrld.ao_indirect_bounces > 0); | ||||
| /* allocation */ | /* allocation */ | ||||
| tree->arena = BLI_memarena_new(0x8000 * sizeof(OccNode), "occ tree arena"); | tree->arena = BLI_memarena_new(0x8000 * sizeof(OccNode), "occ tree arena"); | ||||
| BLI_memarena_use_calloc(tree->arena); | BLI_memarena_use_calloc(tree->arena); | ||||
| if (re->wrld.aomode & WO_AOCACHE) | if (re->wrld.aomode & WO_AOCACHE) | ||||
| tree->cache = MEM_callocN(sizeof(OcclusionCache) * BLENDER_MAX_THREADS, "OcclusionCache"); | tree->cache = MEM_callocN(sizeof(OcclusionCache) * num_threads, "OcclusionCache"); | ||||
| tree->face = MEM_callocN(sizeof(OccFace) * totface, "OcclusionFace"); | tree->face = MEM_callocN(sizeof(OccFace) * totface, "OcclusionFace"); | ||||
| tree->co = MEM_callocN(sizeof(float) * 3 * totface, "OcclusionCo"); | tree->co = MEM_callocN(sizeof(float) * 3 * totface, "OcclusionCo"); | ||||
| tree->occlusion = MEM_callocN(sizeof(float) * totface, "OcclusionOcclusion"); | tree->occlusion = MEM_callocN(sizeof(float) * totface, "OcclusionOcclusion"); | ||||
| if (tree->doindirect) | if (tree->doindirect) | ||||
| tree->rad = MEM_callocN(sizeof(float) * 3 * totface, "OcclusionRad"); | tree->rad = MEM_callocN(sizeof(float) * 3 * totface, "OcclusionRad"); | ||||
| Show All 34 Lines | static OcclusionTree *occ_tree_build(Render *re) | ||||
| } | } | ||||
| MEM_freeN(tree->co); | MEM_freeN(tree->co); | ||||
| tree->co = NULL; | tree->co = NULL; | ||||
| if (!(re->test_break(re->tbh))) | if (!(re->test_break(re->tbh))) | ||||
| occ_build_sh_normalize(tree->root); | occ_build_sh_normalize(tree->root); | ||||
| for (a = 0; a < BLENDER_MAX_THREADS; a++) | for (a = 0; a < num_threads; a++) | ||||
| tree->stack[a] = MEM_callocN(sizeof(OccNode) * TOTCHILD * (tree->maxdepth + 1), "OccStack"); | tree->stack[a] = MEM_callocN(sizeof(OccNode) * TOTCHILD * (tree->maxdepth + 1), "OccStack"); | ||||
| tree->num_threads = num_threads; | |||||
| return tree; | return tree; | ||||
| } | } | ||||
| static void occ_free_tree(OcclusionTree *tree) | static void occ_free_tree(OcclusionTree *tree) | ||||
| { | { | ||||
| int a; | int a; | ||||
| if (tree) { | if (tree) { | ||||
| if (tree->arena) BLI_memarena_free(tree->arena); | if (tree->arena) BLI_memarena_free(tree->arena); | ||||
| for (a = 0; a < BLENDER_MAX_THREADS; a++) | for (a = 0; a < tree->num_threads; a++) | ||||
| if (tree->stack[a]) | if (tree->stack[a]) | ||||
| MEM_freeN(tree->stack[a]); | MEM_freeN(tree->stack[a]); | ||||
| if (tree->occlusion) MEM_freeN(tree->occlusion); | if (tree->occlusion) MEM_freeN(tree->occlusion); | ||||
| if (tree->cache) MEM_freeN(tree->cache); | if (tree->cache) MEM_freeN(tree->cache); | ||||
| if (tree->face) MEM_freeN(tree->face); | if (tree->face) MEM_freeN(tree->face); | ||||
| if (tree->rad) MEM_freeN(tree->rad); | if (tree->rad) MEM_freeN(tree->rad); | ||||
| MEM_freeN(tree); | MEM_freeN(tree); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 770 Lines • Show Last 20 Lines | |||||