Using a normal map (bump map) texture in shader


I’m in the process of trying to apply a bump map via vertex / fragment shader - can’t seem to make much progress, wondering if anyone could point me in the right direction? Specfically stuck on how to compute tangent and binormals and pass to shader.

vec3 nrmMap = texture2D(nrmSampler , uv);

vec3 new_normal = mat3(world) * normal * (nrmMap*0.5+0.5);


Cool, got it working - thanks :slight_smile:

Hi, @nasimiasl,
I am looking into similar topics and ran into this post.
Could you please explain mat3(world) * normal * (nrmMap*0.5+0.5); a little?
I am new to glsl and trying to grasp the concept and math behind world-space normal calculations.
Thanks alot!

world : in shader mean ( move and rotate and scale of original mesh )
when you use mat3(world) you just use of rotation of world
in normal map we don’t use scale + movement ( the Unit vector always start of (0,0,0) and have a one unit length )
so mat3( world ) * normal correct normal vector

when we use normal map and read it as texture we have normal vector but all positive side
because texture rgb is always between 1. and 0.
but normal map system not calculate the face normal when we wanna mix normal system we have 2 option

mix corrected normal with native side
a: normal * (new_normal *2. -1 )

corrected normal with exact image normal
b: normal 0.5 + normalnew_normal*0.5 => normal * (new_normal * 0.5 + 0.5)

both show you normal map in different directions

the main is first one but the b have more normal map in one direction

1 Like

Thanks for your explaination.