Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/render/render_preview.c
| Show First 20 Lines • Show All 300 Lines • ▼ Show 20 Lines | switch (pr_type) { | ||||
| case MA_ATMOS: | case MA_ATMOS: | ||||
| return "Atmosphere"; | return "Atmosphere"; | ||||
| default: | default: | ||||
| BLI_assert(!"Unknown preview type"); | BLI_assert(!"Unknown preview type"); | ||||
| return ""; | return ""; | ||||
| } | } | ||||
| } | } | ||||
| static void set_preview_layer(SceneLayer *scene_layer, char pr_type) | static void set_preview_layer(ViewLayer *view_layer, char pr_type) | ||||
| { | { | ||||
| LayerCollection *lc; | LayerCollection *lc; | ||||
| const char *collection_name = preview_layer_name(pr_type); | const char *collection_name = preview_layer_name(pr_type); | ||||
| for (lc = scene_layer->layer_collections.first; lc; lc = lc->next) { | for (lc = view_layer->layer_collections.first; lc; lc = lc->next) { | ||||
| if (STREQ(lc->scene_collection->name, collection_name)) { | if (STREQ(lc->scene_collection->name, collection_name)) { | ||||
| lc->flag = COLLECTION_VISIBLE | COLLECTION_DISABLED; | lc->flag = COLLECTION_VISIBLE | COLLECTION_DISABLED; | ||||
| BKE_collection_enable(scene_layer, lc); | BKE_collection_enable(view_layer, lc); | ||||
| } | } | ||||
| else { | else { | ||||
| BKE_collection_disable(scene_layer, lc); | BKE_collection_disable(view_layer, lc); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static World *preview_get_localized_world(ShaderPreview *sp, World *world) | static World *preview_get_localized_world(ShaderPreview *sp, World *world) | ||||
| { | { | ||||
| if (world == NULL) { | if (world == NULL) { | ||||
| return NULL; | return NULL; | ||||
| Show All 12 Lines | |||||
| { | { | ||||
| Scene *sce; | Scene *sce; | ||||
| Main *pr_main = sp->pr_main; | Main *pr_main = sp->pr_main; | ||||
| memcpy(pr_main->name, bmain->name, sizeof(pr_main->name)); | memcpy(pr_main->name, bmain->name, sizeof(pr_main->name)); | ||||
| sce = preview_get_scene(pr_main); | sce = preview_get_scene(pr_main); | ||||
| if (sce) { | if (sce) { | ||||
| SceneLayer *scene_layer = BKE_scene_layer_from_scene_get(sce); | ViewLayer *view_layer = BKE_view_layer_from_scene_get(sce); | ||||
| /* this flag tells render to not execute depsgraph or ipos etc */ | /* this flag tells render to not execute depsgraph or ipos etc */ | ||||
| sce->r.scemode |= R_BUTS_PREVIEW; | sce->r.scemode |= R_BUTS_PREVIEW; | ||||
| /* set world always back, is used now */ | /* set world always back, is used now */ | ||||
| sce->world = pr_main->world.first; | sce->world = pr_main->world.first; | ||||
| /* now: exposure copy */ | /* now: exposure copy */ | ||||
| if (scene->world) { | if (scene->world) { | ||||
| sce->world->exp = scene->world->exp; | sce->world->exp = scene->world->exp; | ||||
| ▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | if (id_type == ID_MA) { | ||||
| sce->r.mode |= R_RAYTRACE; | sce->r.mode |= R_RAYTRACE; | ||||
| if (preview_mat_has_sss(mat, NULL)) | if (preview_mat_has_sss(mat, NULL)) | ||||
| sce->r.mode |= R_SSS; | sce->r.mode |= R_SSS; | ||||
| /* turn off fake shadows if needed */ | /* turn off fake shadows if needed */ | ||||
| /* this only works in a specific case where the preview.blend contains | /* this only works in a specific case where the preview.blend contains | ||||
| * an object starting with 'c' which has a material linked to it (not the obdata) | * an object starting with 'c' which has a material linked to it (not the obdata) | ||||
| * and that material has a fake shadow texture in the active texture slot */ | * and that material has a fake shadow texture in the active texture slot */ | ||||
| for (Base *base = scene_layer->object_bases.first; base; base = base->next) { | for (Base *base = view_layer->object_bases.first; base; base = base->next) { | ||||
| Object *ob = base->object; | Object *ob = base->object; | ||||
| if (ob->id.name[2] == 'c') { | if (ob->id.name[2] == 'c') { | ||||
| Material *shadmat = give_current_material(ob, ob->actcol); | Material *shadmat = give_current_material(ob, ob->actcol); | ||||
| if (shadmat) { | if (shadmat) { | ||||
| if (mat->mode2 & MA_CASTSHADOW) { | if (mat->mode2 & MA_CASTSHADOW) { | ||||
| shadmat->septex = 0; | shadmat->septex = 0; | ||||
| } | } | ||||
| else { | else { | ||||
| shadmat->septex |= 1; | shadmat->septex |= 1; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* turn off bounce lights for volume, | /* turn off bounce lights for volume, | ||||
| * doesn't make much visual difference and slows it down too */ | * doesn't make much visual difference and slows it down too */ | ||||
| for (Base *base = scene_layer->object_bases.first; base; base = base->next) { | for (Base *base = view_layer->object_bases.first; base; base = base->next) { | ||||
| Object *ob = base->object; | Object *ob = base->object; | ||||
| if (ob->type == OB_LAMP) { | if (ob->type == OB_LAMP) { | ||||
| /* if doesn't match 'Lamp.002' --> main key light */ | /* if doesn't match 'Lamp.002' --> main key light */ | ||||
| if (!STREQ(ob->id.name + 2, "Lamp.002")) { | if (!STREQ(ob->id.name + 2, "Lamp.002")) { | ||||
| if (mat->material_type == MA_TYPE_VOLUME) { | if (mat->material_type == MA_TYPE_VOLUME) { | ||||
| base->flag &= ~BASE_VISIBLED; | base->flag &= ~BASE_VISIBLED; | ||||
| } | } | ||||
| else { | else { | ||||
| base->flag |= BASE_VISIBLED; | base->flag |= BASE_VISIBLED; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* use current scene world to light sphere */ | /* use current scene world to light sphere */ | ||||
| if (mat->pr_type == MA_SPHERE_A) { | if (mat->pr_type == MA_SPHERE_A) { | ||||
| sce->world = preview_get_localized_world(sp, scene->world); | sce->world = preview_get_localized_world(sp, scene->world); | ||||
| } | } | ||||
| } | } | ||||
| if (sp->pr_method == PR_ICON_RENDER) { | if (sp->pr_method == PR_ICON_RENDER) { | ||||
| if (mat->material_type == MA_TYPE_HALO) { | if (mat->material_type == MA_TYPE_HALO) { | ||||
| set_preview_layer(scene_layer, MA_FLAT); | set_preview_layer(view_layer, MA_FLAT); | ||||
| } | } | ||||
| else { | else { | ||||
| set_preview_layer(scene_layer, MA_SPHERE_A); | set_preview_layer(view_layer, MA_SPHERE_A); | ||||
| /* same as above, use current scene world to light sphere */ | /* same as above, use current scene world to light sphere */ | ||||
| if (BKE_scene_use_new_shading_nodes(scene)) | if (BKE_scene_use_new_shading_nodes(scene)) | ||||
| sce->world = preview_get_localized_world(sp, scene->world); | sce->world = preview_get_localized_world(sp, scene->world); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| set_preview_layer(scene_layer, mat->pr_type); | set_preview_layer(view_layer, mat->pr_type); | ||||
| if (mat->nodetree && sp->pr_method == PR_NODE_RENDER) { | if (mat->nodetree && sp->pr_method == PR_NODE_RENDER) { | ||||
| /* two previews, they get copied by wmJob */ | /* two previews, they get copied by wmJob */ | ||||
| BKE_node_preview_init_tree(mat->nodetree, sp->sizex, sp->sizey, true); | BKE_node_preview_init_tree(mat->nodetree, sp->sizex, sp->sizey, true); | ||||
| BKE_node_preview_init_tree(origmat->nodetree, sp->sizex, sp->sizey, true); | BKE_node_preview_init_tree(origmat->nodetree, sp->sizex, sp->sizey, true); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| sce->r.mode &= ~(R_OSA | R_RAYTRACE | R_SSS); | sce->r.mode &= ~(R_OSA | R_RAYTRACE | R_SSS); | ||||
| } | } | ||||
| for (Base *base = scene_layer->object_bases.first; base; base = base->next) { | for (Base *base = view_layer->object_bases.first; base; base = base->next) { | ||||
| if (base->object->id.name[2] == 'p') { | if (base->object->id.name[2] == 'p') { | ||||
| /* copy over object color, in case material uses it */ | /* copy over object color, in case material uses it */ | ||||
| copy_v4_v4(base->object->col, sp->col); | copy_v4_v4(base->object->col, sp->col); | ||||
| if (OB_TYPE_SUPPORT_MATERIAL(base->object->type)) { | if (OB_TYPE_SUPPORT_MATERIAL(base->object->type)) { | ||||
| /* don't use assign_material, it changed mat->id.us, which shows in the UI */ | /* don't use assign_material, it changed mat->id.us, which shows in the UI */ | ||||
| Material ***matar = give_matarar(base->object); | Material ***matar = give_matarar(base->object); | ||||
| int actcol = max_ii(base->object->actcol - 1, 0); | int actcol = max_ii(base->object->actcol - 1, 0); | ||||
| Show All 10 Lines | if (sce) { | ||||
| else if (id_type == ID_TE) { | else if (id_type == ID_TE) { | ||||
| Tex *tex = NULL, *origtex = (Tex *)id; | Tex *tex = NULL, *origtex = (Tex *)id; | ||||
| if (origtex) { | if (origtex) { | ||||
| tex = BKE_texture_localize(origtex); | tex = BKE_texture_localize(origtex); | ||||
| sp->texcopy = tex; | sp->texcopy = tex; | ||||
| BLI_addtail(&pr_main->tex, tex); | BLI_addtail(&pr_main->tex, tex); | ||||
| } | } | ||||
| set_preview_layer(scene_layer, MA_TEXTURE); | set_preview_layer(view_layer, MA_TEXTURE); | ||||
| for (Base *base = scene_layer->object_bases.first; base; base = base->next) { | for (Base *base = view_layer->object_bases.first; base; base = base->next) { | ||||
| if (base->object->id.name[2] == 't') { | if (base->object->id.name[2] == 't') { | ||||
| Material *mat = give_current_material(base->object, base->object->actcol); | Material *mat = give_current_material(base->object, base->object->actcol); | ||||
| if (mat && mat->mtex[0]) { | if (mat && mat->mtex[0]) { | ||||
| mat->mtex[0]->tex = tex; | mat->mtex[0]->tex = tex; | ||||
| if (tex && sp->slot) | if (tex && sp->slot) | ||||
| mat->mtex[0]->which_output = sp->slot->which_output; | mat->mtex[0]->which_output = sp->slot->which_output; | ||||
| Show All 24 Lines | else if (id_type == ID_LA) { | ||||
| if (origla) { | if (origla) { | ||||
| la = localize_lamp(origla); | la = localize_lamp(origla); | ||||
| sp->lampcopy = la; | sp->lampcopy = la; | ||||
| BLI_addtail(&pr_main->lamp, la); | BLI_addtail(&pr_main->lamp, la); | ||||
| } | } | ||||
| if (!BKE_scene_use_new_shading_nodes(scene)) { | if (!BKE_scene_use_new_shading_nodes(scene)) { | ||||
| if (la && la->type == LA_SUN && (la->sun_effect_type & LA_SUN_EFFECT_SKY)) { | if (la && la->type == LA_SUN && (la->sun_effect_type & LA_SUN_EFFECT_SKY)) { | ||||
| set_preview_layer(scene_layer, MA_ATMOS); | set_preview_layer(view_layer, MA_ATMOS); | ||||
| sce->world = preview_get_localized_world(sp, scene->world); | sce->world = preview_get_localized_world(sp, scene->world); | ||||
| sce->camera = (Object *)BLI_findstring(&pr_main->object, "CameraAtmo", offsetof(ID, name) + 2); | sce->camera = (Object *)BLI_findstring(&pr_main->object, "CameraAtmo", offsetof(ID, name) + 2); | ||||
| } | } | ||||
| else { | else { | ||||
| sce->world = NULL; | sce->world = NULL; | ||||
| sce->camera = (Object *)BLI_findstring(&pr_main->object, "Camera", offsetof(ID, name) + 2); | sce->camera = (Object *)BLI_findstring(&pr_main->object, "Camera", offsetof(ID, name) + 2); | ||||
| set_preview_layer(scene_layer, MA_LAMP); | set_preview_layer(view_layer, MA_LAMP); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| set_preview_layer(scene_layer, MA_LAMP); | set_preview_layer(view_layer, MA_LAMP); | ||||
| } | } | ||||
| for (Base *base = scene_layer->object_bases.first; base; base = base->next) { | for (Base *base = view_layer->object_bases.first; base; base = base->next) { | ||||
| if (base->object->id.name[2] == 'p') { | if (base->object->id.name[2] == 'p') { | ||||
| if (base->object->type == OB_LAMP) | if (base->object->type == OB_LAMP) | ||||
| base->object->data = la; | base->object->data = la; | ||||
| } | } | ||||
| } | } | ||||
| if (la && la->nodetree && sp->pr_method == PR_NODE_RENDER) { | if (la && la->nodetree && sp->pr_method == PR_NODE_RENDER) { | ||||
| /* two previews, they get copied by wmJob */ | /* two previews, they get copied by wmJob */ | ||||
| BKE_node_preview_init_tree(origla->nodetree, sp->sizex, sp->sizey, true); | BKE_node_preview_init_tree(origla->nodetree, sp->sizex, sp->sizey, true); | ||||
| BKE_node_preview_init_tree(la->nodetree, sp->sizex, sp->sizey, true); | BKE_node_preview_init_tree(la->nodetree, sp->sizex, sp->sizey, true); | ||||
| } | } | ||||
| } | } | ||||
| else if (id_type == ID_WO) { | else if (id_type == ID_WO) { | ||||
| World *wrld = NULL, *origwrld = (World *)id; | World *wrld = NULL, *origwrld = (World *)id; | ||||
| if (origwrld) { | if (origwrld) { | ||||
| wrld = localize_world(origwrld); | wrld = localize_world(origwrld); | ||||
| sp->worldcopy = wrld; | sp->worldcopy = wrld; | ||||
| BLI_addtail(&pr_main->world, wrld); | BLI_addtail(&pr_main->world, wrld); | ||||
| } | } | ||||
| set_preview_layer(scene_layer, MA_SKY); | set_preview_layer(view_layer, MA_SKY); | ||||
| sce->world = wrld; | sce->world = wrld; | ||||
| if (wrld && wrld->nodetree && sp->pr_method == PR_NODE_RENDER) { | if (wrld && wrld->nodetree && sp->pr_method == PR_NODE_RENDER) { | ||||
| /* two previews, they get copied by wmJob */ | /* two previews, they get copied by wmJob */ | ||||
| BKE_node_preview_init_tree(wrld->nodetree, sp->sizex, sp->sizey, true); | BKE_node_preview_init_tree(wrld->nodetree, sp->sizex, sp->sizey, true); | ||||
| BKE_node_preview_init_tree(origwrld->nodetree, sp->sizex, sp->sizey, true); | BKE_node_preview_init_tree(origwrld->nodetree, sp->sizex, sp->sizey, true); | ||||
| } | } | ||||
| } | } | ||||
| Depsgraph *depsgraph = BKE_scene_get_depsgraph(sce, scene_layer, true); | Depsgraph *depsgraph = BKE_scene_get_depsgraph(sce, view_layer, true); | ||||
| /* TODO(sergey): Use proper flag for tagging here. */ | /* TODO(sergey): Use proper flag for tagging here. */ | ||||
| DEG_graph_id_tag_update(pr_main, depsgraph, &sce->id, 0); | DEG_graph_id_tag_update(pr_main, depsgraph, &sce->id, 0); | ||||
| DEG_relations_tag_update(pr_main); | DEG_relations_tag_update(pr_main); | ||||
| BKE_scene_graph_update_tagged(pr_main->eval_ctx, depsgraph, pr_main, sce, scene_layer); | BKE_scene_graph_update_tagged(pr_main->eval_ctx, depsgraph, pr_main, sce, view_layer); | ||||
| return sce; | return sce; | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /* new UI convention: draw is in pixel space already. */ | /* new UI convention: draw is in pixel space already. */ | ||||
| ▲ Show 20 Lines • Show All 775 Lines • Show Last 20 Lines | |||||