I've tried to get your shader working and failed completely.
I then tested your object with one of my shaders (just uses base texture and normal map) and can't see a problem. Perhaps you could enlighten me?
Here's the dba code:
set display mode desktop width(), desktop height(), 32
sync on: sync rate 60: sync
autocam off
position camera 300, 50, -100
point camera 0, 0, -100
global cx#
global cy#
null = make vector4(1)
load object "serous2.x", 1
load image "Serous_Color.dds", 1
load image "Serous_Normal.dds", 2
`load Image "Serous_Specular.dds", 3
`load image "Serous_Emissive.dds", 4
texture object 1, 0, 1 ` base texture
texture object 1, 1, 2 ` normals
`texture object 1, 2, 3 ` specular
`texture object 1, 3, 4 ` emissive
load effect "GGbump04.fx", 1, 0
set effect technique 1, "t1"
set object effect 1, 1
set vector4 1, 0.0, -1.0, 0.0, 1.0
set effect constant vector 1, "lightDir", 1
set vector4 1, 0.0, 0.0, 0.0, 1.0
set effect constant vector 1, "ambiColor", 1
set vector4 1, 1.0, 1.0, 1.0, 1.0
set effect constant vector 1, "lightColor", 1
loop object 1, 100, 1000
set object speed 1, 5
repeat
positionCamera()
sync
until spacekey()
end
function positionCamera()
control camera using arrowkeys 0, 1, 0
cx# = cx# + mousemovey(): cy# = cy# + mousemovex()
rotate camera cx#, cy#, 0
endfunction
and here's the shader:
//
// Green Gandalf's Bumpmapper v1.4
//
// Created 27 June 2006, Modified 2 August 2009.
//
// Bumpmapping using a texture and normal map with a single directional light source
// plus ambient light and specular reflection.
// Uses full normalization in the pixel shader.
//
// Contains two techniques:
// t0 - standard normal mapping suitable for simple objects such as cubes
// t1 - improved normal mapping suitable for objects such as DBPro spheres
// which might contain seams.
//
// Special thanks to Morcilla of MPL3D for some useful corrections.
matrix wvp : WorldViewProjection;
matrix mworld : World;
matrix winv: WorldInverse;
float4 eyePos : CameraPosition;
texture baseTexture < string ResourceName = ""; >;
texture nMapTexture < string ResourceName = ""; >;
sampler baseSample = sampler_state
{ texture = <baseTexture>;
mipFilter = linear;
magFilter = linear;
minFilter = linear;
};
sampler nMapSample = sampler_state
{ texture = <nMapTexture>;
mipFilter = linear;
magFilter = linear;
minFilter = linear;
};
float4 lightDir = {-1.0, 0.0, 0.0, 1.0};
float4 ambiColor = {0.2, 0.2, 0.2, 1.0};
float4 lightColor = {1.0, 1.0, 1.0, 1.0};
float specLevel = 0.5;
float specExpon = 10.0;
struct VSInput
{ float4 pos : position;
float2 UV : texcoord0;
float3 tangent : tangent;
float3 binormal : binormal;
float3 normal : normal;
};
struct VSOutput
{ float4 pos : position;
float2 UV : texcoord0;
float3 light : texcoord1;
float3 view : texcoord2;
};
VSOutput GGBumpVShader0(VSInput In, VSOutput Out)
{ Out.pos = mul(In.pos, wvp);
Out.UV = In.UV;
// normalize everything just in case
float3 n = normalize(In.normal);
float3 t = normalize(In.tangent);
float3 b = normalize(In.binormal);
float3x3 TSM = {t, b, n};
TSM = transpose(TSM);
float3 temp = -mul(lightDir.xyz, winv);
Out.light = mul(temp, TSM);
temp = (mul(eyePos, winv) - In.pos).xyz;
Out.view = mul(temp, TSM);
return Out;
}
VSOutput GGBumpVShader1(VSInput In, VSOutput Out)
{ Out.pos = mul(In.pos, wvp);
Out.UV = In.UV;
// adjust tangents and binormals - GG fix for seams on DBPro spheres
float3 n = normalize(In.normal);
float3 b = normalize(cross(n, In.tangent));
float3 t = normalize(cross(b, n));
float3x3 TSM = {t, b, n};
TSM = transpose(TSM);
float3 temp = -mul(lightDir.xyz, winv);
Out.light = mul(temp, TSM);
temp = (mul(eyePos, winv) - In.pos).xyz;
Out.view = mul(temp, TSM);
return Out;
}
struct PSInput
{ float2 UV : texcoord0;
float3 light : texcoord1;
float3 view : texcoord2;
};
struct PSOutput { float4 col : color; };
PSOutput GGBumpPShader(PSInput In, PSOutput Out)
{ float4 baseColour = tex2D(baseSample, In.UV);
float3 normal = 2 * tex2D(nMapSample, In.UV) - 1.0;
float3 tempLightDir = normalize(In.light);
float3 tempViewDir = normalize(In.view);
float diffuse = saturate(dot(normal, tempLightDir));
float3 reflect = 2 * diffuse * normal - tempLightDir;
float specular = diffuse * specLevel * pow(saturate(dot(reflect, tempViewDir)), specExpon);
Out.col = baseColour * (ambiColor + diffuse * lightColor) + specular * lightColor;
return Out;
}
technique t0
{ pass p0
{ VertexShader = compile vs_2_0 GGBumpVShader0();
PixelShader = compile ps_2_0 GGBumpPShader();
}
}
technique t1
{ pass p0
{ VertexShader = compile vs_2_0 GGBumpVShader1();
PixelShader = compile ps_2_0 GGBumpPShader();
}
}
Screenshot:
Edit Tried to guess what you were trying to do with your shader, so here's some revised code:
Dba file:
set display mode desktop width(), desktop height(), 32
sync on: sync rate 60: sync
autocam off
position camera 120, 50, -50
point camera 0, 50, -50
global cx#
global cy#
cx# = camera angle x()
cy# = camera angle y()
null = make vector4(1)
load object "serous2.x", 1
load image "Serous_Color.dds", 1
load image "Serous_Normal.dds", 2
load Image "Serous_Specular.dds", 3
load image "Serous_Emissive.dds", 4
load image "Serous_Emissive2.dds", 5
texture object 1, 0, 1 ` base texture
texture object 1, 1, 2 ` normals
texture object 1, 2, 3 ` specular
texture object 1, 3, 4 ` emissive eyes
texture object 1, 4, 5 ` emissive arms, etc
load effect "GGbump04es.fx", 1, 0
set effect technique 1, "t1"
set object effect 1, 1
set vector4 1, 0.0, -0.707107, 0.707107, 1.0
set effect constant vector 1, "lightDir", 1
set vector4 1, 0.0, 0.0, 0.0, 1.0
set effect constant vector 1, "ambiColor", 1
set vector4 1, 1.0, 1.0, 1.0, 1.0
set effect constant vector 1, "lightColor", 1
`set object frame 1, 0
loop object 1, 100, 1000
set object speed 1, 5
repeat
positionCamera()
inc angle#, 0.2
set vector4 1, sin(angle#), 0.0, cos(angle#), 1.0
set effect constant vector 1, "lightDir", 1
sync
until spacekey()
end
function positionCamera()
text 20, 20, "cam XZ = "+str$(camera position x(), 2)+" "+str$(camera position z(), 2)
control camera using arrowkeys 0, 1, 0
cx# = cx# + mousemovey(): cy# = cy# + mousemovex()
rotate camera cx#, cy#, 0
endfunction
Shader:
//
// Green Gandalf's Bumpmapper v1.4
//
// Created 27 June 2006, Modified 25 April 2010.
//
// This version adds simple emissive and specular mapping.
// Bumpmapping using a texture and normal map with a single directional light source
// plus ambient light and specular reflection.
// Uses full normalization in the pixel shader.
//
// Contains two techniques:
// t0 - standard normal mapping suitable for simple objects such as cubes
// t1 - improved normal mapping suitable for objects such as DBPro spheres
// which might contain seams.
//
// Special thanks to Morcilla of MPL3D for some useful corrections.
matrix wvp : WorldViewProjection;
matrix mworld : World;
matrix winv: WorldInverse;
float4 eyePos : CameraPosition;
texture baseTexture < string ResourceName = ""; >;
texture nMapTexture < string ResourceName = ""; >;
texture sMapTexture < string ResourceName = ""; >;
texture eMapTexture < string ResourceName = ""; >;
texture eMap2Texture < string ResourceName = ""; >;
sampler baseSample = sampler_state
{ texture = <baseTexture>;
mipFilter = linear;
magFilter = linear;
minFilter = linear;
};
sampler nMapSample = sampler_state
{ texture = <nMapTexture>;
mipFilter = linear;
magFilter = linear;
minFilter = linear;
};
sampler sMapSample = sampler_state
{ texture = <sMapTexture>;
mipFilter = linear;
magFilter = linear;
minFilter = linear;
};
sampler eMapSample = sampler_state
{ texture = <eMapTexture>;
mipFilter = linear;
magFilter = linear;
minFilter = linear;
};
sampler eMap2Sample = sampler_state
{ texture = <eMap2Texture>;
mipFilter = linear;
magFilter = linear;
minFilter = linear;
};
float4 lightDir = {-1.0, 0.0, 0.0, 1.0};
float4 ambiColor = {0.2, 0.2, 0.2, 1.0};
float4 lightColor = {1.0, 1.0, 1.0, 1.0};
//float specLevel = 0.5; // removed - handled using specular map
float specExpon = 10.0;
struct VSInput
{ float4 pos : position;
float2 UV : texcoord0;
float3 tangent : tangent;
float3 binormal : binormal;
float3 normal : normal;
};
struct VSOutput
{ float4 pos : position;
float2 UV : texcoord0;
float3 light : texcoord1;
float3 view : texcoord2;
};
VSOutput GGBumpVShader0(VSInput In, VSOutput Out)
{ Out.pos = mul(In.pos, wvp);
Out.UV = In.UV;
// normalize everything just in case
float3 n = normalize(In.normal);
float3 t = normalize(In.tangent);
float3 b = normalize(In.binormal);
float3x3 TSM = {t, b, n};
TSM = transpose(TSM);
float3 temp = -mul(lightDir.xyz, winv);
Out.light = mul(temp, TSM);
temp = (mul(eyePos, winv) - In.pos).xyz;
Out.view = mul(temp, TSM);
return Out;
}
VSOutput GGBumpVShader1(VSInput In, VSOutput Out)
{ Out.pos = mul(In.pos, wvp);
Out.UV = In.UV;
// adjust tangents and binormals - GG fix for seams on DBPro spheres
float3 n = normalize(In.normal);
float3 b = normalize(cross(n, In.tangent));
float3 t = normalize(cross(b, n));
float3x3 TSM = {t, b, n};
TSM = transpose(TSM);
float3 temp = -mul(lightDir.xyz, winv);
Out.light = mul(temp, TSM);
temp = (mul(eyePos, winv) - In.pos).xyz;
Out.view = mul(temp, TSM);
return Out;
}
struct PSInput
{ float2 UV : texcoord0;
float3 light : texcoord1;
float3 view : texcoord2;
};
struct PSOutput { float4 col : color; };
PSOutput GGBumpPShader(PSInput In, PSOutput Out)
{ float4 baseColour = tex2D(baseSample, In.UV);
float3 normal = 2 * tex2D(nMapSample, In.UV) - 1.0;
float4 specMap = tex2D(sMapSample, In.UV);
float4 emissMap = tex2D(eMapSample, In.UV);
float4 emiss2Map = tex2D(eMap2Sample, In.UV);
float3 tempLightDir = normalize(In.light);
float3 tempViewDir = normalize(In.view);
float diffuse = saturate(dot(normal, tempLightDir));
float3 reflect = 2 * diffuse * normal - tempLightDir;
float4 specular = diffuse * specMap * pow(saturate(dot(reflect, tempViewDir)), specExpon) * specMap.a;
Out.col = baseColour * (ambiColor + diffuse * lightColor) + specular * lightColor + emissMap + emiss2Map * emiss2Map.a;
return Out;
}
technique t0
{ pass p0
{ VertexShader = compile vs_2_0 GGBumpVShader0();
PixelShader = compile ps_2_0 GGBumpPShader();
}
}
technique t1
{ pass p0
{ VertexShader = compile vs_2_0 GGBumpVShader1();
PixelShader = compile ps_2_0 GGBumpPShader();
}
}
New screenshot: