Page MenuHome

DWM: Limit background image drawing to camera view (Store in the camera).

Authored by Campbell Barton (campbellbarton) on Sep 7 2017, 10:26 AM.



Move reference images from view3d to camera

This is an initial patch, part of the proposal to use background images only for camera view: T52668

The reason to post a WIP patch is to check if the approach is generally OK, before spending time to finish it off.

  • Remove 3D view background images (and panel from viewport).
  • Add Camera background images (and panel to camera properties).
  • Test code to call this from draw-manager.
  • Add 'scale' variable (previously this wasn't possible, we can offset and rotate already, scale seems reasonable. less hassles to add now than later).


  • Current patch changes view3d functions to use camera's in-place (to make the diff less noisy, the functions should be moved for the final patch).
  • Draw manager uses extern to call into legacy viewport code. The function should be moved to a more general location.
  • Draw manager use currently draws images on-top, even when the option to draw behind is used (needs investigation).

Diff Detail

rB Blender
Build Status
Buildable 805
Build 805: arc lint + arc unit

Event Timeline


Moved from 3D view with only very minor changes.


This could be made less vague - check buttons context for eg.


Should rename, kept similar to existing name for convenience.


This should move to rna_camera.c

Campbell Barton (campbellbarton) retitled this revision from DWM: draw background image in camera view to DWM: Limit background image drawing to camera view (Store in the camera)..Sep 7 2017, 10:58 AM
Campbell Barton (campbellbarton) edited the summary of this revision. (Show Details)

This could be made into a function, wm_draw.c shouldn't need to include details about camera/object logic.

@Campbell Barton (campbellbarton) Hope you don't mind if I take a look at it :), as I'm already somewhat familiar with this from D2824

  • Currently breaks "Set as background" in clip editor
  • This is probably a topic for a separate patch, but this inherits the problem of having to manually twiddle around with the offset/scale/rot values. Maybe we could add a modal operator to move images in the viewport, though I'm not sure how much work that would be? OTOH, people are likely going to stick with the defaults here anyway, so perhaps it's not worth the effort.

The reason the images are always appearing on top is that Eevee does all its drawing in the background stage (Clay doesn't), probably for easier post-processing. That's also why in my patch, I was using the Z-Buffer to ensure images always stay in the background, even though I didn't particularly like that solution either.
The grid is drawn in the object mode engine and doing camera references there would ensure the grid stays above background images(Grid doesn't write into the depth buffer, only checks).
Alternatively, we could keep this code in the draw manager, but do the same depth buffer trick and allow the grid to write into the depth buffer, not sure if this would have any consequences.
We could also move the grid back into the draw manager (there is a dead function which doesn't get called anymore and should probably be #if 0'ed out/removed to avoid confusion).
However, it would probably be nicer to have the draw manager only act as a glue between all the engines. Also, we could more easily avoid having to reupload GL textures all the time (once we have proper checking for dirty caches). Plus, all the code for image empties and camera references would be in the same place.


This currently fails for "OpenGL render active viewport", where do_camera_frameshould(argument) should be false (though you might already be aware of this anyway).
Same for other call to this function.

Not sure how reliable this would be:

view3d_draw_bgpic_test(scene, ar, v3d, false, !DST.draw_ctx.evil_C)

Problem from old code, but should be image_aspect[1] = clip->aspy / clip->; or simply BKE_movieclip_get_aspect(clip, &image_aspect[0], &image_aspect[1]).

@Marcelo Mutzbauer (1xundoredo) - thanks for the hints, especially insights into eevee/clay engines.

My first goal was to get the DNA/UI changes into Blender, then focus on details, perhaps it would be best if this patch doesn't even touch the draw manager to begin with.

To your point about twiddling values, agree its annoying although typically this is something you setup once and leave.

Even so, we can have a manipulator for the camera background images quite easily in 2.8x..

I'll look into your other comments too, but first like to see if others approve of moving background to cameras.