Suggestions / feedback on the extensions for the gpu module

Sorry for bumping this thread again, but does an official solution exist for the problem of antialiased gaps between adjacent triangles? I get this jarring diagonal when trying to render a rectangle in the viewport:
image

1 Like

(I should probably note that if blending is disabled, there seem to be no gaps, but the rectangle in question is supposed to have transparency in some cases)

1 Like

I faced this problem before can you send the code so I can investigate it again?

Huh, it actually appears that this problem manifests only in certain scenarios (e.g. when drawing 2D gizmos, or when rendering to GPUOffScreen). 3D gizmos (as in the ā€œGizmo Custom Geometryā€ template) do not seem to show any gaps, despite being drawn with alpha-blending and antialiasing. For that matter, POST_PIXEL callbacks do not have this problem either, but they also seem to have antialiasing disabled.

Which means that Blender internally implements mechanisms to control this behavior, but does not expose them to Python scripts, which can be a pretty critical omission in certain cases (especially the lack of control over whether antialiasing is allowed). Hopefully this can be remedied :slightly_smiling_face:

3D gizmo: 2D gizmo: POST_PIXEL:
image image image

Hereā€™s a script to reproduce this behavior for a 2D gizmo:
gizmo_2d_gaps_example.txt (1.6 KB)

1 Like

Ummm, I ran it here and it doesnā€™t reproduce :sweat_smile:

I see :thinking: Perhaps thereā€™s a difference in our hardware? Regardless, it is still very important for python scripts to have as much control over GPU state as Blender itself, since at least it would allow script developers to try to fix/work around such issues on their own. Iā€™ve compared GPU_state.h and gpu.state, and here are the differences I found:

Critical (without control over these, some stuff is plainly impossible to do or fix, like in my case):

  • GPU_line_smooth
  • GPU_polygon_smooth

Important (could be hard to do without in some advanced scenarios):

  • Stencil-related stuff: eGPUStencilTest, eGPUStencilOp, GPU_stencil_test, GPU_stencil_reference_set, GPU_stencil_write_mask_set, GPU_stencil_compare_mask_set, GPU_stencil_mask_get, GPU_stencil_test_get, GPU_write_mask(eGPUWriteMask.GPU_WRITE_STENCIL)

Nice-to-have (provide some convenience/optimization, but their absence is hardly a roadblock):

  • GPU_provoking_vertex
  • GPU_depth_range

Probably too niche to be of much use to scripts (at least without an explanation of how to work with them):

  • eGPUBlend: GPU_BLEND_OIT, GPU_BLEND_BACKGROUND, GPU_BLEND_CUSTOM, GPU_BLEND_ALPHA_UNDER_PREMUL
  • GPU_logic_op_xor_set (just XOR on its own is probably not as useful as a full set of operationsā€¦ or maybe some way to do such calculations in compute shaders)
2 Likes

By the way, a somewhat related question: how hard would it be to make GPUOffScreen.draw_view3d() work on its own, without requiring the bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_PIXEL') context?
Right now, the only way I can make it work for the purposes of on-demand custom 3D view rendering (for generating previews or for obtaining the depth under the mouse) is by abusing the wm.redraw_timer operator ā€“ which, I suspect, is a very suboptimal approach performance-wise, since it renders the entire UI region (or even the whole window), instead of a small rectangle that I actually need (in some cases, just 1 pixel).
An additional downside of having to resort to wm.redraw_timer is that Blender seems to crash if more than one bpy.ops.wm.redraw_timer() is invoked per frame.

1 Like

I think I need the stencil set/test for a pretty simple scenario right now, unless you can suggest an alternative:

Iā€™m drawing a plane in 3D space thatā€™s translucent and fixed in place, along with 3D lines radiating out from the mouse position. I need the line to be culled by depth against geometry in the Blender scene but not the plane. I can change the render order so the line gets drawn before the plane but then the part of the line below the plane gets alpha blended with the plane and changes color when Iā€™d like the line to stay the same color if it has passed through the plane or not. Stencil is the only test I can think of that would let me not blend the plane where the line is.