nmwsharp / polyscope

A C++ & Python viewer for 3D data like meshes and point clouds
https://polyscope.run
MIT License
1.83k stars 203 forks source link

Adding Custom Shader #287

Closed captain-pool closed 3 months ago

captain-pool commented 3 months ago

Hi Nick, Thanks for making such an amazing tool. I am currently trying to add a custom shader for my task (I am trying to visualize a gaussian splat as a collection of ellipsoids, hence I am adding my shader to sphere_shaders.cpp). However, I am having a hard time debugging the shader code that I added. All I am getting is,

[polyscope]  [EXCEPTION] shader compile failed
GLError() after shader compilation! Program text:
.... <my shader source code> ....
....

Can you please share what is the best way to debug the shader code? I am new to OpenGL, hence I am pretty much unaware of any existing debugging best practices. Thanks!

-- Adrish

nmwsharp commented 3 months ago

Hi, sounds like a cool extension!

Unfortunately debugging openGL shaders in plain C++ code is a huge pain, and it's made worse by the fact that Polyscope pre-processes the shader string text internally before compiling them.

If you look just above that text, there should be a printout of the error from the shader compilation process. E.g. here's a snippet, note the ERROR line. The 0:17 tells you that the problem occurs on line 17. This is at least a small hint!

Shader info log:
ERROR: 0:17: Use of undeclared identifier 'u_modelVieww'

[polyscope]  [EXCEPTION] shader compile failed
GLError() after shader compilation! Program text:
   1: 
   2:         
   3: // tag ${ GLSL_VERSION }$
   4: // from rule: GLSL_VERSION
   5: #version 330 core
   6: 
   7: 
   8:         in vec3 a_position;
   9:         uniform mat4 u_modelView;
  10:         
  11:         
  12: // tag ${ VERT_DECLARATIONS }$
captain-pool commented 3 months ago

Thanks for the quick reply! I noticed that, and it was super helpful in atleast making the shader compile now. I am now stuck trying to figure out how to debug runtime errors. One thing that crosses my mind, is to maybe first throw a known compilation error to get the post processed source code of the shader, and then try to use an external shader IDE to debug. Do you happen to know any Local / Web IDE which helps me debug all three shaders (Vertex, Geometry and Fragment)? Most of what I am finding, they don't seem to support support Geometry.

nmwsharp commented 3 months ago

Unfortunately I can't recommend any more powerful debugging tools. They are out there but I have never used them! I always debug these shaders the old fashioned way with trial & error, setting pixel colors to debug, etc. Good luck!

captain-pool commented 3 months ago

Thank You!