Reputation: 115
I am drawing a scene by drawing vertices one by one. I use opentk and C#, the draw code looks like this:
GL.EnableClientState(ArrayCap.VertexArray);
GL.EnableClientState(ArrayCap.NormalArray);
GL.VertexPointer(3, VertexPointerType.Float, 0, parameterArray);
GL.Color3(color.R / 255.0, color.G / 255.0, color.B / 255.0);
GL.NormalPointer(NormalPointerType.Float, 0, normalArray);
GL.DrawArrays(PrimitiveType.Triangles, 0, parameterArray!.Length / 3);
GL.DisableClientState(ArrayCap.NormalArray);
GL.DisableClientState(ArrayCap.VertexArray);
But since OpenTK is just another wrapper aroung OpenGL, i don't think the code details matter much.
I do that for all my vertices and then grab the image from the backbuffer with ReadPixels.
This is not for display - I am then running further simulations on the generated pictures.
Now, to expand my simulations, i kind of need the normal vector for each pixel.
What i actually need in the end is the angle between the surface and the camera direction for each pixel of the model.
In my understanding, OpenGL internally will generate normal vectors when lighting (although i currently render without lighting at all), so can i somehow let it generate these?
I have the vague idea of rendering the scene in a 3x higher resolution, then use the Z values to generate normals from each 4x4 block, but that would involve a lot of CPU-heavy vector operations. Can't i use opengl to give me the normal vectors? I have the normals of the vertices of course, but i can't know which vertex is shown in a pixel (at least not without iterating over all vertices for each pixel).
Any tip on how i bring openGL to do it for me?
Aren't normal maps from hi-res models also generated like this (Although they are at some step transformed to tangent space if my understanding is correct, and i need them in object space or ultimately in view space.
Upvotes: 0
Views: 66