Suggestions / feedback on the extensions for the gpu module

Hi, any news to expose these to the Python gpu module? since bgl is being fully deprecated in 3.5 and 2 years passed since this thread started

  • GPU_scissor
  • GPU_line_smooth

Hi,

It seems we only added gpu.state.viewport_set, but not scissor testing. I don’t see an issue adding these as well as both Metal and Vulkan have support for them. Added #104911 - GPU: Add gpu.state.scissor_set/gpu.state.scissor_reset - blender - Blender Projects to track the issue.

For line smoothing we cannot use a global state anymore and it has been replaced with polyline shaders. If you need smooth lines we suggest to use polyline shaders as global state line smooth wasn’t supported by all OpenGL platforms and will not be supported by Metal or Vulkan. For polyline please check builtin shaders.

3 Likes

Thank you so much!!!

Sad that global state for line smoothing is not supported but glad that there is a non-global alternative at shader level :smiley:

[For other addon devs]
Here you have the source code of the POLYLINE builtin shaders which is helpful to build your custom line shaders with smoothing. Check for all gpu_shader_3D_polyline_XXX.glsl files.

Also, in gpu_shader_3D_polyline_info.hh you have the info about constants, uniforms, etc… in order to create your own shader from Python by using gpu.types.GPUShaderCreateInfo and gpu.types.GPUStageInterfaceInfo from the API

6 Likes

Hey there,

Will it be possible to alter the sampler state for gpu textures? It would be awesome to control the filter/wrap mode.

1 Like

Hi there,
In my sound waveform display addon I load a texture and use bgl to filter it (sharp pixel after resize) with the following:

bgl.glTexParameterf(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_NEAREST)
bgl.glTexParameterf(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_NEAREST)

Full code is here: sound_waveform_display/display_wave_image.py at b8e0f79a7cd5bf181d2c1aefbe57c1e5c7da2e88 ¡ Pullusb/sound_waveform_display ¡ GitHub

This addon is used by quite a lot of people now, and I would like to update it to support metal and future Blender version.

I didn’t find how I can do that with new gpu module. I suppose this should be done in shader now ?
But I have no clue on how to do that ^^.

If this is supposed to be done in shader, do you have a good reference on how to manipulate texture with fragment shader within Blender ?
Is there a good place for gpu module example in general out of the official doc ?

2 Likes

Good point @Pullup!

The idea of exposing parameters filter, repeat, use_mipmap, clamp_to_border_color and compare_enabled when linking a texture to a shader has been discussed before (in chat).

It would be like this:

gpu.types.GPUShader.uniform_sampler(name, texture, filter='NEAREST', repeat=[False, False, False], use_mipmap=False, clamp_to_border_color=False, compare_enabled=False)

But there were some open questions in this solution. For example.

  • Would these values be better set when creating the texture?
  • Is it worth it to set default values when creating the texture?
  • Could these values be getters/setters and modified in the texture (eg texture.filter = 'NEAREST')

That’s why it went unresolved :\