Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created November 12, 2018 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/0dfead525adf8d108038bd37f37b610b to your computer and use it in GitHub Desktop.
Save zeffii/0dfead525adf8d108038bd37f37b610b to your computer and use it in GitHub Desktop.
pie in the sky?
@zeffii
Copy link
Author

zeffii commented Nov 12, 2018

this is pretty nice, for sending one line based object.

batch = batch_for_shader(shader, 'LINES', {"pos" : coords}, indices=indices)

and the examples are superb so far


in sverchok for 2.79 we have a beast of a viewer node that can accept:

  • vertex color
  • vertex size
  • vertex display on/off
  • edge color
  • edge thickness
  • edge display on/off
  • face color
  • face display on/off
  • optional: faux light source/direction that influences face color (this makes it easier to see curvature)
  • optional: face transparency

image

note, by design we limit the vertex color to a single color, and edge color too. Face color too, except when faux light is switched on, but the user can still only pass one color - which is fine for most of our needs.

image

The problem with drawing lines over polygons, without some z-offset, is that it gives ugly representations to lines (z-fighting?). calculation z-offset is something I didn't want to waste python's computation time on. But if we can pack all the needed data and load it off to a faster language, it's worth asking about.

We would love to be able to pass something like "pydata++" to a batch.

{"pydata++":
   {"verts": verts,
   "edges": edges,
   "faces": faces,
   "vert_color": vert_color,
   "edge_color": edge_color,
   "face_color": face_color,
   "face_transparency": face_transparency,
   "vertex_size": vertex_size,
   "edge_thickness": edge_thickness, 
   "light_direction": light_direction,
   "show_verts": show_verts,
   "show_edges": show_edges,
   "show_faces": show_faces,
   "geometry_matrix": geometry_matrix
}
  • preferably faces list can contain ngons, and the batch processing can tesselate it into tris on its own.
  • also sending multiple pydata++ would be neat

@JacquesLucke
Copy link

I don't know how z-fighting issues like this are usually solved but you can certainly compute small offsets like this in the shader itself. This should be as fast as it can be.

Passing points, edges and faces into a single batch is not possible afaik. You need multiple batches to draw individual edges and faces.
Also the show_verts/... property is not really something a batch deals with. Those settings state which batches should be drawn and which not.

Ngons are a bit more difficult, I actually don't know how ngons are tesselated in Blender. Seems to be a fairly complicated topic. While I understand that it would be nice if you could just draw ngons like that, it is a bit unrealistic. However I think there are already utility functions in the api that tesselate a list of ngons. Not sure how fast they are though.. (https://docs.blender.org/api/blender2.8/mathutils.geometry.html#mathutils.geometry.tessellate_polygon)

All in all I'd say that this "pydata++" structure is pretty application specific. It should be relatively easy for you to write a function that takes this dict and draws it.

@zeffii
Copy link
Author

zeffii commented Nov 13, 2018

right :) it is application specific.. thanks for taking the time to think about it.

The current "old" viewer draw code handles all of the above "pydata++". I'll first attempt to chain a few batch.draw()s , and eventually get feature parity. Then look at a custom fragment shader.

Thanks!

@JacquesLucke
Copy link

Due to the amount of features you want to support it might make sense to just start right away with a custom shader. I'm just not sure if you've ever written a custom shader. I hope the examples I wrote help a bit. Otherwise I'm happy to help you here to get that shader working. :)

@zeffii
Copy link
Author

zeffii commented Nov 13, 2018

let me at least try wrapping my brain around the custom shader, that way if I fail miserably i'll learn more from seeing a solution. Heck, even if I do solve it i'll certainly show you for some feedback! .

@zeffii
Copy link
Author

zeffii commented Nov 13, 2018

there is one thing that I would like to see an example of the addon/file by ideasman42 addons / space_view3d_math_vis / draw.py , has a function to draw a matrix using lines and dotted lines, any chance there could be a shader primitive for that? or a corresponding batch chain (or whatever that's called)

@zeffii
Copy link
Author

zeffii commented Nov 13, 2018

here's sverchok drawing multiple matrices, the color transition is to show the order of the matrices in the list
nortikin/sverchok#1572 (comment)

@JacquesLucke
Copy link

I already rewrote this specific module, but without dotted lines. The problem is that dotted lines are deprecated in modern OpenGL. You have to achieve this effect yourself somehow using a custom shader. It's unlikely that Blender will provide a built-in shader for that...
I've never created a dotted line in modern OpenGL, so unfortunately I can't tell you what's the best way to do it.

That is an interesting way to show the order of matrices in a lot. Did not have this idea when I implemented the Viewer in Animation Nodes. :D

@zeffii
Copy link
Author

zeffii commented Nov 13, 2018

OK! cool. i can handle doing dashed lines programmatically. For now i'll have a look at how you did that module, got a link handy? else i'll find it.

@zeffii
Copy link
Author

zeffii commented Nov 13, 2018

nortikin/sverchok#537 (dashed line converter)

@JacquesLucke
Copy link

Here is the commit where I updated this module: https://developer.blender.org/rBAf80599f36929782af1289fdf0e88f339c8a546ab

That's a cool node too. But I would not recommend you to convert lines to dashed lines in python for performance reasons (for drawing).

@JacquesLucke
Copy link

Usually it would be nice to use instancing when drawing multiple objects with the same geometry but unfortunately I don't know how that works yet. And I think the it will not be supported natively by the gpu api for now.

@zeffii
Copy link
Author

zeffii commented Nov 13, 2018

But I would not recommend you to convert lines to dashed lines in python

i'd do it in numpy if there's a massive issue. I don't need the dotted/dashed line to be high resolution... it's aesthetic anyway, so like you i might just drop that.

anyway. Thanks for this! I don't want to take up more of your time

@zeffii
Copy link
Author

zeffii commented Nov 13, 2018

drawing multiple objects with the same geometry

and passing it different matrices , yeah that would be awesome

@JacquesLucke
Copy link

You really don't. I'm working on the gpu module documentation right now here in the Blender Institute. So any feedback is welcome. (and you give feedback even if you don't notice ;D)

Also I'm trying these kinds of things myself atm to understand how everything works and to make more examples for others to learn from. (my knowledge about OpenGL is also relatively limited still)

@zeffii
Copy link
Author

zeffii commented Nov 13, 2018

the dashed / dotted line is useful for CAD / drafting "line styles", to indicate an axis or other relationship (usually a construction line that's never intended to become real geoemtry).

@zeffii
Copy link
Author

zeffii commented Nov 13, 2018

you may know that, but just in case others are reading :) the fact they where included in old openGL is telling of its origins

@JacquesLucke
Copy link

ok interesting, no I did not know that. But for me it makes total sense that they have been deprecated. Sometimes it's annoying to do these things yourself but in the end you're happy because you have much more possibilities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment