Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYimingWu <xp8110@outlook.com>2020-06-04 13:57:28 +0300
committerYimingWu <xp8110@outlook.com>2020-06-04 13:57:28 +0300
commitbfbf0bb7f7a0191b65fc724d5dfea225e6293c6b (patch)
tree042f37d28c9e1cf0ce5a0fb4fd4235288f62d36e /doc/python_api/examples/gpu.2.py
parent3b52dfe549f0c2fca7e0cd499b85fb098e9b4da9 (diff)
parent78017916f7c7a8ec8907c9b993214ff8ec3c3557 (diff)
Merge remote-tracking branch 'origin/master' into temp-lanpr-reviewtemp-lanpr-review
# Conflicts: # release/datafiles/locale # release/scripts/addons
Diffstat (limited to 'doc/python_api/examples/gpu.2.py')
-rw-r--r--doc/python_api/examples/gpu.2.py38
1 files changed, 32 insertions, 6 deletions
diff --git a/doc/python_api/examples/gpu.2.py b/doc/python_api/examples/gpu.2.py
index d1e8ac32589..4bee9acebe3 100644
--- a/doc/python_api/examples/gpu.2.py
+++ b/doc/python_api/examples/gpu.2.py
@@ -1,19 +1,45 @@
"""
-3D Lines with Single Color
---------------------------
+Triangle with Custom Shader
+---------------------------
"""
import bpy
import gpu
from gpu_extras.batch import batch_for_shader
-coords = [(1, 1, 1), (-2, 0, 0), (-2, -1, 3), (0, 1, 1)]
-shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
-batch = batch_for_shader(shader, 'LINES', {"pos": coords})
+vertex_shader = '''
+ uniform mat4 viewProjectionMatrix;
+
+ in vec3 position;
+ out vec3 pos;
+
+ void main()
+ {
+ pos = position;
+ gl_Position = viewProjectionMatrix * vec4(position, 1.0f);
+ }
+'''
+
+fragment_shader = '''
+ uniform float brightness;
+
+ in vec3 pos;
+
+ void main()
+ {
+ gl_FragColor = vec4(pos * brightness, 1.0);
+ }
+'''
+
+coords = [(1, 1, 1), (2, 0, 0), (-2, -1, 3)]
+shader = gpu.types.GPUShader(vertex_shader, fragment_shader)
+batch = batch_for_shader(shader, 'TRIS', {"position": coords})
def draw():
shader.bind()
- shader.uniform_float("color", (1, 1, 0, 1))
+ matrix = bpy.context.region_data.perspective_matrix
+ shader.uniform_float("viewProjectionMatrix", matrix)
+ shader.uniform_float("brightness", 0.5)
batch.draw(shader)