static int gpu_shader_seprgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { return GPU_stack_link(mat, node, "separate_rgb", in, out); }
static int gpu_shader_curve_vec(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) { float *array; int size; curvemapping_table_RGBA(node->storage, &array, &size); return GPU_stack_link(mat, "curves_vec", in, out, GPU_texture(size, array)); }
static int gpu_shader_rgb(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) { bNodeSocket *sock= node->outputs.first; float *col= ((bNodeSocketValueRGBA*)sock->default_value)->value; GPUNodeLink *vec = GPU_uniform(col); return GPU_stack_link(mat, "set_rgba", in, out, vec); }
static int gpu_shader_valtorgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { float *array; int size; colorband_table_RGBA(node->storage, &array, &size); return GPU_stack_link(mat, "valtorgb", in, out, GPU_texture(size, array)); }
static int node_shader_gpu_subsurface_scattering(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { if (!in[5].link) in[5].link = GPU_builtin(GPU_VIEW_NORMAL); else GPU_link(mat, "direction_transform_m4v3", in[5].link, GPU_builtin(GPU_VIEW_MATRIX), &in[5].link); return GPU_stack_link(mat, "node_subsurface_scattering", in, out); }
static int node_shader_gpu_tex_voronoi(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { if (!in[0].link) in[0].link = GPU_attribute(CD_ORCO, ""); node_shader_gpu_tex_mapping(mat, node, in, out); return GPU_stack_link(mat, "node_tex_voronoi", in, out); }
static int node_shader_gpu_output_material(GPUMaterial *mat, bNode *UNUSED(node), GPUNodeStack *in, GPUNodeStack *out) { GPUNodeLink *outlink; GPU_stack_link(mat, "node_output_material", in, out, &outlink); GPU_material_output_link(mat, outlink); return 1; }
static int node_shader_gpu_tex_coord(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { GPUNodeLink *orco = GPU_attribute(CD_ORCO, ""); GPUNodeLink *mtface = GPU_attribute(CD_MTFACE, ""); return GPU_stack_link(mat, "node_tex_coord", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_NORMAL), GPU_builtin(GPU_INVERSE_VIEW_MATRIX), GPU_builtin(GPU_INVERSE_OBJECT_MATRIX), orco, mtface); }
static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) { Image *ima= (Image*)node->id; ImageUser *iuser= NULL; if (!ima) { float black[4] = {0.0f, 0.0f, 0.0f, 1.0f}; GPUNodeLink *vec = GPU_uniform(black); return GPU_stack_link(mat, "set_rgba", out, out, vec); } if (!in[0].link) in[0].link = GPU_attribute(CD_MTFACE, ""); node_shader_gpu_tex_mapping(mat, node, in, out); return GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser)); }
static int node_shader_gpu_output_world(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { GPUNodeLink *outlink; GPU_stack_link(mat, "node_output_world", in, out, &outlink); GPU_material_output_link(mat, outlink); return true; }
static int node_shader_gpu_tex_noise(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) { if (!in[0].link) in[0].link = GPU_attribute(CD_ORCO, ""); node_shader_gpu_tex_mapping(mat, node, in, out); return GPU_stack_link(mat, "node_tex_noise", in, out); }
static int gpu_shader_curve_rgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { float *array; int size; curvemapping_initialize(node->storage); curvemapping_table_RGBA(node->storage, &array, &size); return GPU_stack_link(mat, "curves_rgb", in, out, GPU_texture(size, array)); }
static int gpu_shader_particle_info(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { return GPU_stack_link(mat, "particle_info", in, out, GPU_builtin(GPU_PARTICLE_SCALAR_PROPS), GPU_builtin(GPU_PARTICLE_LOCATION), GPU_builtin(GPU_PARTICLE_VELOCITY), GPU_builtin(GPU_PARTICLE_ANG_VELOCITY)); }
static int gpu_shader_mix_rgb(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) { static const char *names[] = {"mix_blend", "mix_add", "mix_mult", "mix_sub", "mix_screen", "mix_div", "mix_diff", "mix_dark", "mix_light", "mix_overlay", "mix_dodge", "mix_burn", "mix_hue", "mix_sat", "mix_val", "mix_color", "mix_soft", "mix_linear"}; return GPU_stack_link(mat, names[node->custom1], in, out); }
static int node_shader_gpu_tex_coord(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { GPUNodeLink *orco = GPU_attribute(CD_ORCO, ""); GPUNodeLink *mtface = GPU_attribute(CD_MTFACE, ""); GPUMatType type = GPU_Material_get_type(mat); if (type == GPU_MATERIAL_TYPE_MESH) { return GPU_stack_link(mat, "node_tex_coord", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_NORMAL), GPU_builtin(GPU_INVERSE_VIEW_MATRIX), GPU_builtin(GPU_INVERSE_OBJECT_MATRIX), GPU_builtin(GPU_CAMERA_TEXCO_FACTORS), orco, mtface); } else { return GPU_stack_link(mat, "node_tex_coord_background", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_NORMAL), GPU_builtin(GPU_INVERSE_VIEW_MATRIX), GPU_builtin(GPU_INVERSE_OBJECT_MATRIX), GPU_builtin(GPU_CAMERA_TEXCO_FACTORS), orco, mtface); } }
static int node_shader_gpu_layer_weight(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { if (!in[1].link) in[1].link = GPU_builtin(GPU_VIEW_NORMAL); else if (GPU_material_use_world_space_shading(mat)) { GPU_link(mat, "direction_transform_m4v3", in[1].link, GPU_builtin(GPU_VIEW_MATRIX), &in[1].link); } return GPU_stack_link(mat, "node_layer_weight", in, out, GPU_builtin(GPU_VIEW_POSITION)); }
static int gpu_shader_texture(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) { Tex *tex = (Tex*)node->id; if(tex && tex->type == TEX_IMAGE && tex->ima) { GPUNodeLink *texlink = GPU_image(tex->ima, NULL); return GPU_stack_link(mat, "texture_image", in, out, texlink); } else return 0; }
static int gpu_shader_geom(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) { NodeGeometry *ngeo= (NodeGeometry*)node->storage; GPUNodeLink *orco = GPU_attribute(CD_ORCO, ""); GPUNodeLink *mtface = GPU_attribute(CD_MTFACE, ngeo->uvname); GPUNodeLink *mcol = GPU_attribute(CD_MCOL, ngeo->colname); return GPU_stack_link(mat, "geom", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_NORMAL), GPU_builtin(GPU_INVERSE_VIEW_MATRIX), orco, mtface, mcol); }
static int node_shader_gpu_tex_checker(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { if (!in[0].link) { in[0].link = GPU_attribute(CD_ORCO, ""); GPU_link(mat, "generated_from_orco", in[0].link, &in[0].link); } node_shader_gpu_tex_mapping(mat, node, in, out); return GPU_stack_link(mat, "node_tex_checker", in, out); }
static int node_shader_gpu_tex_magic(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) { NodeTexMagic *tex = (NodeTexMagic*)node->storage; float depth = tex->depth; if (!in[0].link) in[0].link = GPU_attribute(CD_ORCO, ""); node_shader_gpu_tex_mapping(mat, node, in, out); return GPU_stack_link(mat, "node_tex_magic", in, out, GPU_uniform(&depth)); }
static int gpu_shader_output(GPUMaterial *mat, bNode *UNUSED(node), GPUNodeStack *in, GPUNodeStack *out) { GPUNodeLink *outlink; /*if(in[1].hasinput) GPU_material_enable_alpha(mat);*/ GPU_stack_link(mat, "output_node", in, out, &outlink); GPU_material_output_link(mat, outlink); return 1; }
static int gpu_shader_mapping(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) { TexMapping *texmap= node->storage; float domin= (texmap->flag & TEXMAP_CLIP_MIN) != 0; float domax= (texmap->flag & TEXMAP_CLIP_MAX) != 0; GPUNodeLink *tmat = GPU_uniform((float*)texmap->mat); GPUNodeLink *tmin = GPU_uniform(texmap->min); GPUNodeLink *tmax = GPU_uniform(texmap->max); GPUNodeLink *tdomin = GPU_uniform(&domin); GPUNodeLink *tdomax = GPU_uniform(&domax); return GPU_stack_link(mat, "mapping", in, out, tmat, tmin, tmax, tdomin, tdomax); }
static int node_shader_gpu_tex_gradient(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { if (!in[0].link) { in[0].link = GPU_attribute(CD_ORCO, ""); GPU_link(mat, "generated_from_orco", in[0].link, &in[0].link); } node_shader_gpu_tex_mapping(mat, node, in, out); NodeTexGradient *tex = (NodeTexGradient *)node->storage; float gradient_type = tex->gradient_type; return GPU_stack_link(mat, "node_tex_gradient", in, out, GPU_uniform(&gradient_type)); }
static int gpu_shader_math(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) { static const char *names[] = {"math_add", "math_subtract", "math_multiply", "math_divide", "math_sine", "math_cosine", "math_tangent", "math_asin", "math_acos", "math_atan", "math_pow", "math_log", "math_min", "math_max", "math_round", "math_less_than", "math_greater_than"}; switch (node->custom1) { case 0: case 1: case 2: case 3: case 10: case 11: case 12: case 13: case 15: case 16: GPU_stack_link(mat, names[node->custom1], NULL, out, GPU_socket(&in[0]), GPU_socket(&in[1])); break; case 4: case 5: case 6: case 7: case 8: case 9: case 14: if(in[0].hasinput || !in[1].hasinput) GPU_stack_link(mat, names[node->custom1], NULL, out, GPU_socket(&in[0])); else GPU_stack_link(mat, names[node->custom1], NULL, out, GPU_socket(&in[1])); break; default: return 0; } return 1; }
static int node_shader_gpu_ambient_occlusion(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { if (!in[2].link) { GPU_link(mat, "world_normals_get", &in[2].link); } GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE); return GPU_stack_link(mat, node, "node_ambient_occlusion", in, out); }
static int node_shader_gpu_bsdf_glass(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { if (!in[3].link) { GPU_link(mat, "world_normals_get", &in[3].link); } GPU_material_flag_set(mat, GPU_MATFLAG_GLOSSY | GPU_MATFLAG_REFRACT); return GPU_stack_link(mat, node, "node_bsdf_glass", in, out, GPU_constant(&node->ssr_id)); }
static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { Image *ima = (Image *)node->id; ImageUser *iuser = NULL; NodeTexImage *tex = node->storage; int isdata = tex->color_space == SHD_COLORSPACE_NONE; if (!ima) return GPU_stack_link(mat, "node_tex_environment_empty", in, out); if (!in[0].link) { GPUMatType type = GPU_Material_get_type(mat); if (type == GPU_MATERIAL_TYPE_MESH) in[0].link = GPU_builtin(GPU_VIEW_POSITION); else GPU_link(mat, "background_transform_to_world", GPU_builtin(GPU_VIEW_POSITION), &in[0].link); } node_shader_gpu_tex_mapping(mat, node, in, out); if (tex->projection == SHD_PROJ_EQUIRECTANGULAR) GPU_stack_link(mat, "node_tex_environment_equirectangular", in, out, GPU_image(ima, iuser, isdata)); else GPU_stack_link(mat, "node_tex_environment_mirror_ball", in, out, GPU_image(ima, iuser, isdata)); ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL); if (ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 && GPU_material_do_color_management(mat)) { GPU_link(mat, "srgb_to_linearrgb", out[0].link, &out[0].link); } BKE_image_release_ibuf(ima, ibuf, NULL); return true; }
static int node_shader_gpu_tex_noise(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { if (!in[0].link) { in[0].link = GPU_attribute(CD_ORCO, ""); GPU_link(mat, "generated_texco", GPU_builtin(GPU_VIEW_POSITION), in[0].link, &in[0].link); } node_shader_gpu_tex_mapping(mat, node, in, out); return GPU_stack_link(mat, node, "node_tex_noise", in, out); }
static int gpu_shader_vect_math(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { static const char *names[] = {"vec_math_add", "vec_math_sub", "vec_math_average", "vec_math_dot", "vec_math_cross", "vec_math_normalize"}; switch (node->custom1) { case 0: case 1: case 2: case 3: case 4: GPU_stack_link(mat, names[node->custom1], in, out); break; case 5: if (in[0].hasinput || !in[1].hasinput) { /* use only first item and terminator */ GPUNodeStack tmp_in[2]; memcpy(&tmp_in[0], &in[0], sizeof(GPUNodeStack)); memcpy(&tmp_in[1], &in[2], sizeof(GPUNodeStack)); GPU_stack_link(mat, names[node->custom1], tmp_in, out); } else { /* use only second item and terminator */ GPUNodeStack tmp_in[2]; memcpy(&tmp_in[0], &in[1], sizeof(GPUNodeStack)); memcpy(&tmp_in[1], &in[2], sizeof(GPUNodeStack)); GPU_stack_link(mat, names[node->custom1], tmp_in, out); } break; default: return 0; } return 1; }
static int node_shader_gpu_blackbody(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { const int size = CM_TABLE + 1; float *data = MEM_mallocN(sizeof(float) * size * 4, "blackbody texture"); blackbody_temperature_to_rgb_table(data, size, 965.0f, 12000.0f); float layer; GPUNodeLink *ramp_texture = GPU_color_band(mat, size, data, &layer); return GPU_stack_link(mat, node, "node_blackbody", in, out, ramp_texture, GPU_constant(&layer)); }