rnd-team-dev / plotoptix

Data visualisation and ray tracing in Python based on OptiX 7.7 framework.
https://rnd.team/plotoptix
Other
499 stars 26 forks source link

Color the faces directly #20

Open robinenrico opened 3 years ago

robinenrico commented 3 years ago

Thanks again for this really fast ray tracing package.

I was wondering if there is a way to color the faces directly instead of coloring via the vertices. In other words, we can update the color of the mesh by running: rt.update_mesh(c=np.array(n, 3))

However, this requires an array of colors for the vertices, is there a similar approach where c is a color for each face id?

robertsulej commented 3 years ago

Hi,

If you need only a flat shading then you can use the face index buffer and display it with a color palette, like here.

If you need one of the shaded materials, then I would need to add shaders with a slightly modified logic, that takes color from the face index and applies it instead of interpolated colors from vertex indices.

Let me know what is your use case.

robinenrico commented 3 years ago

Thanks for your fast reply! I indeed looked into that particular example.

If I'm correct, this will create a 2D image with a color palette based on the face ids. However, I'm looking into coloring the mesh. This will make sure that the mesh is colored during the 3D rendering.

robertsulej commented 3 years ago

OK. I'll prepare the next release soon. Will try to include there also the modified shading of meshes. Stay tuned ;)

robinenrico commented 3 years ago

Thanks a lot Robert, that would really help! Without trying to rush you, do you have any idea on when you plan the next release?

robertsulej commented 3 years ago

1-2 weeks, I think. :)

robertsulej commented 3 years ago

I have to make a minor release tomorrow, but did not manage to include new shaders. Sorry for delay! I'll push updates for you in the next release, which should be again in 1~2 weeks.

robinenrico commented 3 years ago

Hi Rober, did you already find the time to look into the new shaders?

robertsulej commented 3 years ago

I was working on that code for a while - changes in the shaders and in the Python API are minimal, but... there is a problem in between. Color buffer size now follows the number of the geometry primitives. For meshes, wireframes and curves it is the number of vertices/nodes. A mesh with some fixed number of vertices can have any number of faces - this does not fit the design of the mesh geometry code. I don't think repeating the whole structure with only differently managed color buffer is the best option, so I still need to figure out how to implement this request.

Sorry, it is a bit more than I thought at the beginning!