Hello,
I am working on rendering volumic meshes composed of exclusively hexahedrons (deformed cubes).
Some of them in the range of 30k elements. I need to be able to represent them individually for a clipping effect and color the hexes depending on cell property like so:
I need some advice please.
I am a bit …let’s be nice and go with bad… with shaders. I’ve been coasting along with basic materials because they suited my needs and I was focusing on my topology library more than the rendering. Up to now I was creating one mesh per hexahedron and could deal with the fact my code would crash most computers. But these ideal times are over… I need to be able to share my work without crashing people’s browsers…
As shown in the example https://threejs.org/examples/?q=instan#webgl_instancing_performance I probably really need to move to instancing.
My game plan is the following, please tell me if it’s “not good” (be gentle):
I was thinking of creating one instanced geometry of a cube (the connectivity is the same as for hexahedrons), creating as many instances are there are hexes in my mesh (duh) with an offset attribute to the center of each hex.
For each instance also giving the list of the 8 vertex positions of the corresponding hex and then using gl_VertexID in the vertex shader to get the proper position. (Should I maybe add 8 different attributes for the positions and an integer vertex attribute as ID? If I should use an array: how please? I haven’t found an example and have 0 experience with RawShaderMaterial or instancing).
That way I could have a float instance attribute for scale, and a vec3 instance attribute for color for my requirements.
dank je for reading that far in the rantings of a sleep deprived individual, and thanks in advance for any tips or tricks.