Page MenuHome

Add an option to draw volume that represent camera frustum in the viewport
AbandonedPublic

Authored by Ulysse Martin (youle) on Feb 27 2016, 7:03 PM.

Details

Summary

This patch adds an option to draw a volume that represent the camera frustum in the viewport.

It can be used to visualize what is the frustum of a camera, and what objects are in the frustum of this camera.

The UI is in the camera panel, behind show limits.

Video test: https://youtu.be/be-ku3YVgZ8

Test File: http://www.pasteall.org/blend/40883

Diff Detail

Event Timeline

source/blender/editors/space_view3d/drawobject.c
1005

I'd prefer merge these lines in :

glDrawElements(solid ? GL_TRIANGLE_STRIP : GL_LINE_STRIP, 12, GL_UNSIGNED_BYTE, indices);
1204

Why this call ?

Ulysse Martin (youle) updated this revision to Diff 6192.EditedMar 1 2016, 10:18 PM
Ulysse Martin (youle) retitled this revision from Add an option to draw lines that represent camera frustum in the viewport to Add an option to draw volume that represent camera frustum in the viewport.
Ulysse Martin (youle) updated this object.
Ulysse Martin (youle) added a subscriber: Unknown Object (User).

Finally I added transparent faces to draw the frustum. The display is more clear. But we had a discussion with @Daniel Stokes (kupoman) about openGL states. I'd like to have your opinion Mike Erwin if you've got the time: When in draw_cam_persp_frustum (for example) we "restore" openGL states: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_BLEND); glDepthMask(1); glDisable(GL_CULL_FACE); glCullFace(GL_BACK); , how could we be sure that the previous states (before calling draw_cam_persp_frustum) were these states? Is the code openGL safe? As glPush/PopAttrib are deprecated, how can we deal with this? (The code is taken from draw_transp_sun_volume and draw_transp_spot_volume in drawobject.c)

I fixed a ratio issue to make the frustum behave like camera. I update the summary with a video test.

I fixed clipstart value missing when I drawn perspective camera frustum.

EDIT: My frustum seems not right with clipstart.... Thanks Mike Erwin for your review. Finally I have to draw a box too for perpective cam: http://www.pasteall.org/65625/diff to preserve angle of view when I modify clipstart value... I make other checks and I'll update the patch.

The GL state usage looks good to me. It's more important to set the items you mentioned to their default values. Restoring their previous values with glGet is a performance killer! And not needed most of the time.

source/blender/editors/space_view3d/drawobject.c
1223

Suggest rewording to /* restore state to default values */

1228

already set to this value during "draw front side lighting"

1269

Suggest rewording to /* restore state to default values */

1274

already set to this value during "draw front side lighting"

Ulysse Martin (youle) updated this revision to Diff 6196.EditedMar 2 2016, 6:16 PM
Ulysse Martin (youle) updated this object.
Ulysse Martin (youle) edited edge metadata.

I think I've got the right frustum behavior now...

I drawn a box instead of a pyramid for perspective camera (it was needed to preserve angle of view when we modify clipstart value)

I update video test link in the summary.

EDIT: It seems that there are builds issues with my patch on Linux. I'll try to compile it on linux, fix it and update later..........

Fixed compilation error on Linux (replaced "min" with "min_ff")

Updated patch for last Blender sources.

Replaced spaces with tabs in drawobject.c

Not really convinced this is so useful, main question is - does this really help artists placing cameras?

I did a test some years back for a similar feature, http://www.graphicall.org/ftp/ideasman42/camera_lock_clip_feature.ogv - but concluded it was only of limited use too.

Would be good to get feedback for artists on this one.

I'm not convinced about the usefulness of this too finally. So I close the task for the moment, and if users request such a feature, I'll reopen it. Thanks anyway for your reviews and comments.

source/blender/editors/space_view3d/drawobject.c
1204

to activate dotted lines

Oh I've missed this one, I actually ran into needing this several times in the past.

My workaround has been doing clipping-border (Alt+B) from the camera view.

Cases when it's useful:

  • Camera placement, especially when they're dynamic (like on a path, or Fly/Walk mode)
  • Setting up Cycles "Camera Culling" simplify feature
  • Manually removing objects to optimize scenes
  • Basically the same reasons Show Cone is great for lamps, it's a quick glimpse on what's going to be seen, especially when there are objects that come in/out of frame.

@venomgfx: It seems that Campbell Barton made a more advanced and better patch than mine in the past. So I abandon this one but you can discuss with him to see if he could eventually change his mind about his feature :)