Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/paint_utils.c
| Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | |||||
| #include "GPU_texture.h" | #include "GPU_texture.h" | ||||
| #include "IMB_colormanagement.h" | #include "IMB_colormanagement.h" | ||||
| #include "IMB_imbuf.h" | #include "IMB_imbuf.h" | ||||
| #include "IMB_imbuf_types.h" | #include "IMB_imbuf_types.h" | ||||
| #include "RE_render_ext.h" | #include "RE_render_ext.h" | ||||
| #include "ED_image.h" | |||||
| #include "ED_screen.h" | #include "ED_screen.h" | ||||
| #include "ED_view3d.h" | #include "ED_view3d.h" | ||||
| #include "BLI_sys_types.h" | #include "BLI_sys_types.h" | ||||
| #include "ED_mesh.h" /* for face mask functions */ | #include "ED_mesh.h" /* for face mask functions */ | ||||
| #include "DRW_select_buffer.h" | #include "DRW_select_buffer.h" | ||||
| ▲ Show 20 Lines • Show All 376 Lines • ▼ Show 20 Lines | void paint_sample_color( | ||||
| bContext *C, ARegion *region, int x, int y, bool texpaint_proj, bool use_palette) | bContext *C, ARegion *region, int x, int y, bool texpaint_proj, bool use_palette) | ||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); | ||||
| Paint *paint = BKE_paint_get_active_from_context(C); | Paint *paint = BKE_paint_get_active_from_context(C); | ||||
| Palette *palette = BKE_paint_palette(paint); | Palette *palette = BKE_paint_palette(paint); | ||||
| PaletteColor *color = NULL; | PaletteColor *color = NULL; | ||||
| Brush *br = BKE_paint_brush(BKE_paint_get_active_from_context(C)); | Brush *br = BKE_paint_brush(BKE_paint_get_active_from_context(C)); | ||||
| uint col; | |||||
| const uchar *cp; | |||||
| CLAMP(x, 0, region->winx); | CLAMP(x, 0, region->winx); | ||||
| CLAMP(y, 0, region->winy); | CLAMP(y, 0, region->winy); | ||||
| if (use_palette) { | if (use_palette) { | ||||
| if (!palette) { | if (!palette) { | ||||
| palette = BKE_palette_add(CTX_data_main(C), "Palette"); | palette = BKE_palette_add(CTX_data_main(C), "Palette"); | ||||
| BKE_paint_palette_set(paint, palette); | BKE_paint_palette_set(paint, palette); | ||||
| } | } | ||||
| color = BKE_palette_color_add(palette); | color = BKE_palette_color_add(palette); | ||||
| palette->active_color = BLI_listbase_count(&palette->colors) - 1; | palette->active_color = BLI_listbase_count(&palette->colors) - 1; | ||||
| } | } | ||||
| if (CTX_wm_view3d(C) && texpaint_proj) { | SpaceImage *sima = CTX_wm_space_image(C); | ||||
| const View3D *v3d = CTX_wm_view3d(C); | |||||
| if (v3d && texpaint_proj) { | |||||
| /* first try getting a color directly from the mesh faces if possible */ | /* first try getting a color directly from the mesh faces if possible */ | ||||
| ViewLayer *view_layer = CTX_data_view_layer(C); | ViewLayer *view_layer = CTX_data_view_layer(C); | ||||
| Object *ob = OBACT(view_layer); | Object *ob = OBACT(view_layer); | ||||
| Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); | Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); | ||||
| bool sample_success = false; | |||||
| ImagePaintSettings *imapaint = &scene->toolsettings->imapaint; | ImagePaintSettings *imapaint = &scene->toolsettings->imapaint; | ||||
| bool use_material = (imapaint->mode == IMAGEPAINT_MODE_MATERIAL); | bool use_material = (imapaint->mode == IMAGEPAINT_MODE_MATERIAL); | ||||
| if (ob) { | if (ob) { | ||||
| CustomData_MeshMasks cddata_masks = CD_MASK_BAREMESH; | CustomData_MeshMasks cddata_masks = CD_MASK_BAREMESH; | ||||
| cddata_masks.pmask |= CD_MASK_ORIGINDEX; | cddata_masks.pmask |= CD_MASK_ORIGINDEX; | ||||
| Mesh *me = (Mesh *)ob->data; | Mesh *me = (Mesh *)ob->data; | ||||
| Mesh *me_eval = mesh_get_eval_final(depsgraph, scene, ob_eval, &cddata_masks); | Mesh *me_eval = mesh_get_eval_final(depsgraph, scene, ob_eval, &cddata_masks); | ||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | if (ob) { | ||||
| } | } | ||||
| if (v < 0.0f) { | if (v < 0.0f) { | ||||
| v += 1.0f; | v += 1.0f; | ||||
| } | } | ||||
| } | } | ||||
| ImBuf *ibuf = BKE_image_acquire_ibuf(image, &iuser, NULL); | ImBuf *ibuf = BKE_image_acquire_ibuf(image, &iuser, NULL); | ||||
| if (ibuf && (ibuf->rect || ibuf->rect_float)) { | if (ibuf && (ibuf->rect || ibuf->rect_float)) { | ||||
| sample_success = true; | |||||
| u = u * ibuf->x; | u = u * ibuf->x; | ||||
| v = v * ibuf->y; | v = v * ibuf->y; | ||||
| if (ibuf->rect_float) { | if (ibuf->rect_float) { | ||||
| float rgba_f[4]; | float rgba_f[4]; | ||||
| bilinear_interpolation_color_wrap(ibuf, NULL, rgba_f, u, v); | bilinear_interpolation_color_wrap(ibuf, NULL, rgba_f, u, v); | ||||
| straight_to_premul_v4(rgba_f); | straight_to_premul_v4(rgba_f); | ||||
| if (use_palette) { | if (use_palette) { | ||||
| Show All 11 Lines | if (ob) { | ||||
| rgb_uchar_to_float(color->rgb, rgba); | rgb_uchar_to_float(color->rgb, rgba); | ||||
| } | } | ||||
| else { | else { | ||||
| float rgba_f[3]; | float rgba_f[3]; | ||||
| rgb_uchar_to_float(rgba_f, rgba); | rgb_uchar_to_float(rgba_f, rgba); | ||||
| BKE_brush_color_set(scene, br, rgba_f); | BKE_brush_color_set(scene, br, rgba_f); | ||||
| } | } | ||||
| } | } | ||||
| BKE_image_release_ibuf(image, ibuf, NULL); | |||||
| return; | |||||
| } | } | ||||
| BKE_image_release_ibuf(image, ibuf, NULL); | BKE_image_release_ibuf(image, ibuf, NULL); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| if (!sample_success) { | else if (sima != NULL) { | ||||
| GPU_frontbuffer_read_pixels( | /* Sample from the active image buffer. The sampled color is in | ||||
| x + region->winrct.xmin, y + region->winrct.ymin, 1, 1, 4, GPU_DATA_UNSIGNED_BYTE, &col); | * Linear Scene Reference Space. */ | ||||
| float rgba_f[3]; | |||||
| if (ED_space_image_color_sample(sima, region, (int[2]){x, y}, rgba_f)) { | |||||
| linearrgb_to_srgb_v3_v3(rgba_f, rgba_f); | |||||
| if (use_palette) { | |||||
| copy_v3_v3(color->rgb, rgba_f); | |||||
| } | } | ||||
| else { | else { | ||||
| BKE_brush_color_set(scene, br, rgba_f); | |||||
| } | |||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| else { | |||||
| /* No sample found; sample directly from the GPU front buffer. */ | |||||
| { | |||||
| float rgba_f[4]; | |||||
| GPU_frontbuffer_read_pixels( | GPU_frontbuffer_read_pixels( | ||||
| x + region->winrct.xmin, y + region->winrct.ymin, 1, 1, 4, GPU_DATA_UNSIGNED_BYTE, &col); | x + region->winrct.xmin, y + region->winrct.ymin, 1, 1, 4, GPU_DATA_FLOAT, &rgba_f); | ||||
| } | |||||
| cp = (uchar *)&col; | |||||
| if (use_palette) { | if (use_palette) { | ||||
| rgb_uchar_to_float(color->rgb, cp); | copy_v3_v3(color->rgb, rgba_f); | ||||
| } | } | ||||
| else { | else { | ||||
| float rgba_f[3]; | |||||
| rgb_uchar_to_float(rgba_f, cp); | |||||
| BKE_brush_color_set(scene, br, rgba_f); | BKE_brush_color_set(scene, br, rgba_f); | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| static int brush_curve_preset_exec(bContext *C, wmOperator *op) | static int brush_curve_preset_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Brush *br = BKE_paint_brush(BKE_paint_get_active_from_context(C)); | Brush *br = BKE_paint_brush(BKE_paint_get_active_from_context(C)); | ||||
| if (br) { | if (br) { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| ViewLayer *view_layer = CTX_data_view_layer(C); | ViewLayer *view_layer = CTX_data_view_layer(C); | ||||
| ▲ Show 20 Lines • Show All 207 Lines • Show Last 20 Lines | |||||