I'm getting some pretty freaky results from my tangent space normal mapping shader :). In the scene I show here, the teapot and checkered walls are being shaded with my ordinary Phong-Blinn shader (obviously teapot backface cull gives it a lightly ephemeral look and feel :-) ). I've tried to add in normal mapping to the sphere, with psychedelic results:

Incorrect Normal Mapping on Sphere

The light is coming from the right (just about visible as a black blob). The normal map I'm using on the sphere looks like this:

Normal Map

I'm using AssImp to process input models, so it's calculating tangent and bi-normals for each vertex automatically for me.

The pixel and vertex shaders are below. I'm not too sure what's going wrong, but it wouldn't surprise me if the tangent basis matrix is somehow wrong. I assume I have to compute things into eye space and then transform the eye and light vectors into tangent space and that this is the correct way to go about it. Note that the light position comes into the shader already in view space.

// Vertex Shader
#version 420

// Uniform Buffer Structures

// Camera.
layout (std140) uniform Camera
{
    mat4 Camera_Projection; 
    mat4 Camera_View;
};

// Matrices per model.
layout (std140) uniform Model
{
    mat4 Model_ViewModelSpace;
    mat4 Model_ViewModelSpaceInverseTranspose;
};

// Spotlight.
layout (std140) uniform OmniLight
{
    float Light_Intensity;

    vec3 Light_Position;            // Already in view space.
    vec4 Light_Ambient_Colour;
    vec4 Light_Diffuse_Colour;
    vec4 Light_Specular_Colour;
};

// Streams (per vertex)
layout(location = 0) in vec3 attrib_Position;
layout(location = 1) in vec3 attrib_Normal;
layout(location = 2) in vec3 attrib_Tangent;
layout(location = 3) in vec3 attrib_BiNormal;
layout(location = 4) in vec2 attrib_Texture;

// Ou
Edit
Report