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); return GPU_stack_link(mat, "node_layer_weight", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_MATRIX)); }
static void node_shader_gpu_volume_attribute(GPUMaterial *mat, const char *name, GPUNodeLink **outcol, GPUNodeLink **outvec, GPUNodeLink **outf) { if (strcmp(name, "density") == 0) { GPU_link(mat, "node_attribute_volume_density", GPU_builtin(GPU_VOLUME_DENSITY), outcol, outvec, outf); } else if (strcmp(name, "color") == 0) { GPU_link( mat, "node_attribute_volume_color", GPU_builtin(GPU_VOLUME_DENSITY), outcol, outvec, outf); } else if (strcmp(name, "flame") == 0) { GPU_link( mat, "node_attribute_volume_flame", GPU_builtin(GPU_VOLUME_FLAME), outcol, outvec, outf); } else if (strcmp(name, "temperature") == 0) { GPU_link(mat, "node_attribute_volume_temperature", GPU_builtin(GPU_VOLUME_FLAME), GPU_builtin(GPU_VOLUME_TEMPERATURE), outcol, outvec, outf); } else { *outcol = *outvec = *outf = NULL; } }
static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { Image *ima = (Image *)node->id; ImageUser *iuser = NULL; NodeTexImage *tex = node->storage; GPUNodeLink *norm; int isdata = tex->color_space == SHD_COLORSPACE_NONE; float blend = tex->projection_blend; if (!ima) return GPU_stack_link(mat, "node_tex_image_empty", in, out); if (!in[0].link) in[0].link = GPU_attribute(CD_MTFACE, ""); node_shader_gpu_tex_mapping(mat, node, in, out); switch (tex->projection) { case SHD_PROJ_FLAT: GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser, isdata)); break; case SHD_PROJ_BOX: GPU_link(mat, "direction_transform_m4v3", GPU_builtin(GPU_VIEW_NORMAL), GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &norm); GPU_link(mat, "direction_transform_m4v3", norm, GPU_builtin(GPU_INVERSE_OBJECT_MATRIX), &norm); GPU_link(mat, "node_tex_image_box", in[0].link, norm, GPU_image(ima, iuser, isdata), GPU_uniform(&blend), &out[0].link, &out[1].link); break; case SHD_PROJ_SPHERE: GPU_link(mat, "point_texco_remap_square", in[0].link, &in[0].link); GPU_link(mat, "point_map_to_sphere", in[0].link, &in[0].link); GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser, isdata)); break; case SHD_PROJ_TUBE: GPU_link(mat, "point_texco_remap_square", in[0].link, &in[0].link); GPU_link(mat, "point_map_to_tube", in[0].link, &in[0].link); GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser, isdata)); break; } ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL); if ((tex->color_space == SHD_COLORSPACE_COLOR) && 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 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 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_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_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_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_environment(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) { Image *ima= (Image*)node->id; ImageUser *iuser= NULL; NodeTexImage *tex = node->storage; int isdata = tex->color_space == SHD_COLORSPACE_NONE; int ret; if (!ima) return GPU_stack_link(mat, "node_tex_environment_empty", in, out); if (!in[0].link) in[0].link = GPU_builtin(GPU_VIEW_POSITION); node_shader_gpu_tex_mapping(mat, node, in, out); ret = GPU_stack_link(mat, "node_tex_environment", in, out, GPU_image(ima, iuser, isdata)); if (ret) { 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 ret; }
static int gpu_shader_bump(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { if (!in[3].link) in[3].link = GPU_builtin(GPU_VIEW_NORMAL); else GPU_link(mat, "direction_transform_m4v3", in[3].link, GPU_builtin(GPU_VIEW_MATRIX), &in[3].link); float invert = node->custom1; GPU_stack_link(mat, "node_bump", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_uniform(&invert)); /* Other nodes are applying view matrix if the input Normal has a link. * We don't want normal to have view matrix applied twice, so we cancel it here. * * TODO(sergey): This is an extra multiplication which cancels each other, * better avoid this but that requires bigger refactor. */ return GPU_link(mat, "direction_transform_m4v3", out[0].link, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &out[0].link); }
static int node_shader_gpu_bsdf_velvet(GPUMaterial *mat, bNode *UNUSED(node), GPUNodeStack *in, GPUNodeStack *out) { if (!in[2].link) in[2].link = GPU_builtin(GPU_VIEW_NORMAL); return GPU_stack_link(mat, "node_bsdf_velvet", in, out); }
static int node_shader_gpu_bsdf_glass(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { if (!in[3].link) in[3].link = GPU_builtin(GPU_VIEW_NORMAL); return GPU_stack_link(mat, "node_bsdf_glass", in, out); }
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); return GPU_stack_link(mat, "node_subsurface_scattering", 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_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 node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, GPUNodeStack *in, GPUNodeStack *out) { Image *ima= (Image*)node->id; ImageUser *iuser= NULL; if (!ima) return GPU_stack_link(mat, "node_tex_environment_empty", in, out); if (!in[0].link) in[0].link = GPU_builtin(GPU_VIEW_POSITION); node_shader_gpu_tex_mapping(mat, node, in, out); return GPU_stack_link(mat, "node_tex_environment", in, out, GPU_image(ima, iuser)); }
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_bsdf_translucent(GPUMaterial *mat, bNode *UNUSED(node), GPUNodeStack *in, GPUNodeStack *out) { return GPU_stack_link(mat, "node_bsdf_translucent", in, out, GPU_builtin(GPU_VIEW_NORMAL)); }
static int gpu_shader_normal_map(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { NodeShaderNormalMap *nm = node->storage; GPUNodeLink *negnorm; GPUNodeLink *realnorm; GPUNodeLink *strength; float d[4] = {0, 0, 0, 0}; if (in[0].link) strength = in[0].link; else strength = GPU_uniform(in[0].vec); if (in[1].link) realnorm = in[1].link; else realnorm = GPU_uniform(in[1].vec); negnorm = GPU_builtin(GPU_VIEW_NORMAL); GPU_link(mat, "math_max", strength, GPU_uniform(d), &strength); if (GPU_material_use_world_space_shading(mat)) { /* ******* CYCLES or BLENDER INTERNAL with world space shading flag ******* */ const char *color_to_normal_fnc_name = "color_to_normal_new_shading"; if (nm->space == SHD_SPACE_BLENDER_OBJECT || nm->space == SHD_SPACE_BLENDER_WORLD || !GPU_material_use_new_shading_nodes(mat)) color_to_normal_fnc_name = "color_to_blender_normal_new_shading"; switch (nm->space) { case SHD_SPACE_TANGENT: GPU_link(mat, "color_to_normal_new_shading", realnorm, &realnorm); GPU_link(mat, "node_normal_map", GPU_attribute(CD_TANGENT, nm->uv_map), negnorm, realnorm, &realnorm); GPU_link(mat, "vec_math_mix", strength, realnorm, GPU_builtin(GPU_VIEW_NORMAL), &out[0].link); /* for uniform scale this is sufficient to match Cycles */ GPU_link(mat, "direction_transform_m4v3", out[0].link, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &out[0].link); GPU_link(mat, "vect_normalize", out[0].link, &out[0].link); return true; case SHD_SPACE_OBJECT: case SHD_SPACE_BLENDER_OBJECT: GPU_link(mat, "direction_transform_m4v3", negnorm, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &negnorm); GPU_link(mat, color_to_normal_fnc_name, realnorm, &realnorm); GPU_link(mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_OBJECT_MATRIX), &realnorm); break; case SHD_SPACE_WORLD: case SHD_SPACE_BLENDER_WORLD: GPU_link(mat, "direction_transform_m4v3", negnorm, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &negnorm); GPU_link(mat, color_to_normal_fnc_name, realnorm, &realnorm); break; } } else { /* ************** BLENDER INTERNAL without world space shading flag ******* */ GPU_link(mat, "color_to_normal", realnorm, &realnorm); GPU_link(mat, "mtex_negate_texnormal", realnorm, &realnorm); GPU_link(mat, "vec_math_negate", negnorm, &negnorm); switch (nm->space) { case SHD_SPACE_TANGENT: GPU_link(mat, "node_normal_map", GPU_attribute(CD_TANGENT, nm->uv_map), negnorm, realnorm, &realnorm); break; case SHD_SPACE_OBJECT: case SHD_SPACE_BLENDER_OBJECT: GPU_link(mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_LOC_TO_VIEW_MATRIX), &realnorm); break; case SHD_SPACE_WORLD: case SHD_SPACE_BLENDER_WORLD: GPU_link(mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_VIEW_MATRIX), &realnorm); break; } } GPU_link(mat, "vec_math_mix", strength, realnorm, negnorm, &out[0].link); GPU_link(mat, "vect_normalize", out[0].link, &out[0].link); return true; }
static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { Image *ima = (Image *)node->id; NodeTexEnvironment *tex = node->storage; /* We get the image user from the original node, since GPU image keeps * a pointer to it and the dependency refreshes the original. */ bNode *node_original = node->original ? node->original : node; NodeTexImage *tex_original = node_original->storage; ImageUser *iuser = &tex_original->iuser; GPUNodeLink *outalpha; if (!ima) { return GPU_stack_link(mat, node, "node_tex_environment_empty", in, out); } if (!in[0].link) { GPU_link(mat, "node_tex_environment_texco", GPU_builtin(GPU_VIEW_POSITION), &in[0].link); } node_shader_gpu_tex_mapping(mat, node, in, out); /* Compute texture coordinate. */ if (tex->projection == SHD_PROJ_EQUIRECTANGULAR) { /* To fix pole issue we clamp the v coordinate. The clamp value depends on the filter size. */ float clamp_size = (ELEM(tex->interpolation, SHD_INTERP_CUBIC, SHD_INTERP_SMART)) ? 1.5 : 0.5; GPU_link(mat, "node_tex_environment_equirectangular", in[0].link, GPU_constant(&clamp_size), GPU_image(ima, iuser), &in[0].link); } else { GPU_link(mat, "node_tex_environment_mirror_ball", in[0].link, &in[0].link); } /* Sample texture with correct interpolation. */ switch (tex->interpolation) { case SHD_INTERP_LINEAR: /* Force the highest mipmap and don't do anisotropic filtering. * This is to fix the artifact caused by derivatives discontinuity. */ GPU_link(mat, "node_tex_image_linear_no_mip", in[0].link, GPU_image(ima, iuser), &out[0].link, &outalpha); break; case SHD_INTERP_CLOSEST: GPU_link(mat, "node_tex_image_nearest", in[0].link, GPU_image(ima, iuser), &out[0].link, &outalpha); break; default: GPU_link( mat, "node_tex_image_cubic", in[0].link, GPU_image(ima, iuser), &out[0].link, &outalpha); break; } if (out[0].hasoutput) { GPU_link(mat, "tex_color_alpha_clear", out[0].link, &out[0].link); } return true; }
static int node_shader_gpu_emission(GPUMaterial *mat, bNode *UNUSED(node), GPUNodeStack *in, GPUNodeStack *out) { return GPU_stack_link(mat, "node_emission", in, out, GPU_builtin(GPU_VIEW_NORMAL)); }
static int node_shader_gpu_fresnel(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { /* todo: is incoming vector normalized? */ return GPU_stack_link(mat, "node_fresnel", in, out, GPU_builtin(GPU_VIEW_NORMAL), GPU_builtin(GPU_VIEW_POSITION)); }
static int gpu_shader_bump(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { return GPU_stack_link(mat, "node_bump", in, out, GPU_builtin(GPU_VIEW_NORMAL)); }
static int node_shader_gpu_ambient_occlusion(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { return GPU_stack_link(mat, "node_ambient_occlusion", in, out, GPU_builtin(GPU_VIEW_NORMAL)); }
static int node_shader_gpu_oct_portal_mat(struct GPUMaterial *mat, struct bNode *UNUSED(node), struct bNodeExecData *UNUSED(execdata), struct GPUNodeStack *UNUSED(in), struct GPUNodeStack *out) { float rgb[4] = {0.1f, 0.1f, 0.1f, 0.5f}; float roughness[4] = {0}; return GPU_stack_link(mat, "node_bsdf_diffuse", 0, out, GPU_uniform(rgb), GPU_uniform(roughness), GPU_builtin(GPU_VIEW_NORMAL)); }