Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/intern/gpu_node_graph.c
| Show First 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | switch (link->link_type) { | ||||
| case GPU_NODE_LINK_COLORBAND: | case GPU_NODE_LINK_COLORBAND: | ||||
| input->source = GPU_SOURCE_TEX; | input->source = GPU_SOURCE_TEX; | ||||
| input->texture = link->texture; | input->texture = link->texture; | ||||
| break; | break; | ||||
| case GPU_NODE_LINK_IMAGE_TILED_MAPPING: | case GPU_NODE_LINK_IMAGE_TILED_MAPPING: | ||||
| input->source = GPU_SOURCE_TEX_TILED_MAPPING; | input->source = GPU_SOURCE_TEX_TILED_MAPPING; | ||||
| input->texture = link->texture; | input->texture = link->texture; | ||||
| break; | break; | ||||
| case GPU_NODE_LINK_VOLUME_GRID: | |||||
| input->source = GPU_SOURCE_VOLUME_GRID; | |||||
| input->volume_grid = link->volume_grid; | |||||
| break; | |||||
| case GPU_NODE_LINK_ATTR: | case GPU_NODE_LINK_ATTR: | ||||
| input->source = GPU_SOURCE_ATTR; | input->source = GPU_SOURCE_ATTR; | ||||
| input->attr = link->attr; | input->attr = link->attr; | ||||
| input->attr->gputype = type; | input->attr->gputype = type; | ||||
| break; | break; | ||||
| case GPU_NODE_LINK_CONSTANT: | case GPU_NODE_LINK_CONSTANT: | ||||
| input->source = (type == GPU_CLOSURE) ? GPU_SOURCE_STRUCT : GPU_SOURCE_CONSTANT; | input->source = (type == GPU_CLOSURE) ? GPU_SOURCE_STRUCT : GPU_SOURCE_CONSTANT; | ||||
| break; | break; | ||||
| ▲ Show 20 Lines • Show All 186 Lines • ▼ Show 20 Lines | if (tex == NULL) { | ||||
| BLI_addtail(&graph->textures, tex); | BLI_addtail(&graph->textures, tex); | ||||
| } | } | ||||
| tex->users++; | tex->users++; | ||||
| return tex; | return tex; | ||||
| } | } | ||||
| static GPUMaterialVolumeGrid *gpu_node_graph_add_volume_grid(GPUNodeGraph *graph, const char *name) | |||||
| { | |||||
| /* Find existing volume grid. */ | |||||
| int num_grids = 0; | |||||
| GPUMaterialVolumeGrid *grid = graph->volume_grids.first; | |||||
| for (; grid; grid = grid->next) { | |||||
| if (STREQ(grid->name, name)) { | |||||
| break; | |||||
| } | |||||
| num_grids++; | |||||
| } | |||||
| /* Add new requested volume grid. */ | |||||
| if (grid == NULL) { | |||||
| grid = MEM_callocN(sizeof(*grid), __func__); | |||||
| grid->name = BLI_strdup(name); | |||||
| BLI_snprintf(grid->sampler_name, sizeof(grid->sampler_name), "vsamp%d", num_grids); | |||||
| BLI_addtail(&graph->volume_grids, grid); | |||||
| } | |||||
| grid->users++; | |||||
| return grid; | |||||
| } | |||||
| /* Creating Inputs */ | /* Creating Inputs */ | ||||
| GPUNodeLink *GPU_attribute(GPUMaterial *mat, const CustomDataType type, const char *name) | GPUNodeLink *GPU_attribute(GPUMaterial *mat, const CustomDataType type, const char *name) | ||||
| { | { | ||||
| GPUNodeGraph *graph = gpu_material_node_graph(mat); | GPUNodeGraph *graph = gpu_material_node_graph(mat); | ||||
| GPUMaterialAttribute *attr = gpu_node_graph_add_attribute(graph, type, name); | GPUMaterialAttribute *attr = gpu_node_graph_add_attribute(graph, type, name); | ||||
| if (attr == NULL) { | if (attr == NULL) { | ||||
| ▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | GPUNodeLink *GPU_color_band(GPUMaterial *mat, int size, float *pixels, float *row) | ||||
| GPUNodeGraph *graph = gpu_material_node_graph(mat); | GPUNodeGraph *graph = gpu_material_node_graph(mat); | ||||
| GPUNodeLink *link = gpu_node_link_create(); | GPUNodeLink *link = gpu_node_link_create(); | ||||
| link->link_type = GPU_NODE_LINK_COLORBAND; | link->link_type = GPU_NODE_LINK_COLORBAND; | ||||
| link->texture = gpu_node_graph_add_texture(graph, NULL, NULL, colorband, link->link_type); | link->texture = gpu_node_graph_add_texture(graph, NULL, NULL, colorband, link->link_type); | ||||
| return link; | return link; | ||||
| } | } | ||||
| GPUNodeLink *GPU_volume_grid(GPUMaterial *mat, const char *name) | |||||
| { | |||||
| /* NOTE: this could be optimized by automatically merging duplicate | |||||
| * lookups of the same attribute. */ | |||||
| GPUNodeGraph *graph = gpu_material_node_graph(mat); | |||||
| GPUNodeLink *link = gpu_node_link_create(); | |||||
| link->link_type = GPU_NODE_LINK_VOLUME_GRID; | |||||
| link->volume_grid = gpu_node_graph_add_volume_grid(graph, name); | |||||
| /* Two special cases, where we adjust the output values of smoke grids to | |||||
| * bring the into standard range without having to modify the grid values. */ | |||||
| if (strcmp(name, "color") == 0) { | |||||
| GPU_link(mat, "node_attribute_volume_color", link, &link); | |||||
| } | |||||
| else if (strcmp(name, "temperature") == 0) { | |||||
| GPU_link(mat, "node_attribute_volume_temperature", link, &link); | |||||
| } | |||||
| else { | |||||
| GPU_link(mat, "node_attribute_volume", link, &link); | |||||
| } | |||||
| return link; | |||||
| } | |||||
| GPUNodeLink *GPU_builtin(eGPUBuiltin builtin) | GPUNodeLink *GPU_builtin(eGPUBuiltin builtin) | ||||
| { | { | ||||
| GPUNodeLink *link = gpu_node_link_create(); | GPUNodeLink *link = gpu_node_link_create(); | ||||
| link->link_type = GPU_NODE_LINK_BUILTIN; | link->link_type = GPU_NODE_LINK_BUILTIN; | ||||
| link->builtin = builtin; | link->builtin = builtin; | ||||
| return link; | return link; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | static void gpu_inputs_free(ListBase *inputs) | ||||
| for (input = inputs->first; input; input = input->next) { | for (input = inputs->first; input; input = input->next) { | ||||
| if (input->source == GPU_SOURCE_ATTR) { | if (input->source == GPU_SOURCE_ATTR) { | ||||
| input->attr->users--; | input->attr->users--; | ||||
| } | } | ||||
| else if (ELEM(input->source, GPU_SOURCE_TEX, GPU_SOURCE_TEX_TILED_MAPPING)) { | else if (ELEM(input->source, GPU_SOURCE_TEX, GPU_SOURCE_TEX_TILED_MAPPING)) { | ||||
| input->texture->users--; | input->texture->users--; | ||||
| } | } | ||||
| else if (ELEM(input->source, GPU_SOURCE_VOLUME_GRID)) { | |||||
| input->volume_grid->users--; | |||||
| } | |||||
| if (input->link) { | if (input->link) { | ||||
| gpu_node_link_free(input->link); | gpu_node_link_free(input->link); | ||||
| } | } | ||||
| } | } | ||||
| BLI_freelistN(inputs); | BLI_freelistN(inputs); | ||||
| } | } | ||||
| Show All 26 Lines | void gpu_node_graph_free_nodes(GPUNodeGraph *graph) | ||||
| graph->outlink = NULL; | graph->outlink = NULL; | ||||
| } | } | ||||
| /* Free both node graph and requested attributes and textures. */ | /* Free both node graph and requested attributes and textures. */ | ||||
| void gpu_node_graph_free(GPUNodeGraph *graph) | void gpu_node_graph_free(GPUNodeGraph *graph) | ||||
| { | { | ||||
| gpu_node_graph_free_nodes(graph); | gpu_node_graph_free_nodes(graph); | ||||
| for (GPUMaterialVolumeGrid *grid = graph->volume_grids.first; grid; grid = grid->next) { | |||||
| MEM_SAFE_FREE(grid->name); | |||||
| } | |||||
| BLI_freelistN(&graph->volume_grids); | |||||
| BLI_freelistN(&graph->textures); | BLI_freelistN(&graph->textures); | ||||
| BLI_freelistN(&graph->attributes); | BLI_freelistN(&graph->attributes); | ||||
| } | } | ||||
| /* Prune Unused Nodes */ | /* Prune Unused Nodes */ | ||||
| static void gpu_nodes_tag(GPUNodeLink *link) | static void gpu_nodes_tag(GPUNodeLink *link) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | void gpu_node_graph_prune_unused(GPUNodeGraph *graph) | ||||
| } | } | ||||
| for (GPUMaterialTexture *tex = graph->textures.first, *next = NULL; tex; tex = next) { | for (GPUMaterialTexture *tex = graph->textures.first, *next = NULL; tex; tex = next) { | ||||
| next = tex->next; | next = tex->next; | ||||
| if (tex->users == 0) { | if (tex->users == 0) { | ||||
| BLI_freelinkN(&graph->textures, tex); | BLI_freelinkN(&graph->textures, tex); | ||||
| } | } | ||||
| } | } | ||||
| for (GPUMaterialVolumeGrid *grid = graph->volume_grids.first, *next = NULL; grid; grid = next) { | |||||
| next = grid->next; | |||||
| if (grid->users == 0) { | |||||
| MEM_SAFE_FREE(grid->name); | |||||
| BLI_freelinkN(&graph->volume_grids, grid); | |||||
| } | |||||
| } | |||||
| } | } | ||||