Python API: Expose background drawing as argument for gpu.types.GPUOffScreen.draw_view3d() #105748

Merged
Jeroen Bakker merged 3 commits from Yuntoko/blender:expose-draw-background-pyapi into main 2023-04-17 09:28:12 +02:00
Contributor

Currently, when using the python api for offscreen drawing, the default background will always be rendered into the GPUOffScreen's framebuffer, rendering the alpha channel essentially useless and making it difficult to separate objects from the background.

This patch allows offscreen drawing of a 3d view with transparent background by exposing an optional parameter to the python api, enabling, for example, compositing the result over another image.

The new parameter to draw_view3d() is optional, with the default value matching the previous behavior, so this change is fully backwards-compatible.


offscreen.draw_view3d(
        scene,
        context.view_layer,
        context.space_data,
        context.region,
        view_matrix,
        projection_matrix,
        do_color_management=False,
        draw_background=False) # New optional keyword parameter
Currently, when using the python api for offscreen drawing, the default background will always be rendered into the GPUOffScreen's framebuffer, rendering the alpha channel essentially useless and making it difficult to separate objects from the background. This patch allows offscreen drawing of a 3d view with transparent background by exposing an optional parameter to the python api, enabling, for example, compositing the result over another image. The new parameter to draw_view3d() is optional, with the default value matching the previous behavior, so this change is fully backwards-compatible. ----- ``` offscreen.draw_view3d( scene, context.view_layer, context.space_data, context.region, view_matrix, projection_matrix, do_color_management=False, draw_background=False) # New optional keyword parameter ```
Yuntoko added 1 commit 2023-03-14 01:00:23 +01:00
buildbot/vexp-code-patch-coordinator Build done. Details
d1438add40
Python API: Expose background drawing as argument for gpu.types.GPUOffScreen.draw_view3d()
Currently, when using the python api for offscreen drawing, the default background will always be rendered into the GPUOffScreen's framebuffer, rendering the alpha channel essentially useless and making it difficult to separate objects from the background.

This patch allows offscreen drawing of a 3d view with transparent background by exposing an optional parameter to the python api, enabling, for example, compositing the result over another image.

The new parameter to draw_view3d() is optional, with the default value matching the previous behavior, so this change is fully backwards-compatible.
Brecht Van Lommel requested review from Jeroen Bakker 2023-04-05 18:09:41 +02:00
Brecht Van Lommel requested review from Germano Cavalcante 2023-04-05 18:09:41 +02:00

This function is old, I'm not familiar with the draw_background parameter.
If enabled, does it reuse the current offscreen color slot?
If that's the case, I think the parameter name could be "clear_color=True".

But I'm still not sure of the motivation for this change. Isn't it better to avoid adding more parameters to draw_view3d in order to simplify the API? Why not simply redraw the result with alpha over an background texture?

This function is old, I'm not familiar with the draw_background parameter. If enabled, does it reuse the current offscreen color slot? If that's the case, I think the parameter name could be "clear_color=True". But I'm still not sure of the motivation for this change. Isn't it better to avoid adding more parameters to `draw_view3d` in order to simplify the API? Why not simply redraw the result with alpha over an background texture?
Member

the draw_view3d is a legacy function. And when the background is drawn the transparency data isn't available to do the compositing. The background actually is drawn with an alpha under replacing all alpha values.

Yes we should make a new API for offscreen rendering that would be more configurable currently it isn't clear how this will look like. The new API would also consider overlays etc. I am fine to add this optional parameter for now.

Usecase is same as for other cases where draw_view3d is used, mostly for automation in pipelines where speed is desired or where compositing isn't executed in Blender.

the draw_view3d is a legacy function. And when the background is drawn the transparency data isn't available to do the compositing. The background actually is drawn with an alpha under replacing all alpha values. Yes we should make a new API for offscreen rendering that would be more configurable currently it isn't clear how this will look like. The new API would also consider overlays etc. I am fine to add this optional parameter for now. Usecase is same as for other cases where draw_view3d is used, mostly for automation in pipelines where speed is desired or where compositing isn't executed in Blender.
Germano Cavalcante approved these changes 2023-04-06 15:22:31 +02:00
@ -304,2 +304,3 @@
" :arg do_color_management: Color manage the output.\n"
" :type do_color_management: bool\n");
" :type do_color_management: bool\n"
" :arg draw_background: Draw background.\n"

This description is not adding much.

This description is not adding much.
Jeroen Bakker added 1 commit 2023-04-14 16:31:30 +02:00
Jeroen Bakker added 1 commit 2023-04-17 09:04:10 +02:00
buildbot/vexp-code-patch-coordinator Build done. Details
92e2472edb
Merge branch 'main' into expose-draw-background-pyapi
Member

@blender-bot build

@blender-bot build
Jeroen Bakker approved these changes 2023-04-17 09:26:24 +02:00
Jeroen Bakker added this to the 3.6 LTS milestone 2023-04-17 09:26:38 +02:00
Jeroen Bakker merged commit 3a02d760f7 into main 2023-04-17 09:28:12 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#105748
No description provided.