Normal maps and specular with reflections

798 views Asked by At

I'm using ogre3d meshy to view a model. I have written a shader that works with normal maps, reflection, specular maps. But normal maps doesn't work as shown in the picture.

The reflection is working as you see, and sepcular maps is working, but I don't need see the normal maps and bump mapping is working though.

I have tried to disable everything and output the result of the normal maps and its textured and sampled correctly, the same for specular, and for the diffuse map.

enter image description here Here is the GLSL VS

/* Environmental Cubic Reflection NormalMapping TetxureMapping Scaling */

#version 120
#define lowp
#define mediump
#define highp

attribute vec4 vertex;
attribute vec3 normal;
attribute vec4 uv0;
attribute vec4 uv1;
attribute vec4 tangent;
//attribute vec3 binormal;

uniform mat4 normalMatrix;
uniform mat4 modelViewProjectionMatrix;
uniform mat4 modelView;
uniform vec3 camera_world_position;
uniform mat4 textureMatrix0;

varying vec2 texCoord[2];
varying vec3 viewWorld;
varying mat3 world2Tangent;


void main()
{       
    gl_Position = modelViewProjectionMatrix * vertex;

    // transform the uv coordinates
    texCoord[0] = (textureMatrix0 * uv0).xy;
    texCoord[1] = uv1.xy;

    //world.
    vec3 vertexWorld = vec3(modelView * vertex);

    //transform world to tangent.
    //world2Tangent = mat3(normalMatrix) * mat3(tangent, binormal, normal);

    // no binormal in ogre?. must reconstruct. Ogre inverts?
    vec3 binormal = cross ( normal, tangent.xyz ) * tangent.www;
    world2Tangent = mat3(normalMatrix) * mat3(tangent.xyz, binormal, normal);

    //Camera Position
    //Use Light0 instead of camera position to match phong specular with environment reflection 
    viewWorld = normalize( - vertexWorld );

} 


#version 120
#define lowp
#define mediump
#define highp

uniform sampler2D diffuseColorMap;
uniform sampler2D ambientOcclusionMap;
uniform sampler2D normalMap;
uniform sampler2D specularMap;
uniform samplerCube envMap;

uniform float diffuseFactor;
uniform float reflectionFactor;
uniform float opacity;

varying vec2 texCoord[2];
varying mat3 world2Tangent;
varying vec3 viewWorld;

void main()
{
    //unpack current normal in tangent space
     vec3 normal = 2.0 * texture2D (normalMap, texCoord[0].st).rgb - 1.0;



    // environment reflection in world space
    vec3 normalWorld = normalize(world2Tangent * normal);
    vec3 refDir = viewWorld - 2.0 * dot(viewWorld,normalWorld) * normalWorld;

    vec4 diffuseColor = texture2D( diffuseColorMap, texCoord[0] );

    //mix ambient material with reflection
    vec4 final = diffuseFactor * ( diffuseColor * texture2D(ambientOcclusionMap, texCoord[0]) ) +
    reflectionFactor * ( textureCube(envMap,refDir) * texture2D(specularMap, texCoord[0]) );
    final.a = diffuseColor.a * opacity;
    gl_FragColor= final;
}
0

There are 0 answers