PDA

View Full Version : Can I draw lines representing normal vectors from fragment shader?



hashbrown
05-13-2017, 11:38 PM
Is there a way I can draw lines from the center of every face of a mesh in the fragment shader? I'm trying to visualize the mesh's normals, but not sure how to.

I've got a normalMatrix uniform and vertexNormal vec3 varying I sent from the vertex shader. I've calculated a normal vector in the fragment shader:


vec3 norm = normalize(vec3(u_nrmMatrix * vec4(v_normals, 0.0)));

Is there a way I can draw a line along that norm vector from the fragment shader? I'm not sure how to accomplish this, any advise is greatly appreciated! Oh and I'm using WebGL, that's using GLSL 1.0 I believe.

GClements
05-14-2017, 01:59 AM
If you want to draw face normals as lines, you're going to need an extra draw call using GL_LINES.

You could generate the vertices for the normals from the triangle vertices using a geometry shader, compute shader, or transform feedback mode, but WebGL doesn't support any of those, so you'll need to generate them in the client code.

hashbrown
05-18-2017, 09:24 PM
If you want to draw face normals as lines, you're going to need an extra draw call using GL_LINES.

You could generate the vertices for the normals from the triangle vertices using a geometry shader, compute shader, or transform feedback mode, but WebGL doesn't support any of those, so you'll need to generate them in the client code.

Thanks GC, I'll definitely use the geometry shader once I write the desktop implementation. For now I generate them client side as you suggested.