OpenGL: Which shaders for normal map (bump map)?
NickName:Ferchar Ask DateTime:2019-09-26T01:38:28

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

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)

Copyright Notice:Content Author:「Ferchar」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/58103849/opengl-which-shaders-for-normal-map-bump-map

More about “OpenGL: Which shaders for normal map (bump map)?” related questions

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

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, normal...

Show Detail

Normal map generation - shaders and FBO

I want to generate a normal map from a heightmap. I know it's a pretty 'overasked question', but I haven't found any good topics about this. The normal map should be about 6-8x larger than the orig...

Show Detail

Bump map sprite casting shadows on itself

I've got a fairly simple implementation of normal map lighting working for 2D sprites in webgl (GLSL shaders) which I was able to adapt & optimize from an example. It uses just one directional ...

Show Detail

How to apply a normal map in OpenGL?

I'm learning to use normal maps (per pixel lighting?) in 2D graphics with OpenGL. New to normal mapping, I managed to wrap my head around the Sobel operator and the generation of normal maps (mostly

Show Detail

How do I combine the bump map normal and the real normal?

I'm trying to create a shader with bump-mapping. I have the real normal of the object, and I have the bump-map sampled normal. What I would like to do is rotate the sampled normal, so that "up" on...

Show Detail

THREEJS - OBJMTLLoader and Bump Map

I'm loading an OBJ with an MTL which references a diffuse map and a bump. The map_Kd (diffuse map) is reading and loading in the renderer, but the map_Bump (bump map) is not. When I log the mater...

Show Detail

Bump-map a sphere with a texture map

We would like to bump-map a sphere with a texture map. However, the surface of the sphere has an area that is 10 times the area of the texture map(area for both in pixels). Describe different ways in

Show Detail

Changing settings of normal map intensity

i currently have an issue with the correct view of my Normal map in three.js. It looks like shown in the attachment. I think it is a problem with the setting of the normal-map intensity. Is there a...

Show Detail

Normal map in *.obj file

In blender i create a normal map, i will export to blender like OBJ (Wawefront) and there is stored in *.mtl file like "map_Bump". map_Bump have always the same bumpsacale. What parramter in MTL f...

Show Detail

OpenGL shaders: uniform variables count incorrect

I want to do bump/normal/parallax mapping but for this purpose I need multitexturing - use 2 textures at a time - one for the color and one for the height map. But this task accomplishment appeared

Show Detail