Nodes: move some texture nodes to c++

This is necessary to be able to use them in geometry nodes.
This commit is contained in:
Jacques Lucke 2021-09-13 11:54:05 +02:00
parent 9d6e960e2c
commit f6ebbfe7de
6 changed files with 118 additions and 123 deletions

View File

@ -292,16 +292,16 @@ set(SRC
shader/nodes/node_shader_tex_checker.c
shader/nodes/node_shader_tex_coord.c
shader/nodes/node_shader_tex_environment.c
shader/nodes/node_shader_tex_gradient.c
shader/nodes/node_shader_tex_gradient.cc
shader/nodes/node_shader_tex_image.c
shader/nodes/node_shader_tex_magic.c
shader/nodes/node_shader_tex_musgrave.c
shader/nodes/node_shader_tex_noise.c
shader/nodes/node_shader_tex_musgrave.cc
shader/nodes/node_shader_tex_noise.cc
shader/nodes/node_shader_tex_pointdensity.c
shader/nodes/node_shader_tex_sky.c
shader/nodes/node_shader_tex_voronoi.c
shader/nodes/node_shader_tex_voronoi.cc
shader/nodes/node_shader_tex_wave.c
shader/nodes/node_shader_tex_white_noise.c
shader/nodes/node_shader_tex_white_noise.cc
shader/nodes/node_shader_uvAlongStroke.c
shader/nodes/node_shader_uvmap.c
shader/nodes/node_shader_valToRgb.cc

View File

@ -43,7 +43,8 @@ static bNodeSocketTemplate sh_node_tex_gradient_out[] = {
static void node_shader_init_tex_gradient(bNodeTree *UNUSED(ntree), bNode *node)
{
NodeTexGradient *tex = MEM_callocN(sizeof(NodeTexGradient), "NodeTexGradient");
NodeTexGradient *tex = (NodeTexGradient *)MEM_callocN(sizeof(NodeTexGradient),
"NodeTexGradient");
BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT);
BKE_texture_colormapping_default(&tex->base.color_mapping);
tex->gradient_type = SHD_BLEND_LINEAR;

View File

@ -49,7 +49,8 @@ static bNodeSocketTemplate sh_node_tex_musgrave_out[] = {
static void node_shader_init_tex_musgrave(bNodeTree *UNUSED(ntree), bNode *node)
{
NodeTexMusgrave *tex = MEM_callocN(sizeof(NodeTexMusgrave), "NodeTexMusgrave");
NodeTexMusgrave *tex = (NodeTexMusgrave *)MEM_callocN(sizeof(NodeTexMusgrave),
"NodeTexMusgrave");
BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT);
BKE_texture_colormapping_default(&tex->base.color_mapping);
tex->musgrave_type = SHD_MUSGRAVE_FBM;
@ -58,6 +59,41 @@ static void node_shader_init_tex_musgrave(bNodeTree *UNUSED(ntree), bNode *node)
node->storage = tex;
}
static const char *gpu_shader_name_get(const int type, const int dimensions)
{
BLI_assert(type >= 0 && type < 5);
BLI_assert(dimensions > 0 && dimensions < 5);
switch (type) {
case SHD_MUSGRAVE_MULTIFRACTAL:
return std::array{"node_tex_musgrave_multi_fractal_1d",
"node_tex_musgrave_multi_fractal_2d",
"node_tex_musgrave_multi_fractal_3d",
"node_tex_musgrave_multi_fractal_4d"}[dimensions - 1];
case SHD_MUSGRAVE_FBM:
return std::array{"node_tex_musgrave_fBm_1d",
"node_tex_musgrave_fBm_2d",
"node_tex_musgrave_fBm_3d",
"node_tex_musgrave_fBm_4d"}[dimensions - 1];
case SHD_MUSGRAVE_HYBRID_MULTIFRACTAL:
return std::array{"node_tex_musgrave_hybrid_multi_fractal_1d",
"node_tex_musgrave_hybrid_multi_fractal_2d",
"node_tex_musgrave_hybrid_multi_fractal_3d",
"node_tex_musgrave_hybrid_multi_fractal_4d"}[dimensions - 1];
case SHD_MUSGRAVE_RIDGED_MULTIFRACTAL:
return std::array{"node_tex_musgrave_ridged_multi_fractal_1d",
"node_tex_musgrave_ridged_multi_fractal_2d",
"node_tex_musgrave_ridged_multi_fractal_3d",
"node_tex_musgrave_ridged_multi_fractal_4d"}[dimensions - 1];
case SHD_MUSGRAVE_HETERO_TERRAIN:
return std::array{"node_tex_musgrave_hetero_terrain_1d",
"node_tex_musgrave_hetero_terrain_2d",
"node_tex_musgrave_hetero_terrain_3d",
"node_tex_musgrave_hetero_terrain_4d"}[dimensions - 1];
}
return nullptr;
}
static int node_shader_gpu_tex_musgrave(GPUMaterial *mat,
bNode *node,
bNodeExecData *UNUSED(execdata),
@ -71,53 +107,9 @@ static int node_shader_gpu_tex_musgrave(GPUMaterial *mat,
int dimensions = tex->dimensions;
int type = tex->musgrave_type;
static const char *names[][5] = {
[SHD_MUSGRAVE_MULTIFRACTAL] =
{
"",
"node_tex_musgrave_multi_fractal_1d",
"node_tex_musgrave_multi_fractal_2d",
"node_tex_musgrave_multi_fractal_3d",
"node_tex_musgrave_multi_fractal_4d",
},
[SHD_MUSGRAVE_FBM] =
{
"",
"node_tex_musgrave_fBm_1d",
"node_tex_musgrave_fBm_2d",
"node_tex_musgrave_fBm_3d",
"node_tex_musgrave_fBm_4d",
},
[SHD_MUSGRAVE_HYBRID_MULTIFRACTAL] =
{
"",
"node_tex_musgrave_hybrid_multi_fractal_1d",
"node_tex_musgrave_hybrid_multi_fractal_2d",
"node_tex_musgrave_hybrid_multi_fractal_3d",
"node_tex_musgrave_hybrid_multi_fractal_4d",
},
[SHD_MUSGRAVE_RIDGED_MULTIFRACTAL] =
{
"",
"node_tex_musgrave_ridged_multi_fractal_1d",
"node_tex_musgrave_ridged_multi_fractal_2d",
"node_tex_musgrave_ridged_multi_fractal_3d",
"node_tex_musgrave_ridged_multi_fractal_4d",
},
[SHD_MUSGRAVE_HETERO_TERRAIN] =
{
"",
"node_tex_musgrave_hetero_terrain_1d",
"node_tex_musgrave_hetero_terrain_2d",
"node_tex_musgrave_hetero_terrain_3d",
"node_tex_musgrave_hetero_terrain_4d",
},
};
const char *name = gpu_shader_name_get(type, dimensions);
BLI_assert(type >= 0 && type < 5);
BLI_assert(dimensions > 0 && dimensions < 5);
return GPU_stack_link(mat, node, names[type][dimensions], in, out);
return GPU_stack_link(mat, node, name, in, out);
}
static void node_shader_update_tex_musgrave(bNodeTree *UNUSED(ntree), bNode *node)

View File

@ -48,7 +48,7 @@ static bNodeSocketTemplate sh_node_tex_noise_out[] = {
static void node_shader_init_tex_noise(bNodeTree *UNUSED(ntree), bNode *node)
{
NodeTexNoise *tex = MEM_callocN(sizeof(NodeTexNoise), "NodeTexNoise");
NodeTexNoise *tex = (NodeTexNoise *)MEM_callocN(sizeof(NodeTexNoise), "NodeTexNoise");
BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT);
BKE_texture_colormapping_default(&tex->base.color_mapping);
tex->dimensions = 3;
@ -56,6 +56,16 @@ static void node_shader_init_tex_noise(bNodeTree *UNUSED(ntree), bNode *node)
node->storage = tex;
}
static const char *gpu_shader_get_name(const int dimensions)
{
BLI_assert(dimensions >= 1 && dimensions <= 4);
return std::array{"node_noise_texture_1d",
"node_noise_texture_2d",
"node_noise_texture_3d",
"node_noise_texture_4d"}[dimensions - 1];
return nullptr;
}
static int node_shader_gpu_tex_noise(GPUMaterial *mat,
bNode *node,
bNodeExecData *UNUSED(execdata),
@ -66,14 +76,8 @@ static int node_shader_gpu_tex_noise(GPUMaterial *mat,
node_shader_gpu_tex_mapping(mat, node, in, out);
NodeTexNoise *tex = (NodeTexNoise *)node->storage;
static const char *names[] = {
"",
"node_noise_texture_1d",
"node_noise_texture_2d",
"node_noise_texture_3d",
"node_noise_texture_4d",
};
return GPU_stack_link(mat, node, names[tex->dimensions], in, out);
const char *name = gpu_shader_get_name(tex->dimensions);
return GPU_stack_link(mat, node, name, in, out);
}
static void node_shader_update_tex_noise(bNodeTree *UNUSED(ntree), bNode *node)

View File

@ -69,7 +69,7 @@ static bNodeSocketTemplate sh_node_tex_voronoi_out[] = {
static void node_shader_init_tex_voronoi(bNodeTree *UNUSED(ntree), bNode *node)
{
NodeTexVoronoi *tex = MEM_callocN(sizeof(NodeTexVoronoi), "NodeTexVoronoi");
NodeTexVoronoi *tex = (NodeTexVoronoi *)MEM_callocN(sizeof(NodeTexVoronoi), "NodeTexVoronoi");
BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT);
BKE_texture_colormapping_default(&tex->base.color_mapping);
tex->dimensions = 3;
@ -79,6 +79,51 @@ static void node_shader_init_tex_voronoi(bNodeTree *UNUSED(ntree), bNode *node)
node->storage = tex;
}
static const char *gpu_shader_get_name(const int feature, const int dimensions)
{
BLI_assert(feature >= 0 && feature < 5);
BLI_assert(dimensions > 0 && dimensions < 5);
switch (feature) {
case SHD_VORONOI_F1:
return std::array{
"node_tex_voronoi_f1_1d",
"node_tex_voronoi_f1_2d",
"node_tex_voronoi_f1_3d",
"node_tex_voronoi_f1_4d",
}[dimensions - 1];
case SHD_VORONOI_F2:
return std::array{
"node_tex_voronoi_f2_1d",
"node_tex_voronoi_f2_2d",
"node_tex_voronoi_f2_3d",
"node_tex_voronoi_f2_4d",
}[dimensions - 1];
case SHD_VORONOI_SMOOTH_F1:
return std::array{
"node_tex_voronoi_smooth_f1_1d",
"node_tex_voronoi_smooth_f1_2d",
"node_tex_voronoi_smooth_f1_3d",
"node_tex_voronoi_smooth_f1_4d",
}[dimensions - 1];
case SHD_VORONOI_DISTANCE_TO_EDGE:
return std::array{
"node_tex_voronoi_distance_to_edge_1d",
"node_tex_voronoi_distance_to_edge_2d",
"node_tex_voronoi_distance_to_edge_3d",
"node_tex_voronoi_distance_to_edge_4d",
}[dimensions - 1];
case SHD_VORONOI_N_SPHERE_RADIUS:
return std::array{
"node_tex_voronoi_n_sphere_radius_1d",
"node_tex_voronoi_n_sphere_radius_2d",
"node_tex_voronoi_n_sphere_radius_3d",
"node_tex_voronoi_n_sphere_radius_4d",
}[dimensions - 1];
}
return nullptr;
}
static int node_shader_gpu_tex_voronoi(GPUMaterial *mat,
bNode *node,
bNodeExecData *UNUSED(execdata),
@ -88,57 +133,12 @@ static int node_shader_gpu_tex_voronoi(GPUMaterial *mat,
node_shader_gpu_default_tex_coord(mat, node, &in[0].link);
node_shader_gpu_tex_mapping(mat, node, in, out);
static const char *names[][5] = {
[SHD_VORONOI_F1] =
{
"",
"node_tex_voronoi_f1_1d",
"node_tex_voronoi_f1_2d",
"node_tex_voronoi_f1_3d",
"node_tex_voronoi_f1_4d",
},
[SHD_VORONOI_F2] =
{
"",
"node_tex_voronoi_f2_1d",
"node_tex_voronoi_f2_2d",
"node_tex_voronoi_f2_3d",
"node_tex_voronoi_f2_4d",
},
[SHD_VORONOI_SMOOTH_F1] =
{
"",
"node_tex_voronoi_smooth_f1_1d",
"node_tex_voronoi_smooth_f1_2d",
"node_tex_voronoi_smooth_f1_3d",
"node_tex_voronoi_smooth_f1_4d",
},
[SHD_VORONOI_DISTANCE_TO_EDGE] =
{
"",
"node_tex_voronoi_distance_to_edge_1d",
"node_tex_voronoi_distance_to_edge_2d",
"node_tex_voronoi_distance_to_edge_3d",
"node_tex_voronoi_distance_to_edge_4d",
},
[SHD_VORONOI_N_SPHERE_RADIUS] =
{
"",
"node_tex_voronoi_n_sphere_radius_1d",
"node_tex_voronoi_n_sphere_radius_2d",
"node_tex_voronoi_n_sphere_radius_3d",
"node_tex_voronoi_n_sphere_radius_4d",
},
};
NodeTexVoronoi *tex = (NodeTexVoronoi *)node->storage;
float metric = tex->distance;
BLI_assert(tex->feature >= 0 && tex->feature < 5);
BLI_assert(tex->dimensions > 0 && tex->dimensions < 5);
const char *name = gpu_shader_get_name(tex->feature, tex->dimensions);
return GPU_stack_link(
mat, node, names[tex->feature][tex->dimensions], in, out, GPU_constant(&metric));
return GPU_stack_link(mat, node, name, in, out, GPU_constant(&metric));
}
static void node_shader_update_tex_voronoi(bNodeTree *UNUSED(ntree), bNode *node)

View File

@ -37,25 +37,23 @@ static void node_shader_init_tex_white_noise(bNodeTree *UNUSED(ntree), bNode *no
node->custom1 = 3;
}
static const char *gpu_shader_get_name(const int dimensions)
{
BLI_assert(dimensions >= 1 && dimensions <= 4);
return std::array{"node_white_noise_1d",
"node_white_noise_2d",
"node_white_noise_3d",
"node_white_noise_4d"}[dimensions - 1];
}
static int gpu_shader_tex_white_noise(GPUMaterial *mat,
bNode *node,
bNodeExecData *UNUSED(execdata),
GPUNodeStack *in,
GPUNodeStack *out)
{
static const char *names[] = {
"",
"node_white_noise_1d",
"node_white_noise_2d",
"node_white_noise_3d",
"node_white_noise_4d",
};
if (node->custom1 < ARRAY_SIZE(names) && names[node->custom1]) {
return GPU_stack_link(mat, node, names[node->custom1], in, out);
}
return 0;
const char *name = gpu_shader_get_name(node->custom1);
return GPU_stack_link(mat, node, name, in, out);
}
static void node_shader_update_tex_white_noise(bNodeTree *UNUSED(ntree), bNode *node)