Clone the sources: git clone --recurse-submodules github.com/emeiri/ogldev.git If you want to get the same version that was used in the video you can checkout the tag 'TUT_52_NORMAL_MAPPING'. Build on Windows: Open the Visual Studio solution: ogldev\Windows\ogldev_vs_2022\ogldev_vs_2022.sln Build the project 'OpenGL\Tutorials\Tutorial52_NormalMapping'
@OGLDEV, just for fun Joey de Vries has a hasty function in GLSL's Fragment shader that calculates tangent normals to world space instead of bringing over tangent and bitangent attributes to the Vertex shader by using derivatives. I tried comparing both methods but I couldn't visually tell which was better; Perhaps just a smidge but he did mention this technique was more overhead than the former: vec3 Get_TBN() { vec3 Tangent_Normal = texture(Normal_Map, Texture_Coordinates).xyz * 2.f - 1.f; vec3 WderivX = dFdx(World_Position); vec3 WderivY = dFdy(World_Position); vec2 TderivX = dFdx(Texture_Coordinates); vec2 TderivY = dFdy(Texture_Coordinates); vec3 T = normalize(WderivX * TderivY.t - WderivY * TderivX.t); vec3 N = normalize(Normal); vec3 B = -normalize(cross(N, T)); mat3 TBN = mat3(T, B, N); return normalize(TBN * Tangent_Normal); }
Great video! I implemented this technique in my renderer the other day! I did it with vec4 tangents where the w component was the direction of the bitangent in raport to the cross product between the normal and the first 3 components. It is a bit more computationally expensive but saves some space. One thing I had some trouble with was the fact that the normal texture had to be in the UNORM format. I am adding this just in case other people encounter this issue. Also I am not sure if it is an issue in OpenGL. My renderer uses Vulkan
Clone the sources:
git clone --recurse-submodules github.com/emeiri/ogldev.git
If you want to get the same version that was used in the video you can checkout the tag 'TUT_52_NORMAL_MAPPING'.
Build on Windows:
Open the Visual Studio solution: ogldev\Windows\ogldev_vs_2022\ogldev_vs_2022.sln
Build the project 'OpenGL\Tutorials\Tutorial52_NormalMapping'
Thank you so much.
You're welcome :-)
@OGLDEV, just for fun Joey de Vries has a hasty function in GLSL's Fragment shader that calculates tangent normals to world space instead of bringing over tangent and bitangent attributes to the Vertex shader by using derivatives. I tried comparing both methods but I couldn't visually tell which was better; Perhaps just a smidge but he did mention this technique was more overhead than the former:
vec3 Get_TBN()
{
vec3 Tangent_Normal = texture(Normal_Map, Texture_Coordinates).xyz * 2.f - 1.f;
vec3 WderivX = dFdx(World_Position);
vec3 WderivY = dFdy(World_Position);
vec2 TderivX = dFdx(Texture_Coordinates);
vec2 TderivY = dFdy(Texture_Coordinates);
vec3 T = normalize(WderivX * TderivY.t - WderivY * TderivX.t);
vec3 N = normalize(Normal);
vec3 B = -normalize(cross(N, T));
mat3 TBN = mat3(T, B, N);
return normalize(TBN * Tangent_Normal);
}
Thanks. This is quite advanced. I still haven't used the derivatives in my tutorials.
Amazing explanation !!
Thank you!
Great explanations!
Thanks!
Great video! I implemented this technique in my renderer the other day! I did it with vec4 tangents where the w component was the direction of the bitangent in raport to the cross product between the normal and the first 3 components. It is a bit more computationally expensive but saves some space. One thing I had some trouble with was the fact that the normal texture had to be in the UNORM format. I am adding this just in case other people encounter this issue. Also I am not sure if it is an issue in OpenGL. My renderer uses Vulkan
Thanks! When you sample the normal from the UNORM texture what is the range of the result components?
@@OGLDEV Sorry i completely forgot about the comment. It is [0, 1] so i double it and subtract one to get the actual normal
So it doesn't really matter if you use a UNORM texture, right? Did you get it working eventually?
Ok..good job 👍
Thanks 👍