Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/workbench/workbench_materials.c
| Show First 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | else { | ||||
| copy_v3_fl(data->base_color, 0.8f); | copy_v3_fl(data->base_color, 0.8f); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| char *workbench_material_build_defines(WORKBENCH_PrivateData *wpd, | char *workbench_material_build_defines(WORKBENCH_PrivateData *wpd, | ||||
| bool is_uniform_color, | bool is_uniform_color, | ||||
| bool is_hair, | bool is_hair, | ||||
| bool is_texture_painting) | WORKBENCH_ObjectColorOverride color_override) | ||||
| { | { | ||||
| char *str = NULL; | char *str = NULL; | ||||
| bool use_textures = (wpd->shading.color_type == V3D_SHADING_TEXTURE_COLOR) && !is_uniform_color; | bool use_textures = (wpd->shading.color_type == V3D_SHADING_TEXTURE_COLOR) && !is_uniform_color; | ||||
| bool use_vertex_colors = (wpd->shading.color_type == V3D_SHADING_VERTEX_COLOR) && | bool use_vertex_colors = (wpd->shading.color_type == V3D_SHADING_VERTEX_COLOR) && | ||||
| !is_uniform_color; | !is_uniform_color; | ||||
| if (is_texture_painting) { | switch (color_override) { | ||||
| case WORKBENCH_COLOR_OVERRIDE_TEXTURE: | |||||
| use_textures = true; | use_textures = true; | ||||
| use_vertex_colors = false; | use_vertex_colors = false; | ||||
| is_hair = false; | |||||
| break; | |||||
| case WORKBENCH_COLOR_OVERRIDE_VERTEX: | |||||
| use_textures = false; | |||||
| use_vertex_colors = true; | |||||
| is_hair = false; | |||||
| break; | |||||
| case WORKBENCH_COLOR_OVERRIDE_OFF: | |||||
| break; | |||||
| } | } | ||||
| DynStr *ds = BLI_dynstr_new(); | DynStr *ds = BLI_dynstr_new(); | ||||
| if (wpd->shading.flag & V3D_SHADING_OBJECT_OUTLINE) { | if (wpd->shading.flag & V3D_SHADING_OBJECT_OUTLINE) { | ||||
| BLI_dynstr_append(ds, "#define V3D_SHADING_OBJECT_OUTLINE\n"); | BLI_dynstr_append(ds, "#define V3D_SHADING_OBJECT_OUTLINE\n"); | ||||
| } | } | ||||
| if (wpd->shading.flag & V3D_SHADING_SHADOW) { | if (wpd->shading.flag & V3D_SHADING_SHADOW) { | ||||
| ▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | int workbench_material_get_composite_shader_index(WORKBENCH_PrivateData *wpd) | ||||
| SET_FLAG_FROM_TEST(index, workbench_is_specular_highlight_enabled(wpd), 1 << 6); | SET_FLAG_FROM_TEST(index, workbench_is_specular_highlight_enabled(wpd), 1 << 6); | ||||
| BLI_assert(index < MAX_COMPOSITE_SHADERS); | BLI_assert(index < MAX_COMPOSITE_SHADERS); | ||||
| return index; | return index; | ||||
| } | } | ||||
| int workbench_material_get_prepass_shader_index(WORKBENCH_PrivateData *wpd, | int workbench_material_get_prepass_shader_index(WORKBENCH_PrivateData *wpd, | ||||
| bool is_uniform_color, | bool is_uniform_color, | ||||
| bool is_hair, | bool is_hair, | ||||
| bool is_texture_painting) | WORKBENCH_ObjectColorOverride color_override) | ||||
| { | { | ||||
| bool use_textures = (wpd->shading.color_type == V3D_SHADING_TEXTURE_COLOR) && !is_uniform_color; | bool use_textures = (wpd->shading.color_type == V3D_SHADING_TEXTURE_COLOR) && !is_uniform_color; | ||||
| bool use_vertex_colors = (wpd->shading.color_type == V3D_SHADING_VERTEX_COLOR) && | bool use_vertex_colors = (wpd->shading.color_type == V3D_SHADING_VERTEX_COLOR) && | ||||
| !is_uniform_color; | !is_uniform_color; | ||||
| if (is_texture_painting) { | |||||
| switch (color_override) { | |||||
| case WORKBENCH_COLOR_OVERRIDE_TEXTURE: | |||||
| use_textures = true; | use_textures = true; | ||||
| use_vertex_colors = false; | use_vertex_colors = false; | ||||
| break; | |||||
| case WORKBENCH_COLOR_OVERRIDE_VERTEX: | |||||
| use_textures = false; | |||||
| use_vertex_colors = true; | |||||
| break; | |||||
| case WORKBENCH_COLOR_OVERRIDE_OFF: | |||||
| break; | |||||
| } | } | ||||
| /* NOTE: change MAX_PREPASS_SHADERS accordingly when modifying this function. */ | /* NOTE: change MAX_PREPASS_SHADERS accordingly when modifying this function. */ | ||||
| int index = 0; | int index = 0; | ||||
| SET_FLAG_FROM_TEST(index, is_hair, 1 << 0); | SET_FLAG_FROM_TEST(index, is_hair, 1 << 0); | ||||
| SET_FLAG_FROM_TEST(index, workbench_is_matdata_pass_enabled(wpd), 1 << 1); | SET_FLAG_FROM_TEST(index, workbench_is_matdata_pass_enabled(wpd), 1 << 1); | ||||
| SET_FLAG_FROM_TEST(index, OBJECT_ID_PASS_ENABLED(wpd), 1 << 2); | SET_FLAG_FROM_TEST(index, OBJECT_ID_PASS_ENABLED(wpd), 1 << 2); | ||||
| SET_FLAG_FROM_TEST(index, NORMAL_VIEWPORT_PASS_ENABLED(wpd), 1 << 3); | SET_FLAG_FROM_TEST(index, NORMAL_VIEWPORT_PASS_ENABLED(wpd), 1 << 3); | ||||
| SET_FLAG_FROM_TEST(index, MATCAP_ENABLED(wpd), 1 << 4); | SET_FLAG_FROM_TEST(index, MATCAP_ENABLED(wpd), 1 << 4); | ||||
| SET_FLAG_FROM_TEST(index, use_textures, 1 << 5); | SET_FLAG_FROM_TEST(index, use_textures, 1 << 5); | ||||
| SET_FLAG_FROM_TEST(index, use_vertex_colors, 1 << 6); | SET_FLAG_FROM_TEST(index, use_vertex_colors, 1 << 6); | ||||
| BLI_assert(index < MAX_PREPASS_SHADERS); | BLI_assert(index < MAX_PREPASS_SHADERS); | ||||
| return index; | return index; | ||||
| } | } | ||||
| int workbench_material_get_accum_shader_index(WORKBENCH_PrivateData *wpd, | int workbench_material_get_accum_shader_index(WORKBENCH_PrivateData *wpd, | ||||
| bool is_uniform_color, | bool is_uniform_color, | ||||
| bool is_hair, | bool is_hair, | ||||
| bool is_texture_painting) | WORKBENCH_ObjectColorOverride color_override) | ||||
| { | { | ||||
| bool use_textures = (wpd->shading.color_type == V3D_SHADING_TEXTURE_COLOR) && !is_uniform_color; | bool use_textures = (wpd->shading.color_type == V3D_SHADING_TEXTURE_COLOR) && !is_uniform_color; | ||||
| bool use_vertex_colors = (wpd->shading.color_type == V3D_SHADING_VERTEX_COLOR) && | bool use_vertex_colors = (wpd->shading.color_type == V3D_SHADING_VERTEX_COLOR) && | ||||
| !is_uniform_color; | !is_uniform_color; | ||||
| if (is_texture_painting) { | |||||
| switch (color_override) { | |||||
| case WORKBENCH_COLOR_OVERRIDE_TEXTURE: | |||||
| use_textures = true; | use_textures = true; | ||||
| use_vertex_colors = false; | use_vertex_colors = false; | ||||
| is_hair = false; | is_hair = false; | ||||
| break; | |||||
| case WORKBENCH_COLOR_OVERRIDE_VERTEX: | |||||
| use_textures = false; | |||||
| use_vertex_colors = true; | |||||
| is_hair = false; | |||||
| break; | |||||
| case WORKBENCH_COLOR_OVERRIDE_OFF: | |||||
| break; | |||||
| } | } | ||||
| /* NOTE: change MAX_ACCUM_SHADERS accordingly when modifying this function. */ | /* NOTE: change MAX_ACCUM_SHADERS accordingly when modifying this function. */ | ||||
| int index = 0; | int index = 0; | ||||
| /* 2 bits FLAT/STUDIO/MATCAP + Specular highlight */ | /* 2 bits FLAT/STUDIO/MATCAP + Specular highlight */ | ||||
| index = wpd->shading.light; | index = wpd->shading.light; | ||||
| SET_FLAG_FROM_TEST(index, use_textures, 1 << 2); | SET_FLAG_FROM_TEST(index, use_textures, 1 << 2); | ||||
| SET_FLAG_FROM_TEST(index, use_vertex_colors, 1 << 3); | SET_FLAG_FROM_TEST(index, use_vertex_colors, 1 << 3); | ||||
| Show All 16 Lines | int workbench_material_determine_color_type(WORKBENCH_PrivateData *wpd, | ||||
| if ((color_type == V3D_SHADING_TEXTURE_COLOR) && | if ((color_type == V3D_SHADING_TEXTURE_COLOR) && | ||||
| (ima == NULL || use_sculpt_pbvh || (ob->dt < OB_TEXTURE))) { | (ima == NULL || use_sculpt_pbvh || (ob->dt < OB_TEXTURE))) { | ||||
| color_type = V3D_SHADING_MATERIAL_COLOR; | color_type = V3D_SHADING_MATERIAL_COLOR; | ||||
| } | } | ||||
| if (color_type == V3D_SHADING_VERTEX_COLOR && (me == NULL || me->mloopcol == NULL)) { | if (color_type == V3D_SHADING_VERTEX_COLOR && (me == NULL || me->mloopcol == NULL)) { | ||||
| color_type = V3D_SHADING_OBJECT_COLOR; | color_type = V3D_SHADING_OBJECT_COLOR; | ||||
| } | } | ||||
| switch (workbench_object_color_override_get(ob)) { | |||||
| /* Force V3D_SHADING_TEXTURE_COLOR for active object when in texture painting | /* Force V3D_SHADING_TEXTURE_COLOR for active object when in texture painting | ||||
| * no matter the shading color that the user has chosen, when there is no | * no matter the shading color that the user has chosen, when there is no | ||||
| * texture we will render the object with the error color */ | * texture we will render the object with the error color */ | ||||
| if (workbench_is_object_in_texture_paint_mode(ob)) { | case WORKBENCH_COLOR_OVERRIDE_TEXTURE: | ||||
| color_type = ima ? V3D_SHADING_TEXTURE_COLOR : V3D_SHADING_ERROR_COLOR; | color_type = ima ? V3D_SHADING_TEXTURE_COLOR : V3D_SHADING_ERROR_COLOR; | ||||
| break; | |||||
| /* Force V3D_SHADING_VERTEX_COLOR for active object when in vertex painting | |||||
| * no matter the shading color that the user has chosen, when there is no | |||||
| * vertex color we will render the object with the error color */ | |||||
| case WORKBENCH_COLOR_OVERRIDE_VERTEX: | |||||
| color_type = V3D_SHADING_VERTEX_COLOR; | |||||
| break; | |||||
| case WORKBENCH_COLOR_OVERRIDE_OFF: | |||||
| break; | |||||
| } | } | ||||
| return color_type; | return color_type; | ||||
| } | } | ||||
| void workbench_material_get_image_and_mat( | void workbench_material_get_image_and_mat( | ||||
| Object *ob, int mat_nr, Image **r_image, ImageUser **r_iuser, int *r_interp, Material **r_mat) | Object *ob, int mat_nr, Image **r_image, ImageUser **r_iuser, int *r_interp, Material **r_mat) | ||||
| { | { | ||||
| bNode *node; | bNode *node; | ||||
| *r_mat = give_current_material(ob, mat_nr); | *r_mat = give_current_material(ob, mat_nr); | ||||
| ▲ Show 20 Lines • Show All 61 Lines • Show Last 20 Lines | |||||