b28 shader module example in docs produces unexpected results #68413

Closed
opened 2019-08-08 16:12:16 +02:00 by Dealga McArdle · 8 comments
Member

System Information
Operating system: NA
Graphics card: NA

Blender Version
Broken: any current 2.80
Worked: several month old versions

Short description of error

run this example as presented in the docs : https://docs.blender.org/api/blender2.8/gpu.html#mesh-with-random-vertex-colors

import bpy
import gpu
import numpy as np
from random import random
from gpu_extras.batch import batch_for_shader

mesh = bpy.context.active_object.data
mesh.calc_loop_triangles()

vertices = np.empty((len(mesh.vertices), 3), 'f')
indices = np.empty((len(mesh.loop_triangles), 3), 'i')

mesh.vertices.foreach_get(
    "co", np.reshape(vertices, len(mesh.vertices) * 3))
mesh.loop_triangles.foreach_get(
    "vertices", np.reshape(indices, len(mesh.loop_triangles) * 3))

vertex_colors = [(random(), random(), random(), 1) for _ in range(len(mesh.vertices))]

shader = gpu.shader.from_builtin('3D_SMOOTH_COLOR')
batch = batch_for_shader(
    shader, 'TRIS',
    {"pos": vertices, "color": vertex_colors},
    indices=indices,
)


def draw():
    batch.draw(shader)


bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_VIEW')

will display a mesh where some faces are not drawn: see

image.png

**System Information** Operating system: NA Graphics card: NA **Blender Version** Broken: any current 2.80 Worked: several month old versions **Short description of error** run this example as presented in the docs : https://docs.blender.org/api/blender2.8/gpu.html#mesh-with-random-vertex-colors ``` import bpy import gpu import numpy as np from random import random from gpu_extras.batch import batch_for_shader mesh = bpy.context.active_object.data mesh.calc_loop_triangles() vertices = np.empty((len(mesh.vertices), 3), 'f') indices = np.empty((len(mesh.loop_triangles), 3), 'i') mesh.vertices.foreach_get( "co", np.reshape(vertices, len(mesh.vertices) * 3)) mesh.loop_triangles.foreach_get( "vertices", np.reshape(indices, len(mesh.loop_triangles) * 3)) vertex_colors = [(random(), random(), random(), 1) for _ in range(len(mesh.vertices))] shader = gpu.shader.from_builtin('3D_SMOOTH_COLOR') batch = batch_for_shader( shader, 'TRIS', {"pos": vertices, "color": vertex_colors}, indices=indices, ) def draw(): batch.draw(shader) bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_VIEW') ``` will display a mesh where some faces are not drawn: see ![image.png](https://archive.blender.org/developer/F7654524/image.png)
Author
Member

Added subscriber: @tetha.z

Added subscriber: @tetha.z
Jacques Lucke was assigned by Dealga McArdle 2019-08-08 16:13:51 +02:00
Author
Member

Added subscriber: @JacquesLucke

Added subscriber: @JacquesLucke
Author
Member

i meant to subscribe @JacquesLucke

i meant to subscribe @JacquesLucke

Added subscriber: @mano-wii

Added subscriber: @mano-wii
Jacques Lucke was unassigned by Germano Cavalcante 2019-08-08 20:31:55 +02:00
Germano Cavalcante self-assigned this 2019-08-08 20:31:55 +02:00

In fact something has changed in the meantime and now you need to enable depth testing before drawing...

bgl.glEnable(bgl.GL_DEPTH_TEST)
In fact something has changed in the meantime and now you need to enable depth testing before drawing... ``` bgl.glEnable(bgl.GL_DEPTH_TEST) ```
Author
Member

thank you @mano-wii !

thank you @mano-wii !
Germano Cavalcante was unassigned by Dalai Felinto 2019-12-23 16:33:21 +01:00

This issue was referenced by blender/blender@2ab5ca81a5

This issue was referenced by blender/blender@2ab5ca81a5379cb99dfc134efffe070d4851d311

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Germano Cavalcante self-assigned this 2020-01-27 14:29:21 +01:00
Sign in to join this conversation.
No Milestone
No project
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-manual#68413
No description provided.