mne-tools / mne-gsoc2018-3d

Sandbox for GSoC 2018 3D Viz
BSD 3-Clause "New" or "Revised" License
9 stars 4 forks source link

Fix/enable surface normals #14

Open OlehKSS opened 6 years ago

OlehKSS commented 6 years ago

Surface normals should fix/smooth out the appearance of individual triangles.

An example of a OpenGL-ES2 compatible Phong shading (at least I think it works properly):

https://github.com/vispy/vispy/blob/master/vispy/visuals/mesh.py#L21

Surface normals calculation will be added with pull request #31, ipyvolume support for the smooth shading should be added later.

OlehKSS commented 6 years ago

@larsoner I have added this issue according to your comment in the pull request. I have been studying the PySurfer code and I am not sure I understand correctly how surface normals are used in PySurfer. Have you implied vertex normals that are used for shading corrections, so the surface does not look triangulated (flat vs smooth shading)?

OlehKSS commented 6 years ago

By the way, inflated surface does not seem as much triangulated as pial surface.

larsoner commented 6 years ago

Yes vertex normals are used for smooth shading. There should be a way to enable it for the WebGL meshes. To compute the vertex normals (surf['nn'])we have complete_surface_info in MNE:

https://github.com/mne-tools/mne-python/blob/master/mne/surface.py#L291

OlehKSS commented 6 years ago

I am not sure whether simple enabling in WebGL will help, since ipyvolume uses custom vertex and surface shaders for implementing its plot_mesh/plot_trisurf functions.

larsoner commented 6 years ago

ipyvolume uses custom vertex and surface shaders for implementing its plot_mesh/plot_trisurf functions.

If it uses smooth shading / lighting, it should already make use of the vertex normals (IIUC it is standard to do so)

OlehKSS commented 6 years ago

This is the source code for the shaders I was talking about:

I am not sure whether this is exactly vertex normal implementation, what do you think? I would need ask in ipyvolume chat or smth.

larsoner commented 6 years ago

I would ask the ipyvolume folks

OlehKSS commented 6 years ago

According to ipyvolume folks they use flat shading.

larsoner commented 6 years ago

You could ask about the possibility of using smooth shading. It's worth a PR to ipyvolume if it's not too much work

OlehKSS commented 6 years ago

Yes, it will be possible to add smooth shading to ipyvolume.