# Regarding per-vtx normal in geometry shader

Hi all,
I have successfully calculated the per-triangle normal and it looks pretty bad. Now I am looking on how to calculate per-vtx normals in the geometry shader. Is it even possible? If so how do i get the adjacency in the geometry shader when my vertex shader only has vertex positions and as far as I know the geometry shader has only info of the current triangle. Does anyone know of a method to get per-vertex normals in geometry shader, any link, reference, tutorial is highly appreciated.

Some background would be useful here. Why do you need to compute per vertex normals in the geometry shader? Are you displacing your vertices somehow - how?

I am doing a basic cloth simulation on GPU. On CPU, after each iteration I can iterate over all the triangles and average the normal to get the per-vertex normal. Now I want to do it on the GPU otherwise I would have to transfer vertex postions to CPU to get the new normals. Therefore, I thought I would ask here if there is a way I could get the per-vertex normals in the geometry shader so that I donot have to transfer data to CPU.

Of course that you can do it on the GPU. Just use adjacency to generate index for a vertex buffer produced by the transform feedback (TF). I guess that you are using GL_POINTS primitive for TF. Otherwise, youâ€™ll have to increase number of vertices in the first pass.

Thanks for the response Aleksandar.

Yeah I am using points for TF. How do i use adjacency how do u define it? I have not used adjacency before can u suggest a good reference for this?

References:

ARB_geometry_shader4 Pay attention to figures: Fig.2.X1 - Fig.2.X3

OpenGL SuperBible 5th Ed, Chapter 11 - Advanced Shader Usage, New Primitive Types Introduced by the Geometry Shader, pg. 438-441

OpenGL 4.0 Shading Language Cookbook, pg.206-207

Thanks Aleksandar, I will have a look at these.