SpiderPig Posted May 5, 2017 Share Posted May 5, 2017 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 Quote Link to comment Share on other sites More sharing options...
macklebee Posted May 5, 2017 Share Posted May 5, 2017 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? 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(); ... ... Quote 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 More sharing options...
SpiderPig Posted May 5, 2017 Author Share Posted May 5, 2017 Sorry, I didn't explain it too well. The normal's seem to point towards the center of the world I think it is... in the editor if you move the object around or the camera, the normal's will change direction. I've attached the model also if you wanted to see it. terrain.zip 1 Quote Link to comment Share on other sites More sharing options...
nick.ace Posted May 6, 2017 Share Posted May 6, 2017 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. 1 Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted May 6, 2017 Author Share Posted May 6, 2017 Ah ha! Thanks very much. Knew it was something simple. Thanks for the tips too. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.