diff options
Diffstat (limited to 'doc/python_api/examples/gpu.10.py')
-rw-r--r-- | doc/python_api/examples/gpu.10.py | 50 |
1 files changed, 26 insertions, 24 deletions
diff --git a/doc/python_api/examples/gpu.10.py b/doc/python_api/examples/gpu.10.py index 8e354dd09a8..b47ff732e2b 100644 --- a/doc/python_api/examples/gpu.10.py +++ b/doc/python_api/examples/gpu.10.py @@ -14,33 +14,36 @@ from random import random from mathutils import Vector from gpu_extras.batch import batch_for_shader -vertex_shader = ''' - uniform mat4 u_ViewProjectionMatrix; +vert_out = gpu.types.GPUStageInterfaceInfo("my_interface") +vert_out.smooth('FLOAT', "v_ArcLength") - in vec3 position; - in float arcLength; +shader_info = gpu.types.GPUShaderCreateInfo() +shader_info.push_constant('MAT4', "u_ViewProjectionMatrix") +shader_info.push_constant('FLOAT', "u_Scale") +shader_info.vertex_in(0, 'VEC3', "position") +shader_info.vertex_in(1, 'FLOAT', "arcLength") +shader_info.vertex_out(vert_out) +shader_info.fragment_out(0, 'VEC4', "FragColor") - out float v_ArcLength; - - void main() - { - v_ArcLength = arcLength; - gl_Position = u_ViewProjectionMatrix * vec4(position, 1.0f); - } -''' - -fragment_shader = ''' - uniform float u_Scale; +shader_info.vertex_source( + "void main()" + "{" + " v_ArcLength = arcLength;" + " gl_Position = u_ViewProjectionMatrix * vec4(position, 1.0f);" + "}" +) - in float v_ArcLength; - out vec4 FragColor; +shader_info.fragment_source( + "void main()" + "{" + " if (step(sin(v_ArcLength * u_Scale), 0.5) == 1) discard;" + " FragColor = vec4(1.0);" + "}" +) - void main() - { - if (step(sin(v_ArcLength * u_Scale), 0.5) == 1) discard; - FragColor = vec4(1.0); - } -''' +shader = gpu.shader.create_from_info(shader_info) +del vert_out +del shader_info coords = [Vector((random(), random(), random())) * 5 for _ in range(5)] @@ -48,7 +51,6 @@ arc_lengths = [0] for a, b in zip(coords[:-1], coords[1:]): arc_lengths.append(arc_lengths[-1] + (a - b).length) -shader = gpu.types.GPUShader(vertex_shader, fragment_shader) batch = batch_for_shader( shader, 'LINE_STRIP', {"position": coords, "arcLength": arc_lengths}, |