Can I draw lines representing normal vectors from fragment shader?

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.

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.

[QUOTE=GClements;1287077]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.[/QUOTE]

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.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.