Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/modes/object_mode.c
| Show All 32 Lines | |||||
| #include "DNA_meta_types.h" | #include "DNA_meta_types.h" | ||||
| #include "DNA_modifier_types.h" | #include "DNA_modifier_types.h" | ||||
| #include "DNA_object_force_types.h" | #include "DNA_object_force_types.h" | ||||
| #include "DNA_lightprobe_types.h" | #include "DNA_lightprobe_types.h" | ||||
| #include "DNA_particle_types.h" | #include "DNA_particle_types.h" | ||||
| #include "DNA_rigidbody_types.h" | #include "DNA_rigidbody_types.h" | ||||
| #include "DNA_smoke_types.h" | #include "DNA_smoke_types.h" | ||||
| #include "DNA_view3d_types.h" | #include "DNA_view3d_types.h" | ||||
| #include "DNA_screen_types.h" | |||||
| #include "DNA_world_types.h" | #include "DNA_world_types.h" | ||||
| #include "BKE_anim.h" | #include "BKE_anim.h" | ||||
| #include "BKE_camera.h" | #include "BKE_camera.h" | ||||
| #include "BKE_constraint.h" | #include "BKE_constraint.h" | ||||
| #include "BKE_curve.h" | #include "BKE_curve.h" | ||||
| #include "BKE_editmesh.h" | #include "BKE_editmesh.h" | ||||
| #include "BKE_image.h" | |||||
| #include "BKE_mball.h" | #include "BKE_mball.h" | ||||
| #include "BKE_mesh.h" | #include "BKE_mesh.h" | ||||
| #include "BKE_modifier.h" | #include "BKE_modifier.h" | ||||
| #include "BKE_movieclip.h" | #include "BKE_movieclip.h" | ||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "BKE_particle.h" | #include "BKE_particle.h" | ||||
| #include "BKE_tracking.h" | #include "BKE_tracking.h" | ||||
| #include "BLI_ghash.h" | #include "BLI_ghash.h" | ||||
| #include "IMB_imbuf_types.h" | |||||
| #include "ED_view3d.h" | #include "ED_view3d.h" | ||||
| #include "GPU_batch.h" | #include "GPU_batch.h" | ||||
| #include "GPU_draw.h" | #include "GPU_draw.h" | ||||
| #include "GPU_shader.h" | #include "GPU_shader.h" | ||||
| #include "GPU_texture.h" | #include "GPU_texture.h" | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| Show All 9 Lines | |||||
| extern char datatoc_object_outline_prepass_vert_glsl[]; | extern char datatoc_object_outline_prepass_vert_glsl[]; | ||||
| extern char datatoc_object_outline_prepass_geom_glsl[]; | extern char datatoc_object_outline_prepass_geom_glsl[]; | ||||
| extern char datatoc_object_outline_prepass_frag_glsl[]; | extern char datatoc_object_outline_prepass_frag_glsl[]; | ||||
| extern char datatoc_object_outline_resolve_frag_glsl[]; | extern char datatoc_object_outline_resolve_frag_glsl[]; | ||||
| extern char datatoc_object_outline_detect_frag_glsl[]; | extern char datatoc_object_outline_detect_frag_glsl[]; | ||||
| extern char datatoc_object_outline_expand_frag_glsl[]; | extern char datatoc_object_outline_expand_frag_glsl[]; | ||||
| extern char datatoc_object_grid_frag_glsl[]; | extern char datatoc_object_grid_frag_glsl[]; | ||||
| extern char datatoc_object_grid_vert_glsl[]; | extern char datatoc_object_grid_vert_glsl[]; | ||||
| extern char datatoc_object_camera_image_frag_glsl[]; | |||||
| extern char datatoc_object_camera_image_vert_glsl[]; | |||||
| extern char datatoc_object_empty_image_frag_glsl[]; | extern char datatoc_object_empty_image_frag_glsl[]; | ||||
| extern char datatoc_object_empty_image_vert_glsl[]; | extern char datatoc_object_empty_image_vert_glsl[]; | ||||
| extern char datatoc_object_lightprobe_grid_vert_glsl[]; | extern char datatoc_object_lightprobe_grid_vert_glsl[]; | ||||
| extern char datatoc_object_loose_points_frag_glsl[]; | extern char datatoc_object_loose_points_frag_glsl[]; | ||||
| extern char datatoc_object_particle_prim_vert_glsl[]; | extern char datatoc_object_particle_prim_vert_glsl[]; | ||||
| extern char datatoc_object_particle_dot_vert_glsl[]; | extern char datatoc_object_particle_dot_vert_glsl[]; | ||||
| extern char datatoc_object_particle_dot_frag_glsl[]; | extern char datatoc_object_particle_dot_frag_glsl[]; | ||||
| extern char datatoc_common_colormanagement_lib_glsl[]; | |||||
| extern char datatoc_common_globals_lib_glsl[]; | extern char datatoc_common_globals_lib_glsl[]; | ||||
| extern char datatoc_common_view_lib_glsl[]; | extern char datatoc_common_view_lib_glsl[]; | ||||
| extern char datatoc_common_fxaa_lib_glsl[]; | extern char datatoc_common_fxaa_lib_glsl[]; | ||||
| extern char datatoc_gpu_shader_flat_color_frag_glsl[]; | extern char datatoc_gpu_shader_flat_color_frag_glsl[]; | ||||
| extern char datatoc_gpu_shader_flat_id_frag_glsl[]; | extern char datatoc_gpu_shader_flat_id_frag_glsl[]; | ||||
| extern char datatoc_common_fullscreen_vert_glsl[]; | extern char datatoc_common_fullscreen_vert_glsl[]; | ||||
| extern char datatoc_gpu_shader_uniform_color_frag_glsl[]; | extern char datatoc_gpu_shader_uniform_color_frag_glsl[]; | ||||
| extern char datatoc_gpu_shader_3D_vert_glsl[]; | extern char datatoc_gpu_shader_3D_vert_glsl[]; | ||||
| Show All 12 Lines | typedef struct OBJECT_PassList { | ||||
| struct DRWPass *grid; | struct DRWPass *grid; | ||||
| struct DRWPass *bone_solid[2]; | struct DRWPass *bone_solid[2]; | ||||
| struct DRWPass *bone_outline[2]; | struct DRWPass *bone_outline[2]; | ||||
| struct DRWPass *bone_wire[2]; | struct DRWPass *bone_wire[2]; | ||||
| struct DRWPass *bone_envelope[2]; | struct DRWPass *bone_envelope[2]; | ||||
| struct DRWPass *bone_axes[2]; | struct DRWPass *bone_axes[2]; | ||||
| struct DRWPass *particle; | struct DRWPass *particle; | ||||
| struct DRWPass *lightprobes; | struct DRWPass *lightprobes; | ||||
| struct DRWPass *camera_images_back; | |||||
| struct DRWPass *camera_images_front; | |||||
| } OBJECT_PassList; | } OBJECT_PassList; | ||||
| typedef struct OBJECT_FramebufferList { | typedef struct OBJECT_FramebufferList { | ||||
| struct GPUFrameBuffer *outlines_fb; | struct GPUFrameBuffer *outlines_fb; | ||||
| struct GPUFrameBuffer *blur_fb; | struct GPUFrameBuffer *blur_fb; | ||||
| struct GPUFrameBuffer *expand_fb; | struct GPUFrameBuffer *expand_fb; | ||||
| struct GPUFrameBuffer *ghost_fb; | struct GPUFrameBuffer *ghost_fb; | ||||
| } OBJECT_FramebufferList; | } OBJECT_FramebufferList; | ||||
| Show All 17 Lines | typedef struct OBJECT_Shaders { | ||||
| GPUShader *outline_resolve; | GPUShader *outline_resolve; | ||||
| GPUShader *outline_resolve_aa; | GPUShader *outline_resolve_aa; | ||||
| GPUShader *outline_detect; | GPUShader *outline_detect; | ||||
| GPUShader *outline_detect_wire; | GPUShader *outline_detect_wire; | ||||
| GPUShader *outline_fade; | GPUShader *outline_fade; | ||||
| GPUShader *outline_fade_large; | GPUShader *outline_fade_large; | ||||
| /* regular shaders */ | /* regular shaders */ | ||||
| GPUShader *object_camera_image; | |||||
| GPUShader *object_empty_image; | GPUShader *object_empty_image; | ||||
| GPUShader *object_empty_image_wire; | GPUShader *object_empty_image_wire; | ||||
| GPUShader *grid; | GPUShader *grid; | ||||
| GPUShader *part_dot; | GPUShader *part_dot; | ||||
| GPUShader *part_prim; | GPUShader *part_prim; | ||||
| GPUShader *part_axis; | GPUShader *part_axis; | ||||
| GPUShader *lightprobe_grid; | GPUShader *lightprobe_grid; | ||||
| GPUShader *loose_points; | GPUShader *loose_points; | ||||
| ▲ Show 20 Lines • Show All 172 Lines • ▼ Show 20 Lines | static struct { | ||||
| bool draw_grid; | bool draw_grid; | ||||
| /* Temp buffer textures */ | /* Temp buffer textures */ | ||||
| struct GPUTexture *outlines_depth_tx; | struct GPUTexture *outlines_depth_tx; | ||||
| struct GPUTexture *outlines_id_tx; | struct GPUTexture *outlines_id_tx; | ||||
| struct GPUTexture *outlines_color_tx; | struct GPUTexture *outlines_color_tx; | ||||
| struct GPUTexture *outlines_blur_tx; | struct GPUTexture *outlines_blur_tx; | ||||
| ListBase smoke_domains; | ListBase smoke_domains; | ||||
| ListBase movie_clips; | |||||
| } e_data = {NULL}; /* Engine data */ | } e_data = {NULL}; /* Engine data */ | ||||
| enum { | enum { | ||||
| SHOW_AXIS_X = (1 << 0), | SHOW_AXIS_X = (1 << 0), | ||||
| SHOW_AXIS_Y = (1 << 1), | SHOW_AXIS_Y = (1 << 1), | ||||
| SHOW_AXIS_Z = (1 << 2), | SHOW_AXIS_Z = (1 << 2), | ||||
| SHOW_GRID = (1 << 3), | SHOW_GRID = (1 << 3), | ||||
| PLANE_XY = (1 << 4), | PLANE_XY = (1 << 4), | ||||
| ▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | /* Empty images */ | ||||
| "#define DEPTH_FRONT " STRINGIFY(OB_EMPTY_IMAGE_DEPTH_FRONT) "\n" | "#define DEPTH_FRONT " STRINGIFY(OB_EMPTY_IMAGE_DEPTH_FRONT) "\n" | ||||
| "#define DEPTH_BACK " STRINGIFY(OB_EMPTY_IMAGE_DEPTH_BACK) "\n"); | "#define DEPTH_BACK " STRINGIFY(OB_EMPTY_IMAGE_DEPTH_BACK) "\n"); | ||||
| sh_data->object_empty_image = GPU_shader_create_from_arrays({ | sh_data->object_empty_image = GPU_shader_create_from_arrays({ | ||||
| .vert = (const char *[]){sh_cfg_data->lib, | .vert = (const char *[]){sh_cfg_data->lib, | ||||
| datatoc_common_view_lib_glsl, | datatoc_common_view_lib_glsl, | ||||
| datatoc_object_empty_image_vert_glsl, | datatoc_object_empty_image_vert_glsl, | ||||
| NULL}, | NULL}, | ||||
| .frag = (const char *[]){datatoc_object_empty_image_frag_glsl, NULL}, | .frag = (const char *[]){datatoc_common_colormanagement_lib_glsl, | ||||
| datatoc_object_empty_image_frag_glsl, | |||||
| NULL}, | |||||
| .defs = (const char *[]){sh_cfg_data->def, empty_image_defs, NULL}, | .defs = (const char *[]){sh_cfg_data->def, empty_image_defs, NULL}, | ||||
| }); | }); | ||||
| sh_data->object_empty_image_wire = GPU_shader_create_from_arrays({ | sh_data->object_empty_image_wire = GPU_shader_create_from_arrays({ | ||||
| .vert = (const char *[]){sh_cfg_data->lib, | .vert = (const char *[]){sh_cfg_data->lib, | ||||
| datatoc_common_view_lib_glsl, | datatoc_common_view_lib_glsl, | ||||
| datatoc_object_empty_image_vert_glsl, | datatoc_object_empty_image_vert_glsl, | ||||
| NULL}, | NULL}, | ||||
| .frag = (const char *[]){datatoc_object_empty_image_frag_glsl, NULL}, | .frag = (const char *[]){datatoc_object_empty_image_frag_glsl, NULL}, | ||||
| .defs = (const char *[]){sh_cfg_data->def, "#define USE_WIRE\n", empty_image_defs, NULL}, | .defs = (const char *[]){sh_cfg_data->def, "#define USE_WIRE\n", empty_image_defs, NULL}, | ||||
| }); | }); | ||||
| sh_data->object_camera_image = GPU_shader_create_from_arrays({ | |||||
| .vert = (const char *[]){sh_cfg_data->lib, datatoc_object_camera_image_vert_glsl, NULL}, | |||||
| .frag = (const char *[]){datatoc_common_colormanagement_lib_glsl, | |||||
| datatoc_object_camera_image_frag_glsl, | |||||
| NULL}, | |||||
| }); | |||||
| } | } | ||||
| /* Grid */ | /* Grid */ | ||||
| sh_data->grid = GPU_shader_create_from_arrays({ | sh_data->grid = GPU_shader_create_from_arrays({ | ||||
| .vert = (const char *[]){datatoc_common_globals_lib_glsl, | .vert = (const char *[]){datatoc_common_globals_lib_glsl, | ||||
| datatoc_common_view_lib_glsl, | datatoc_common_view_lib_glsl, | ||||
| datatoc_object_grid_vert_glsl, | datatoc_object_grid_vert_glsl, | ||||
| NULL}, | NULL}, | ||||
| ▲ Show 20 Lines • Show All 548 Lines • ▼ Show 20 Lines | if (tex && ((ob->color[3] > 0.0f) || !use_alpha_blend)) { | ||||
| DRW_shgroup_uniform_bool_copy(grp, "useAlphaTest", !use_alpha_blend); | DRW_shgroup_uniform_bool_copy(grp, "useAlphaTest", !use_alpha_blend); | ||||
| if (sh_cfg == GPU_SHADER_CFG_CLIPPED) { | if (sh_cfg == GPU_SHADER_CFG_CLIPPED) { | ||||
| DRW_shgroup_state_enable(grp, DRW_STATE_CLIP_PLANES); | DRW_shgroup_state_enable(grp, DRW_STATE_CLIP_PLANES); | ||||
| } | } | ||||
| DRW_shgroup_call_no_cull(grp, DRW_cache_image_plane_get(), ob); | DRW_shgroup_call_no_cull(grp, DRW_cache_image_plane_get(), ob); | ||||
| } | } | ||||
| } | } | ||||
| /* Draw Camera Background Images */ | |||||
| typedef struct CameraEngineData { | |||||
| DrawData dd; | |||||
| ListBase bg_data; | |||||
| } CameraEngineData; | |||||
| typedef struct CameraEngineBGData { | |||||
| float transform_mat[4][4]; | |||||
| } CameraEngineBGData; | |||||
| static void camera_engine_data_free(DrawData *dd) | |||||
| { | |||||
| CameraEngineData *data = (CameraEngineData *)dd; | |||||
| for (LinkData *link = data->bg_data.first; link; link = link->next) { | |||||
| CameraEngineBGData *bg_data = (CameraEngineBGData *)link->data; | |||||
| MEM_freeN(bg_data); | |||||
| } | |||||
| BLI_freelistN(&data->bg_data); | |||||
| } | |||||
| static void camera_background_images_stereo_setup(Scene *scene, | |||||
| View3D *v3d, | |||||
| Image *ima, | |||||
| ImageUser *iuser) | |||||
| { | |||||
| if (BKE_image_is_stereo(ima)) { | |||||
| iuser->flag |= IMA_SHOW_STEREO; | |||||
| if ((scene->r.scemode & R_MULTIVIEW) == 0) { | |||||
| iuser->multiview_eye = STEREO_LEFT_ID; | |||||
| } | |||||
| else if (v3d->stereo3d_camera != STEREO_3D_ID) { | |||||
| /* show only left or right camera */ | |||||
| iuser->multiview_eye = v3d->stereo3d_camera; | |||||
| } | |||||
| BKE_image_multiview_index(ima, iuser); | |||||
| } | |||||
| else { | |||||
| iuser->flag &= ~IMA_SHOW_STEREO; | |||||
| } | |||||
| } | |||||
| static void DRW_shgroup_camera_background_images(OBJECT_Shaders *sh_data, | |||||
| OBJECT_PassList *psl, | |||||
| Object *ob, | |||||
| RegionView3D *rv3d) | |||||
| { | |||||
| if (!BKE_object_empty_image_frame_is_visible_in_view3d(ob, rv3d)) { | |||||
| return; | |||||
| } | |||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | |||||
| struct ARegion *ar = draw_ctx->ar; | |||||
| View3D *v3d = draw_ctx->v3d; | |||||
| Scene *scene = draw_ctx->scene; | |||||
| Depsgraph *depsgraph = draw_ctx->depsgraph; | |||||
| Camera *cam = ob->data; | |||||
| const Object *camera_object = DEG_get_evaluated_object(depsgraph, v3d->camera); | |||||
| const bool is_active = (ob == camera_object); | |||||
| const bool look_through = (is_active && (rv3d->persp == RV3D_CAMOB)); | |||||
| if (look_through && (cam->flag & CAM_SHOW_BG_IMAGE)) { | |||||
| GPUBatch *batch = DRW_cache_image_plane_get(); | |||||
| /* load camera engine data */ | |||||
| CameraEngineData *camera_engine_data = (CameraEngineData *)DRW_drawdata_ensure( | |||||
| &ob->id, | |||||
| &draw_engine_object_type, | |||||
| sizeof(CameraEngineData), | |||||
| NULL, | |||||
| camera_engine_data_free); | |||||
| LinkData *list_node = camera_engine_data->bg_data.first; | |||||
| for (CameraBGImage *bgpic = cam->bg_images.first; bgpic; bgpic = bgpic->next) { | |||||
| if ((bgpic->flag & CAM_BGIMG_FLAG_DISABLED)) { | |||||
| continue; | |||||
| } | |||||
| /* retrieve the image we want to show, continue to next when no image could be found */ | |||||
| ImBuf *ibuf = NULL; | |||||
| GPUTexture *tex = NULL; | |||||
| float image_aspect_x, image_aspect_y; | |||||
| float image_aspect; | |||||
| int image_width, image_height; | |||||
| bool premultiplied = false; | |||||
| if (bgpic->source == CAM_BGIMG_SOURCE_IMAGE) { | |||||
| Image *image = bgpic->ima; | |||||
| if (image == NULL) { | |||||
| continue; | |||||
| } | |||||
| premultiplied = (image->alpha_mode == IMA_ALPHA_PREMUL); | |||||
| ImageUser *iuser = &bgpic->iuser; | |||||
| BKE_image_user_frame_calc(image, iuser, (int)DEG_get_ctime(depsgraph)); | |||||
| if (image->source == IMA_SRC_SEQUENCE && !(iuser->flag & IMA_USER_FRAME_IN_RANGE)) { | |||||
| /* frame is out of range, dont show */ | |||||
| continue; | |||||
| } | |||||
| else { | |||||
| camera_background_images_stereo_setup(scene, v3d, image, iuser); | |||||
| } | |||||
| tex = GPU_texture_from_blender(image, iuser, GL_TEXTURE_2D); | |||||
| if (tex == NULL) { | |||||
| continue; | |||||
| } | |||||
| ibuf = BKE_image_acquire_ibuf(image, iuser, NULL); | |||||
| if (ibuf == NULL) { | |||||
| continue; | |||||
| } | |||||
| image_aspect_x = bgpic->ima->aspx; | |||||
| image_aspect_y = bgpic->ima->aspy; | |||||
| image_width = ibuf->x; | |||||
| image_height = ibuf->y; | |||||
| BKE_image_release_ibuf(image, ibuf, NULL); | |||||
jbakker: update comment
| |||||
| image_aspect = (image_width * image_aspect_x) / (image_height * image_aspect_y); | |||||
| } | |||||
| else if (bgpic->source == CAM_BGIMG_SOURCE_MOVIE) { | |||||
| MovieClip *clip = NULL; | |||||
| if (bgpic->flag & CAM_BGIMG_FLAG_CAMERACLIP) { | |||||
| if (scene->camera) { | |||||
| clip = BKE_object_movieclip_get(scene, scene->camera, true); | |||||
| } | |||||
| } | |||||
| else { | |||||
| clip = bgpic->clip; | |||||
| } | |||||
| if (clip == NULL) { | |||||
| continue; | |||||
| } | |||||
| image_aspect_x = clip->aspx; | |||||
| image_aspect_y = clip->aspy; | |||||
| BKE_movieclip_user_set_frame(&bgpic->cuser, (int)DEG_get_ctime(depsgraph)); | |||||
| tex = GPU_texture_from_movieclip(clip, &bgpic->cuser, GL_TEXTURE_2D); | |||||
| if (tex == NULL) { | |||||
| continue; | |||||
| } | |||||
| BLI_addtail(&e_data.movie_clips, BLI_genericNodeN(clip)); | |||||
| BKE_movieclip_get_size(clip, &bgpic->cuser, &image_width, &image_height); | |||||
| image_aspect = (image_width * image_aspect_x) / (image_height * image_aspect_y); | |||||
| } | |||||
| /* ensure link_data is allocated to store matrice */ | |||||
| CameraEngineBGData *bg_data; | |||||
| if (list_node != NULL) { | |||||
| bg_data = (CameraEngineBGData *)list_node->data; | |||||
| list_node = list_node->next; | |||||
| } | |||||
| else { | |||||
| bg_data = MEM_mallocN(sizeof(CameraEngineBGData), __func__); | |||||
| BLI_addtail(&camera_engine_data->bg_data, BLI_genericNodeN(bg_data)); | |||||
| } | |||||
| /* calculate the transformation matric for the current bg image */ | |||||
| float rot_m4[4][4]; | |||||
| float scale_m4[4][4]; | |||||
| float translate_m4[4][4]; | |||||
| float win_m4[4][4]; | |||||
| unit_m4(win_m4); | |||||
| unit_m4(scale_m4); | |||||
| axis_angle_to_mat4_single(rot_m4, 'Z', bgpic->rotation); | |||||
| unit_m4(translate_m4); | |||||
| rctf render_border; | |||||
| ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &render_border, false); | |||||
| const float camera_aspect_width = render_border.xmax - render_border.xmin; | |||||
| const float camera_aspect_height = render_border.ymax - render_border.ymin; | |||||
| const float camera_aspect_center_x = (render_border.xmax + render_border.xmin) / 2.0; | |||||
| const float camera_aspect_center_y = (render_border.ymax + render_border.ymin) / 2.0; | |||||
| const float camera_aspect = camera_aspect_width / camera_aspect_height; | |||||
| const float camera_aspect_x = (camera_aspect_width / ar->winx); | |||||
| const float camera_aspect_y = (camera_aspect_height / ar->winy); | |||||
| const float camera_offset_x = (camera_aspect_center_x - (ar->winx / 2.0)) / | |||||
| (0.5 * camera_aspect_width / camera_aspect_x); | |||||
| const float camera_offset_y = (camera_aspect_center_y - (ar->winy / 2.0)) / | |||||
| (0.5 * camera_aspect_height / camera_aspect_y); | |||||
| win_m4[0][0] = camera_aspect_x; | |||||
| win_m4[1][1] = camera_aspect_y; | |||||
| win_m4[3][0] = camera_offset_x; | |||||
| win_m4[3][1] = camera_offset_y; | |||||
| /* Update scaling based on image and camera framing */ | |||||
| float scale_x = bgpic->scale; | |||||
| float scale_y = bgpic->scale; | |||||
| if (bgpic->flag & CAM_BGIMG_FLAG_CAMERA_ASPECT) { | |||||
| float fit_scale = image_aspect / camera_aspect; | |||||
| if (bgpic->flag & CAM_BGIMG_FLAG_CAMERA_CROP) { | |||||
| if (image_aspect > camera_aspect) { | |||||
| scale_x *= fit_scale; | |||||
| } | |||||
| else { | |||||
| scale_y /= fit_scale; | |||||
| } | |||||
| } | |||||
| else { | |||||
| if (image_aspect > camera_aspect) { | |||||
| scale_y /= fit_scale; | |||||
| } | |||||
| else { | |||||
| scale_x *= fit_scale; | |||||
| } | |||||
| } | |||||
| } | |||||
| // scale image to match the desired aspect ratio | |||||
| scale_m4[0][0] = scale_x; | |||||
| scale_m4[1][1] = scale_y; | |||||
| // translate | |||||
| translate_m4[3][0] = bgpic->offset[0] * camera_aspect_x; | |||||
| translate_m4[3][1] = bgpic->offset[1] * camera_aspect_y; | |||||
Done Inline ActionsRevisit this order, rotation and translation do not work together. jbakker: Revisit this order, rotation and translation do not work together. | |||||
Done Inline ActionsAlso scaling does not work as expected. jbakker: Also scaling does not work as expected. | |||||
| mul_m4_series(bg_data->transform_mat, translate_m4, rot_m4, scale_m4, win_m4); | |||||
| DRWPass *pass = (bgpic->flag & CAM_BGIMG_FLAG_FOREGROUND) ? psl->camera_images_front : | |||||
| psl->camera_images_back; | |||||
| DRWShadingGroup *grp = DRW_shgroup_create(sh_data->object_camera_image, pass); | |||||
Done Inline ActionsChange to vec2 jbakker: Change to vec2 | |||||
| DRW_shgroup_uniform_float_copy( | |||||
| grp, "depth", (bgpic->flag & CAM_BGIMG_FLAG_FOREGROUND) ? 0.000001 : 0.999999); | |||||
| DRW_shgroup_uniform_float_copy(grp, "alpha", bgpic->alpha); | |||||
| DRW_shgroup_uniform_texture(grp, "image", tex); | |||||
| DRW_shgroup_uniform_bool_copy(grp, "imagePremultiplied", premultiplied); | |||||
| DRW_shgroup_uniform_float_copy( | |||||
| grp, "flipX", (bgpic->flag & CAM_BGIMG_FLAG_FLIP_X) ? -1.0 : 1.0); | |||||
| DRW_shgroup_uniform_float_copy( | |||||
| grp, "flipY", (bgpic->flag & CAM_BGIMG_FLAG_FLIP_Y) ? -1.0 : 1.0); | |||||
| DRW_shgroup_uniform_mat4(grp, "TransformMat", bg_data->transform_mat); | |||||
| DRW_shgroup_call(grp, batch, NULL); | |||||
| } | |||||
| } | |||||
| } | |||||
| static void camera_background_images_free_textures(void) | |||||
| { | |||||
| for (LinkData *link = e_data.movie_clips.first; link; link = link->next) { | |||||
| MovieClip *clip = (MovieClip *)link->data; | |||||
| GPU_free_texture_movieclip(clip); | |||||
| } | |||||
| BLI_freelistN(&e_data.movie_clips); | |||||
| } | |||||
| static void OBJECT_cache_init(void *vedata) | static void OBJECT_cache_init(void *vedata) | ||||
| { | { | ||||
| const GlobalsUboStorage *gb = &G_draw.block; | const GlobalsUboStorage *gb = &G_draw.block; | ||||
Done Inline Actionsremove line jbakker: remove line | |||||
| OBJECT_PassList *psl = ((OBJECT_Data *)vedata)->psl; | OBJECT_PassList *psl = ((OBJECT_Data *)vedata)->psl; | ||||
| OBJECT_StorageList *stl = ((OBJECT_Data *)vedata)->stl; | OBJECT_StorageList *stl = ((OBJECT_Data *)vedata)->stl; | ||||
| DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); | DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); | ||||
| OBJECT_PrivateData *g_data; | OBJECT_PrivateData *g_data; | ||||
| const DRWContextState *draw_ctx = DRW_context_state_get(); | const DRWContextState *draw_ctx = DRW_context_state_get(); | ||||
| OBJECT_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg]; | OBJECT_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg]; | ||||
| const float outline_width = UI_GetThemeValuef(TH_OUTLINE_WIDTH); | const float outline_width = UI_GetThemeValuef(TH_OUTLINE_WIDTH); | ||||
| ▲ Show 20 Lines • Show All 152 Lines • ▼ Show 20 Lines | g_data->custom_shapes = BLI_ghash_ptr_new(__func__); | ||||
| grp = DRW_shgroup_create(sh_data->grid, psl->grid); | grp = DRW_shgroup_create(sh_data->grid, psl->grid); | ||||
| DRW_shgroup_uniform_int(grp, "gridFlag", &e_data.zpos_flag, 1); | DRW_shgroup_uniform_int(grp, "gridFlag", &e_data.zpos_flag, 1); | ||||
| DRW_shgroup_uniform_vec3(grp, "planeAxes", e_data.zplane_axes, 1); | DRW_shgroup_uniform_vec3(grp, "planeAxes", e_data.zplane_axes, 1); | ||||
| DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); | DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); | ||||
| DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth); | DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth); | ||||
| DRW_shgroup_call(grp, geom, NULL); | DRW_shgroup_call(grp, geom, NULL); | ||||
| } | } | ||||
| /* Camera background images */ | |||||
| { | |||||
| /* TODO: Check blending it used the DRW_STATE_BLEND, but that has been removed */ | |||||
Done Inline ActionsThis is correct. BLEND_ALPHA is the old BLEND fclem: This is correct. BLEND_ALPHA is the old BLEND | |||||
| DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_BLEND_ALPHA; | |||||
| psl->camera_images_back = DRW_pass_create("Camera Images Back", state); | |||||
| psl->camera_images_front = DRW_pass_create("Camera Images Front", state); | |||||
| } | |||||
| for (int i = 0; i < 2; ++i) { | for (int i = 0; i < 2; ++i) { | ||||
| OBJECT_ShadingGroupList *sgl = (i == 1) ? &stl->g_data->sgl_ghost : &stl->g_data->sgl; | OBJECT_ShadingGroupList *sgl = (i == 1) ? &stl->g_data->sgl_ghost : &stl->g_data->sgl; | ||||
| /* Solid bones */ | /* Solid bones */ | ||||
| DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL; | DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL; | ||||
| sgl->bone_solid = psl->bone_solid[i] = DRW_pass_create("Bone Solid Pass", state); | sgl->bone_solid = psl->bone_solid[i] = DRW_pass_create("Bone Solid Pass", state); | ||||
| sgl->bone_outline = psl->bone_outline[i] = DRW_pass_create("Bone Outline Pass", state); | sgl->bone_outline = psl->bone_outline[i] = DRW_pass_create("Bone Outline Pass", state); | ||||
| ▲ Show 20 Lines • Show All 2,039 Lines • ▼ Show 20 Lines | switch (ob->type) { | ||||
| } | } | ||||
| DRW_shgroup_light(sgl, ob, view_layer); | DRW_shgroup_light(sgl, ob, view_layer); | ||||
| break; | break; | ||||
| case OB_CAMERA: | case OB_CAMERA: | ||||
| if (hide_object_extra) { | if (hide_object_extra) { | ||||
| break; | break; | ||||
| } | } | ||||
| DRW_shgroup_camera(sgl, ob, view_layer); | DRW_shgroup_camera(sgl, ob, view_layer); | ||||
| DRW_shgroup_camera_background_images(sh_data, psl, ob, rv3d); | |||||
| break; | break; | ||||
| case OB_EMPTY: | case OB_EMPTY: | ||||
| if (hide_object_extra) { | if (hide_object_extra) { | ||||
| break; | break; | ||||
| } | } | ||||
| DRW_shgroup_empty(sh_data, sgl, ob, view_layer, rv3d, draw_ctx->sh_cfg); | DRW_shgroup_empty(sh_data, sgl, ob, view_layer, rv3d, draw_ctx->sh_cfg); | ||||
| break; | break; | ||||
| case OB_SPEAKER: | case OB_SPEAKER: | ||||
| ▲ Show 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | static void OBJECT_draw_scene(void *vedata) | ||||
| int id_len_prb_transform = g_data->id_ofs_prb_transform; | int id_len_prb_transform = g_data->id_ofs_prb_transform; | ||||
| int outline_calls = id_len_select + id_len_select_dupli + id_len_active + id_len_transform; | int outline_calls = id_len_select + id_len_select_dupli + id_len_active + id_len_transform; | ||||
| outline_calls += id_len_prb_select + id_len_prb_select_dupli + id_len_prb_active + | outline_calls += id_len_prb_select + id_len_prb_select_dupli + id_len_prb_active + | ||||
| id_len_prb_transform; | id_len_prb_transform; | ||||
| float clearcol[4] = {0.0f, 0.0f, 0.0f, 0.0f}; | float clearcol[4] = {0.0f, 0.0f, 0.0f, 0.0f}; | ||||
| DRW_draw_pass(psl->camera_images_back); | |||||
| /* Don't draw Transparent passes in MSAA buffer. */ | /* Don't draw Transparent passes in MSAA buffer. */ | ||||
| // DRW_draw_pass(psl->bone_envelope); /* Never drawn in Object mode currently. */ | // DRW_draw_pass(psl->bone_envelope); /* Never drawn in Object mode currently. */ | ||||
| DRW_draw_pass(stl->g_data->sgl.transp_shapes); | DRW_draw_pass(stl->g_data->sgl.transp_shapes); | ||||
| MULTISAMPLE_SYNC_ENABLE(dfbl, dtxl); | MULTISAMPLE_SYNC_ENABLE(dfbl, dtxl); | ||||
| DRW_draw_pass(stl->g_data->sgl.bone_solid); | DRW_draw_pass(stl->g_data->sgl.bone_solid); | ||||
| DRW_draw_pass(stl->g_data->sgl.bone_wire); | DRW_draw_pass(stl->g_data->sgl.bone_wire); | ||||
| ▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | if (e_data.draw_grid) { | ||||
| DRW_draw_pass(psl->grid); | DRW_draw_pass(psl->grid); | ||||
| } | } | ||||
| /* Combine with scene buffer last */ | /* Combine with scene buffer last */ | ||||
| if (outline_calls > 0) { | if (outline_calls > 0) { | ||||
| DRW_draw_pass(psl->outlines_resolve); | DRW_draw_pass(psl->outlines_resolve); | ||||
| } | } | ||||
| } | } | ||||
| volumes_free_smoke_textures(); | volumes_free_smoke_textures(); | ||||
| batch_camera_path_free(&stl->g_data->sgl.camera_path); | batch_camera_path_free(&stl->g_data->sgl.camera_path); | ||||
| if (!DRW_pass_is_empty(stl->g_data->sgl_ghost.bone_solid) || | if (!DRW_pass_is_empty(stl->g_data->sgl_ghost.bone_solid) || | ||||
| !DRW_pass_is_empty(stl->g_data->sgl_ghost.bone_wire) || | !DRW_pass_is_empty(stl->g_data->sgl_ghost.bone_wire) || | ||||
| !DRW_pass_is_empty(stl->g_data->sgl_ghost.bone_outline) || | !DRW_pass_is_empty(stl->g_data->sgl_ghost.bone_outline) || | ||||
| !DRW_pass_is_empty(stl->g_data->sgl_ghost.non_meshes) || | !DRW_pass_is_empty(stl->g_data->sgl_ghost.non_meshes) || | ||||
| !DRW_pass_is_empty(stl->g_data->sgl_ghost.image_empties) || | !DRW_pass_is_empty(stl->g_data->sgl_ghost.image_empties) || | ||||
| Show All 32 Lines | if (!DRW_pass_is_empty(stl->g_data->sgl_ghost.bone_solid) || | ||||
| if (DRW_state_is_select()) { | if (DRW_state_is_select()) { | ||||
| GPU_depth_range(0.0f, 1.0f); | GPU_depth_range(0.0f, 1.0f); | ||||
| } | } | ||||
| } | } | ||||
| batch_camera_path_free(&stl->g_data->sgl_ghost.camera_path); | batch_camera_path_free(&stl->g_data->sgl_ghost.camera_path); | ||||
| DRW_draw_pass(psl->camera_images_front); | |||||
| camera_background_images_free_textures(); | |||||
| DRW_draw_pass(psl->ob_center); | DRW_draw_pass(psl->ob_center); | ||||
| } | } | ||||
| static const DrawEngineDataSize OBJECT_data_size = DRW_VIEWPORT_DATA_SIZE(OBJECT_Data); | static const DrawEngineDataSize OBJECT_data_size = DRW_VIEWPORT_DATA_SIZE(OBJECT_Data); | ||||
| DrawEngineType draw_engine_object_type = { | DrawEngineType draw_engine_object_type = { | ||||
| NULL, | NULL, | ||||
| NULL, | NULL, | ||||
| Show All 12 Lines | |||||
update comment