64 PassMain background_ps_ = {
"background_ps_"};
67 PassMain foreground_ps_ = {
"foreground_ps_"};
70 PassMain background_scene_ps_ = {
"background_scene_ps_"};
72 PassMain foreground_scene_ps_ = {
"foreground_scene_ps_"};
76 CameraInstanceBuf distances_buf = {selection_type_,
"camera_distances_buf"};
77 CameraInstanceBuf frame_buf = {selection_type_,
"camera_frame_buf"};
78 CameraInstanceBuf tria_buf = {selection_type_,
"camera_tria_buf"};
79 CameraInstanceBuf tria_wire_buf = {selection_type_,
"camera_tria_wire_buf"};
80 CameraInstanceBuf volume_buf = {selection_type_,
"camera_volume_buf"};
81 CameraInstanceBuf volume_wire_buf = {selection_type_,
"camera_volume_wire_buf"};
82 CameraInstanceBuf sphere_solid_buf = {selection_type_,
"camera_sphere_solid_buf"};
83 LinePrimitiveBuf stereo_connect_lines = {selection_type_,
"camera_dashed_lines_buf"};
84 LinePrimitiveBuf tracking_path = {selection_type_,
"camera_tracking_path_buf"};
85 Empties::CallBuffers empties{selection_type_};
88 bool images_enabled_ =
false;
89 bool extras_enabled_ =
false;
90 bool motion_tracking_enabled_ =
false;
103 images_enabled_ =
enabled_ && !res.is_selection() && !
state.is_depth_only_drawing;
104 enabled_ = extras_enabled_ || images_enabled_ || motion_tracking_enabled_;
106 offset_data_ =
state.offset_data_get();
108 if (extras_enabled_ || motion_tracking_enabled_) {
109 call_buffers_.distances_buf.clear();
110 call_buffers_.frame_buf.clear();
111 call_buffers_.tria_buf.clear();
112 call_buffers_.tria_wire_buf.clear();
113 call_buffers_.volume_buf.clear();
114 call_buffers_.volume_wire_buf.clear();
115 call_buffers_.sphere_solid_buf.clear();
116 call_buffers_.stereo_connect_lines.clear();
117 call_buffers_.tracking_path.clear();
121 if (images_enabled_) {
126 pass.
shader_set(res.shaders->image_plane_depth_bias.get());
129 pass.
push_constant(
"depth_bias_winmat", &depth_bias_winmat_);
130 res.select_bind(pass);
135 init_pass(background_ps_, draw_state);
138 init_pass(background_scene_ps_, draw_state);
141 init_pass(foreground_ps_, draw_state);
142 init_pass(foreground_scene_ps_, draw_state);
155 const select::ID select_id = res.select_id(ob_ref);
157 object_sync_extras(ob_ref, select_id,
state, res);
159 object_sync_motion_paths(ob_ref, res,
state);
161 object_sync_images(ob_ref, select_id, manager,
state, res);
166 if (!extras_enabled_ && !motion_tracking_enabled_) {
173 res.select_bind(ps_);
179 state.clipping_plane_count);
180 sub_pass.
shader_set(res.shaders->extra_shape.get());
181 call_buffers_.volume_buf.end_sync(sub_pass, res.shapes.camera_volume.get());
187 state.clipping_plane_count);
188 sub_pass.
shader_set(res.shaders->extra_shape.get());
189 call_buffers_.volume_wire_buf.end_sync(sub_pass, res.shapes.camera_volume_wire.get());
196 state.clipping_plane_count);
197 sub_pass.
shader_set(res.shaders->extra_shape.get());
198 call_buffers_.distances_buf.end_sync(sub_pass, res.shapes.camera_distances.get());
199 call_buffers_.frame_buf.end_sync(sub_pass, res.shapes.camera_frame.get());
200 call_buffers_.tria_buf.end_sync(sub_pass, res.shapes.camera_tria.get());
201 call_buffers_.tria_wire_buf.end_sync(sub_pass, res.shapes.camera_tria_wire.get());
202 call_buffers_.sphere_solid_buf.end_sync(sub_pass, res.shapes.sphere_low_detail.get());
209 state.clipping_plane_count);
210 sub_pass.
shader_set(res.shaders->extra_wire.get());
211 call_buffers_.stereo_connect_lines.end_sync(sub_pass);
212 call_buffers_.tracking_path.end_sync(sub_pass);
221 if (!images_enabled_) {
225 manager.generate_commands(background_scene_ps_,
view);
226 manager.generate_commands(foreground_scene_ps_,
view);
227 manager.generate_commands(background_ps_,
view);
228 manager.generate_commands(foreground_ps_,
view);
230 depth_bias_winmat_ = offset_data_.winmat_polygon_offset(
view.winmat(), -1.0f);
235 if (!extras_enabled_ && !motion_tracking_enabled_) {
240 manager.submit(ps_,
view);
245 if (!images_enabled_) {
256 if (!images_enabled_) {
266 if (!images_enabled_) {
275 void object_sync_extras(
const ObjectRef &ob_ref,
280 if (!extras_enabled_) {
285 float4x4 mat = ob->object_to_world();
297 const bool is_active = (ob == camera_object);
298 const bool is_camera_view = (is_active && (rv3d->
persp ==
RV3D_CAMOB));
302 const bool is_stereo3d_display_extra = is_active && is_multiview && (!is_camera_view) &&
304 const bool is_selection_camera_stereo = is_select && is_camera_view && is_multiview &&
309 if (is_selection_camera_stereo) {
332 for (
int i = 0;
i < 4;
i++) {
339 const float2 center = (vecs[0].xy() + vecs[2].
xy()) * 0.5f;
340 const float2 corner = vecs[0].xy() - center.xy();
341 data.corner_x = corner.
x;
342 data.corner_y = corner.
y;
343 data.center_x = center.
x;
344 data.center_y = center.
y;
345 data.depth = vecs[0].z;
347 if (is_camera_view) {
348 if (!
state.is_image_render) {
355 data.center_x += camera_offaxis_shiftx_get(scene, ob,
data.corner_x, is_right);
356 for (
int i : IndexRange(4)) {
358 for (
int j : IndexRange(3)) {
359 data.matrix[
i][j] = mat[
i][j];
364 call_buffers_.frame_buf.append(
data, select_id);
369 if (is_stereo3d_display_extra) {
370 sync_stereoscopy_extra(
data, select_id, scene, v3d, res, ob);
373 call_buffers_.frame_buf.append(
data, select_id);
377 if (!is_camera_view) {
379 float tria_size = 0.7f * drawsize /
fabsf(
data.depth);
380 float tria_margin = 0.1f * drawsize /
fabsf(
data.depth);
381 data.center_x = center.
x;
382 data.center_y = center.
y +
data.corner_y + tria_margin + tria_size;
383 data.corner_x =
data.corner_y = -tria_size;
384 (is_active ? call_buffers_.tria_buf : call_buffers_.tria_wire_buf).append(
data, select_id);
389 data.matrix.x_axis() *= cam.drawsize;
390 data.matrix.y_axis() *= cam.drawsize;
392 data.dist_color_id = (is_active) ? 3 : 2;
394 data.clip_start = cam.clip_start;
395 data.clip_end = cam.clip_end;
396 call_buffers_.distances_buf.append(
data, select_id);
402 data.dist_color_id = (is_active) ? 1 : 0;
406 call_buffers_.distances_buf.append(
data, select_id);
411 void object_sync_motion_paths(
const ObjectRef &ob_ref, Resources &res,
const State &
state)
413 if (!motion_tracking_enabled_) {
417 Object *ob = ob_ref.object;
422 if (clip ==
nullptr) {
426 const float4 &color = res.object_wire_color(ob_ref,
state);
428 const bool is_selection = res.is_selection();
436 float4 bundle_color_custom;
437 float *bundle_color_solid = res.theme.colors.bundle_solid;
438 float *bundle_color_unselected = res.theme.colors.wire;
439 uchar4 text_color_selected, text_color_unselected;
447 const float4x4 object_to_world{ob->object_to_world().ptr()};
455 tracking_object_mat = camera_mat;
463 tracking, tracking_object, framenr, object_mat.
ptr());
465 tracking_object_mat = object_to_world *
math::invert(object_mat);
478 const float *bundle_color;
483 bundle_color_custom[3] = 1.0;
485 bundle_color = bundle_color_custom;
487 else if (is_solid_bundle) {
488 bundle_color = bundle_color_solid;
490 else if (is_selected) {
491 bundle_color = color;
494 bundle_color = bundle_color_unselected;
497 const select::ID track_select_id = res.select_id(ob_ref, track_index++ << 16);
498 if (is_solid_bundle) {
505 call_buffers_.empties);
508 call_buffers_.sphere_solid_buf.append(
518 call_buffers_.empties);
529 is_selected ? text_color_selected : text_color_unselected);
538 if (reconstruction->
camnr) {
541 for (
int a = 0; a < reconstruction->
camnr; a++, camera++) {
555 void object_sync_images(
const ObjectRef &ob_ref,
556 select::ID select_id,
561 Object *ob = ob_ref.object;
565 const bool is_active = ob_ref.object == camera_object;
566 const bool is_camera_view = (is_active && (
state.rv3d->persp ==
RV3D_CAMOB));
571 if (!images_enabled_ || !is_camera_view || !show_image || !show_frame) {
586 bool use_alpha_premult;
587 bool use_view_transform =
false;
591 gpu::Texture *tex = image_camera_background_texture_get(
592 bgpic,
state, res, aspect, use_alpha_premult, use_view_transform);
595 image_camera_background_matrix_get(&cam, bgpic,
state, aspect, mat);
601 const float4 color_premult_alpha{1.0f, 1.0f, 1.0f, std::min(bgpic->alpha, 0.999999f)};
604 (use_view_transform ? foreground_scene_ps_ : foreground_ps_) :
605 (use_view_transform ? background_scene_ps_ : background_ps_);
606 pass.bind_texture(
"img_tx", tex);
607 pass.push_constant(
"img_premultiplied", use_alpha_premult);
608 pass.push_constant(
"img_alpha_blend",
true);
609 pass.push_constant(
"is_camera_background",
true);
610 pass.push_constant(
"depth_set",
true);
611 pass.push_constant(
"ucolor", color_premult_alpha);
612 ResourceHandleRange res_handle = manager.resource_handle(mat);
613 pass.draw(res.shapes.quad_solid.get(), res_handle, select_id.get());
618 static void image_camera_background_matrix_get(
const Camera *cam,
621 const float image_aspect,
629 float cam_corners[4][3];
631 float cam_width =
fabsf(cam_corners[0][0] - cam_corners[3][0]);
632 float cam_height =
fabsf(cam_corners[0][1] - cam_corners[1][1]);
633 float cam_aspect = cam_width / cam_height;
637 if (image_aspect > cam_aspect) {
638 scale[0][0] *= cam_height * image_aspect;
639 scale[1][1] *= cam_height;
642 scale[0][0] *= cam_width;
643 scale[1][1] *= cam_width / image_aspect;
648 if (image_aspect > cam_aspect) {
649 scale[0][0] *= cam_width;
650 scale[1][1] *= cam_width / image_aspect;
653 scale[0][0] *= cam_height * image_aspect;
654 scale[1][1] *= cam_height;
659 scale[0][0] *= cam_width;
660 scale[1][1] *= cam_height;
672 translate[3][1] /=
max_ff(1.0f, cam_aspect) * (image_aspect / cam_aspect);
677 translate[3][0] += (cam_corners[0][0] + cam_corners[2][0]) * 0.5f;
678 translate[3][1] += (cam_corners[0][1] + cam_corners[2][1]) * 0.5f;
683 gpu::Texture *image_camera_background_texture_get(
const CameraBGImage *bgpic,
687 bool &r_use_alpha_premult,
688 bool &r_use_view_transform)
693 gpu::Texture *tex =
nullptr;
694 float aspect_x, aspect_y;
697 r_use_alpha_premult =
false;
698 r_use_view_transform =
false;
702 if (image ==
nullptr) {
718 iuser->scene =
nullptr;
720 if (tex ==
nullptr) {
734 if (
state.scene->camera) {
742 if (clip ==
nullptr) {
748 if (tex ==
nullptr) {
752 aspect_x = clip->
aspx;
753 aspect_y = clip->
aspy;
754 r_use_view_transform =
true;
759 res.bg_movie_clips.append(clip);
768 r_aspect = (width * aspect_x) / (height * aspect_y);
776 void sync_stereoscopy_extra(
const CameraInstanceData &instdata,
777 const select::ID cam_select_id,
783 CameraInstanceData stereodata = instdata;
791 const bool is_selection = res.is_selection();
793 if (!is_stereo3d_cameras) {
795 call_buffers_.frame_buf.append(instdata, cam_select_id);
798 for (
const int eye : IndexRange(2)) {
802 stereodata.corner_x = instdata.corner_x;
803 stereodata.corner_y = instdata.corner_y;
804 stereodata.center_x = instdata.center_x;
805 stereodata.center_y = instdata.center_y;
806 stereodata.depth = instdata.depth;
808 stereodata.center_x += camera_offaxis_shiftx_get(scene, ob, instdata.corner_x, eye);
810 if (is_stereo3d_cameras) {
811 call_buffers_.frame_buf.append(stereodata, cam_select_id);
814 call_buffers_.stereo_connect_lines.append(stereodata.matrix.location(),
815 instdata.object_to_world.location(),
816 res.theme.colors.wire,
820 if (is_stereo3d_volume && !is_selection) {
821 float r = (eye == 1) ? 2.0f : 1.0f;
824 stereodata.volume_end = -cam.
clip_end;
826 stereodata.color_.x = r + 0.15f;
827 stereodata.color_.y = 1.0f;
828 call_buffers_.volume_wire_buf.append(stereodata, cam_select_id);
832 stereodata.color_.x = r + 0.999f;
834 call_buffers_.volume_buf.append(stereodata, cam_select_id);
837 stereodata.color_.x = instdata.color_.x;
838 stereodata.color_.y = instdata.color_.y;
839 stereodata.color_.z = instdata.color_.z;
843 if (is_stereo3d_plane && !is_selection) {
849 stereodata.matrix.z_axis() =
float3(0.0f);
850 stereodata.matrix.location() =
float3(0.0f);
851 for (
int i : IndexRange(2)) {
855 stereodata.matrix.z_axis() += mat.
z_axis();
856 stereodata.matrix.location() += mat.
location() * 0.5f;
858 stereodata.matrix.z_axis() =
math::normalize(stereodata.matrix.z_axis());
859 stereodata.matrix.x_axis() =
math::cross(stereodata.matrix.y_axis(),
860 stereodata.matrix.z_axis());
864 stereodata.matrix.location() =
float3(0.0f);
865 for (
int i : IndexRange(2)) {
868 stereodata.matrix.location() += mat.
location() * 0.5f;
877 stereodata.color_.x = 0.1f;
878 stereodata.color_.y = 1.0f;
879 call_buffers_.volume_wire_buf.append(stereodata, cam_select_id);
883 stereodata.color_.x = 0.0f;
885 call_buffers_.volume_buf.append(stereodata, cam_select_id);
890 static float camera_offaxis_shiftx_get(
const Scene *scene,
899 const float delta_shiftx = shiftx - cam.
shiftx;
900 const float width = corner_x * 2.0f;
901 return delta_shiftx * width;
void DRW_text_cache_add(DRWTextStore *dt, const float co[3], const char *str, const int str_len, short xoffs, short yoffs, short flag, const uchar col[4], const bool shadow, const bool align_center)