Jump to content

  • Log In with Google      Sign In   
  • Create Account

Rendering Normals (For Debugging) using the Geometry Shader


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 BenS1   Members   -  Reputation: 334

Like
0Likes
Like

Posted 22 November 2012 - 03:19 PM

Hi,

I've got an annoying lighting problem with my terrain engine and I'm not sure if the problem is with my calculation of the terrain surface normals or something else.

I've tried single stepping through the HLSL code but personally I find it a little difficult to visualize vectors when they are just presented as numbers, so I'd much rather actually see the vectors (Normals in this case).

I guess it should be quite trivial to create a Geometry shader that renders the normals... but rather than reinvent the wheel I thought I'd just check to see if anyone has such a shader that I could use? (HLSL SM 5 compatible)

I've tried a quick search but all I've found are OpenGL versions and no HLSL versions.

Anyway, if anyone has such a shader then great. If not then I'll write my own and share it on here for anyone else that may want to use it in future.

Thanks
Ben

Sponsor:

#2 Tordin   Members   -  Reputation: 604

Like
1Likes
Like

Posted 23 November 2012 - 03:27 AM

have you tired render the value as a color? it´s more easy to think of when you got colors. Or atleast i belive so.

Edited by Tordin, 23 November 2012 - 03:46 AM.

"There will be major features. none to be thought of yet"

#3 Nik02   Crossbones+   -  Reputation: 2830

Like
1Likes
Like

Posted 23 November 2012 - 03:46 AM

I haven't seen a ready-made one, but the logic is indeed trivial. You just output a line (of uniform length) that starts from the vertex position and points to the direction of the normal.

While at it, you can also draw tangent and bitangent lines as well in the same shader. If you do, be sure to output meaningful colors to go with the lines.

If you want to visualize the face normals instead of vertex normals, just average the vertex normals for the current triangle (and take the centroid or average of the positions to find the "center" of the triangle) and normalize the result before streaming it out from the GS.

Tordin's suggestion is also good. Red would represent the range of -1...+1 in the x direction, green in the y... and you get the idea.

Edited by Nik02, 23 November 2012 - 03:52 AM.

Niko Suni


#4 BenS1   Members   -  Reputation: 334

Like
1Likes
Like

Posted 23 November 2012 - 07:49 AM

Thanks both,

Yes I'll try the colour idea first, although it'll still be a little difficult to visualize that a triangle of a certain colour represents a normal is a certain direction, but it could still be very useful.

I'll go on to implementing the geometry shader version second and I'll post the code on here for anyone that wants it.

Thanks
Ben

#5 BenS1   Members   -  Reputation: 334

Like
0Likes
Like

Posted 23 November 2012 - 07:56 AM

Interesting... it took less than 30 seconds to implement the rendering of normals as a colour idea and it indeed shows that there's something "not normal with my normals!" :)

I must have a problem with my Sobel filter somewhere

Off to the debugger...

#6 Nik02   Crossbones+   -  Reputation: 2830

Like
0Likes
Like

Posted 23 November 2012 - 08:03 AM

Colors can show discontinuities very effectively, whereas with lines it could actually be more difficult.

Niko Suni


#7 BenS1   Members   -  Reputation: 334

Like
0Likes
Like

Posted 23 November 2012 - 10:04 AM

Sure Nik02, I agree its great for some stuff, but it wouldn't be obvious for example if all my Normals were pointing in the opposite direction.

As it happens, in this case the colours did show quite clearly that something was not right, so I removed my Sobel filter based Normal calculator and replaced it with a simple Normal calculator (i.e. takes 3 points on the terrain, creates 2 vectors and then the Cross of those 2 vectors). All works perfectly now.

At some point I'll revisit the Sobel filter, but for thsi project I don't think I need it anyway.

Big thanks to your help... this lighting problem had been driving me crazy for days.

Thanks
Ben




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS