Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/workbench/workbench_materials.c
| Show First 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | if (use_textures) { | ||||
| BLI_dynstr_appendf(ds, "#define V3D_SHADING_TEXTURE_COLOR\n"); | BLI_dynstr_appendf(ds, "#define V3D_SHADING_TEXTURE_COLOR\n"); | ||||
| } | } | ||||
| if (NORMAL_ENCODING_ENABLED()) { | if (NORMAL_ENCODING_ENABLED()) { | ||||
| BLI_dynstr_appendf(ds, "#define WORKBENCH_ENCODE_NORMALS\n"); | BLI_dynstr_appendf(ds, "#define WORKBENCH_ENCODE_NORMALS\n"); | ||||
| } | } | ||||
| if (is_hair) { | if (is_hair) { | ||||
| BLI_dynstr_appendf(ds, "#define HAIR_SHADER\n"); | BLI_dynstr_appendf(ds, "#define HAIR_SHADER\n"); | ||||
| } | } | ||||
| if (wpd->world_clip_planes != NULL) { | if (WORLD_CLIPPING_ENABLED(wpd)) { | ||||
| BLI_dynstr_appendf(ds, "#define USE_WORLD_CLIP_PLANES\n"); | BLI_dynstr_appendf(ds, "#define USE_WORLD_CLIP_PLANES\n"); | ||||
| } | } | ||||
| str = BLI_dynstr_get_cstring(ds); | str = BLI_dynstr_get_cstring(ds); | ||||
| BLI_dynstr_free(ds); | BLI_dynstr_free(ds); | ||||
| return str; | return str; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | int workbench_material_get_prepass_shader_index( | ||||
| /* 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, MATDATA_PASS_ENABLED(wpd), 1 << 1); | SET_FLAG_FROM_TEST(index, 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, wpd->world_clip_planes != NULL, 1 << 6); | SET_FLAG_FROM_TEST(index, WORLD_CLIPPING_ENABLED(wpd), 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, bool use_textures, bool is_hair) | int workbench_material_get_accum_shader_index(WORKBENCH_PrivateData *wpd, bool use_textures, bool is_hair) | ||||
| { | { | ||||
| /* 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 = SPECULAR_HIGHLIGHT_ENABLED(wpd) ? 3 : wpd->shading.light; | index = SPECULAR_HIGHLIGHT_ENABLED(wpd) ? 3 : 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, is_hair, 1 << 3); | SET_FLAG_FROM_TEST(index, is_hair, 1 << 3); | ||||
| /* 1 bits SHADOWS (only facing factor) */ | /* 1 bits SHADOWS (only facing factor) */ | ||||
| SET_FLAG_FROM_TEST(index, SHADOW_ENABLED(wpd), 1 << 4); | SET_FLAG_FROM_TEST(index, SHADOW_ENABLED(wpd), 1 << 4); | ||||
| SET_FLAG_FROM_TEST(index, WORLD_CLIPPING_ENABLED(wpd), 1 << 5); | |||||
| BLI_assert(index < MAX_ACCUM_SHADERS); | BLI_assert(index < MAX_ACCUM_SHADERS); | ||||
| return index; | return index; | ||||
| } | } | ||||
| int workbench_material_determine_color_type(WORKBENCH_PrivateData *wpd, Image *ima, Object *ob) | int workbench_material_determine_color_type(WORKBENCH_PrivateData *wpd, Image *ima, Object *ob) | ||||
| { | { | ||||
| int color_type = wpd->shading.color_type; | int color_type = wpd->shading.color_type; | ||||
| if ((color_type == V3D_SHADING_TEXTURE_COLOR && ima == NULL) || (ob->dt < OB_TEXTURE)) { | if ((color_type == V3D_SHADING_TEXTURE_COLOR && ima == NULL) || (ob->dt < OB_TEXTURE)) { | ||||
| ▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | if (use_metallic) { | ||||
| DRW_shgroup_uniform_float(grp, "materialMetallic", &material->metallic, 1); | DRW_shgroup_uniform_float(grp, "materialMetallic", &material->metallic, 1); | ||||
| } | } | ||||
| else { | else { | ||||
| DRW_shgroup_uniform_vec3(grp, "materialSpecularColor", material->specular_color, 1); | DRW_shgroup_uniform_vec3(grp, "materialSpecularColor", material->specular_color, 1); | ||||
| } | } | ||||
| DRW_shgroup_uniform_float(grp, "materialRoughness", &material->roughness, 1); | DRW_shgroup_uniform_float(grp, "materialRoughness", &material->roughness, 1); | ||||
| } | } | ||||
| if (wpd->world_clip_planes != NULL) { | if (WORLD_CLIPPING_ENABLED(wpd)) { | ||||
| DRW_shgroup_uniform_vec4(grp, "WorldClipPlanes", wpd->world_clip_planes[0], 6); | DRW_shgroup_uniform_vec4(grp, "WorldClipPlanes", wpd->world_clip_planes[0], 6); | ||||
| DRW_shgroup_state_enable(grp, DRW_STATE_CLIP_PLANES); | DRW_shgroup_state_enable(grp, DRW_STATE_CLIP_PLANES); | ||||
| } | } | ||||
| } | } | ||||
| void workbench_material_copy(WORKBENCH_MaterialData *dest_material, const WORKBENCH_MaterialData *source_material) | void workbench_material_copy(WORKBENCH_MaterialData *dest_material, const WORKBENCH_MaterialData *source_material) | ||||
| { | { | ||||
| dest_material->object_id = source_material->object_id; | dest_material->object_id = source_material->object_id; | ||||
| copy_v3_v3(dest_material->base_color, source_material->base_color); | copy_v3_v3(dest_material->base_color, source_material->base_color); | ||||
| copy_v3_v3(dest_material->diffuse_color, source_material->diffuse_color); | copy_v3_v3(dest_material->diffuse_color, source_material->diffuse_color); | ||||
| copy_v3_v3(dest_material->specular_color, source_material->specular_color); | copy_v3_v3(dest_material->specular_color, source_material->specular_color); | ||||
| dest_material->metallic = source_material->metallic; | dest_material->metallic = source_material->metallic; | ||||
| dest_material->roughness = source_material->roughness; | dest_material->roughness = source_material->roughness; | ||||
| dest_material->ima = source_material->ima; | dest_material->ima = source_material->ima; | ||||
| dest_material->iuser = source_material->iuser; | dest_material->iuser = source_material->iuser; | ||||
| } | } | ||||