I want to draw round POINT
with custom vertex_shader
and fragment shader
.
I defined the draw()
with arguments, but can't write the GLSL
code for that.
import bpy
import gpu
from gpu_extras.batch import batch_for_shader
vertex_shader = '''
uniform mat4 viewProjectionMatrix;
in vec3 pos;
void main()
{
gl_Position = viewProjectionMatrix * vec4(pos, 1.0f);
}
'''
fragment_shader = '''
uniform vec4 color;
out vec4 FragColor;
void main()
{
FragColor = color;
}
'''
def draw(coords:list=[(0.5, 0.5, 0.5)], size:float=12, color:tuple=(1, 0, 0, 1), outline_color:tuple=(1, 1, 1, 1), roundness:float=0.5):
'''
Draw 3D dot with roundness
coords (list) - 3D coordinates of a point.
size (float) - Point size.
color (RGBA) - Color of the point.
outline_color (RGBA) - Outline color of the point.
roundness (float) - Roundness of the point (0 is square and 1 is circle).
'''
shader = gpu.types.GPUShader(vertex_shader, fragment_shader)
batch = batch_for_shader(shader, 'POINTS', {"pos": coords})
gpu.state.blend_set("ALPHA")
gpu.state.point_size_set(size)
shader.bind()
matrix = bpy.context.region_data.perspective_matrix
shader.uniform_float("viewProjectionMatrix", matrix)
shader.uniform_float("color", color)
batch.draw(shader)
bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_VIEW')