OpenGL: Which shaders for normal map (bump map)?

424 views Asked by At

I could not find a way to generate a normal/bump map in PyOpenGL. Specifically I want a map which I can read with glReadPixels(). I do not know how to get a map of the form: (width, height, normals) i.e. the shape should be (w x h x 3).

How can I get such a map? Which Fragment, vertex, geometry shaders are needed for this?

I provide the following inputs to the Vertex shader:

layout (location = 0) in vec3 vertexPosition_modelspace;
layout (location = 1) in vec3 normal;

uniform mat4 ModelMatrix;
uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;

I would like to get a smooth normal map, where every pixel corresponds to a normalized normal vector. Which shaders do I need for this? What I need to do is to render a normal map from a scene. I use marching cubes to get the triangles, normals and vertices. I added a normal buffer. I do not have texture.

NormalBuffer = glGenBuffers(1)
print(NormalBuffer.shape)
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, NormalBuffer)
glBufferData(GL_ELEMENT_ARRAY_BUFFER, normal_arrays[i], GL_STATIC_DRAW)
normal_buffers[i] = NormalBuffer

I use this to draw the triangles and to bind the buffer object.

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, normal_buffers[i])
glVertexAttribPointer(1,           
                      3,      
                      GL_FLOAT,     
                      GL_FALSE,     
                      0,            
                      None)         

glDrawElements(GL_TRIANGLES,
               index[1]*index[0],
               GL_UNSIGNED_INT,
               None)

Is it possible to render the normal map with the shader and how? Is it possible like this to read it?

glReadPixels(0, 0, height, width, GL_RGB, GL_UNSIGNED_INT)
0

There are 0 answers