Jump to content

Vertex Normal Shader


SpiderPig
 Share

Recommended Posts

I've put together a quick shader that will show the object in wire-frame and draw lines to show the direction of each vertex normal. But the normal's don't seem to be acting correctly. Is somehow able to show me what I'm doing wrong? I have a feeling it something to do with the cameraprojection matrix, but unsure how to fix it.

 

I used the info from this site; http://www.geeks3d.com/20130905/exploring-glsl-normal-visualizer-with-geometry-shaders-shader-library/

diffuse_shownormals.zip

Link to comment
Share on other sites

Seems to work ok for me - maybe I am not seeing the issue you are referring to? Other than the warning about 'ex_texcoords0' and 'ex_normal' might be used prior to initializing, I am not seeing a problem. Do you have a particular item where the normals seem wrong?

post-14-0-26349700-1493988412_thumb.jpg

 

To get rid of the warning, just initialize the variables prior to the for loop:

void main() {

ex_texcoords0 = vec2(0);

ex_normal = vec3(0);

for(int i = 0; i < gl_in.length(); i++) {

gl_Position = gl_in.gl_Position;

ex_color = g_ex_color;

ex_texcoords0 = g_ex_texcoords0;

ex_normal = g_ex_normal;

EmitVertex();

}

EndPrimitive();

...

...

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

There's an error in the geometry shader where you define N. You should make the last component 0.0 instead of 1.0 because you mess up the homogeneous component (which causes the projection to be off). I didn't have any issues with moving the camera around, just the mesh, but changing the homogeneous coordinate fixes that.

 

Just FYI, you should be careful with outputting more primitives than you import. GPUs have internal buffers to store geometry shader results, but these tend to fill up pretty easily especially with higher primitive outputs (hence why tessellation shaders became a thing). So you may experience performance issues.

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...