Your first solution is okay, although you're computing one normal per primitive and you should compute one normal per every vertex.
So you should compute your normal inside the for loop, not outside it.
I'm not sure if you can write it like this (also with this solution you need to make sure that your model contains JUST triangles and no other primitive), as I still don't have too much experiences with geometry shaders (but I'm learning them :P).
#version 120#extension GL_EXT_geometry_shader4 : enablevarying vec3 eyeSpaceNormal;void main( void ){ eyeSpaceNormal = gl_NormalMatrix * normalize(cross(gl_PositionIn[1].xyz - gl_PositionIn[0].xyz, gl_PositionIn[2].xyz - gl_PositionIn[0].xyz)); gl_Position = gl_ModelViewProjectionMatrix * gl_PositionIn[0]; EmitVertex(); eyeSpaceNormal = gl_NormalMatrix * normalize(cross(gl_PositionIn[2].xyz - gl_PositionIn[1].xyz, gl_PositionIn[0].xyz - gl_PositionIn[1].xyz)); gl_Position = gl_ModelViewProjectionMatrix * gl_PositionIn[1]; EmitVertex(); eyeSpaceNormal = gl_NormalMatrix * normalize(cross(gl_PositionIn[3].xyz - gl_PositionIn[2].xyz, gl_PositionIn[1].xyz - gl_PositionIn[2].xyz)); gl_Position = gl_ModelViewProjectionMatrix * gl_PositionIn[2]; EmitVertex(); EndPrimitive();}
As I'm not on PC that is able to debug some geometry shaders, I can't test this if it really emits good vertices and distributing eyeSpaceNormal per every vertex and not per primitive.
This MIGHT work, I can't make myself sure if it will work. Just give it a try, it might work.