sorry, i have a better pic too. but the shader which i am trying to use to figure out some of this is one of yours GG. Basically, what i mean is that one arm or leg will have a completely different lighting, as if a second light source is present. I will give you the code, but as said it was your shader, Great one!, but still want to learn how it is working.
EDIT: oh, and i was going to play and see if i could figure out how to get multiple lights... as you will see...
The Shader:
//
// Green Gandalf's Bumpmapper v1.0g (same as v1.0f but with lightmap)
//
// Created 13 January 2007.
//
// Bumpmapping using a texture and normal map with a single directional light source.
// Includes ambient and specular lighting, alpha transparency, and a lightmap.
// The specular lighting is controlled using the alpha layer of the normal map.
// The alpha transparency is controlled using the alpha layer of the base texture.
//
// Uses half vector approximation for specular reflection plus VS normalisation.
// Uses 2D texture lookup for specular light calculation.
matrix wvp : WorldViewProjection;
matrix mworld : World;
matrix winv: WorldInverse;
float3 eyePos : CameraPosition;
texture baseTexture < string ResourceName = ""; >;
texture normalMap < string ResourceName = ""; >;
texture specularLookup < string ResourceName = ""; >;
texture lightMap < string ResourceName = ""; >; // not implemented yet
sampler2D baseSample = sampler_state
{ texture = <baseTexture>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};
sampler2D normalSample = sampler_state
{ texture = <normalMap>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};
sampler2D specularSample = sampler_state
{ texture = <specularLookup>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = Clamp;
AddressV = Clamp;
};
sampler2D lightMapSample = sampler_state
{ texture = <lightMap>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};
float4 lightDir1 = {-1.0f, 0.0f, 0.0f, 1.0f};
float4 ambiColor1 = {0.2f, 0.2f, 0.2f, 1.0f};
float4 lightColor1 = {1.0f, 1.0f, 1.0f, 1.0f};
float LR_1 = 0.8;
float4 lightDir2 = {-1.0f, 0.0f, 0.0f, 1.0f};
float4 ambiColor2 = {0.2f, 0.2f, 0.2f, 1.0f};
float4 lightColor2 = {1.0f, 1.0f, 1.0f, 1.0f};
float LR_2 = 1.0;
float4 lightDir3 = {-1.0f, 0.0f, 0.0f, 1.0f};
float4 ambiColor3 = {0.2f, 0.2f, 0.2f, 1.0f};
float4 lightColor3 = {1.0f, 1.0f, 1.0f, 1.0f};
float LR_3 = 1.0;
float4 lightDir4 = {-1.0f, 0.0f, 0.0f, 1.0f};
float4 ambiColor4 = {0.2f, 0.2f, 0.2f, 1.0f};
float4 lightColor4 = {1.0f, 1.0f, 1.0f, 1.0f};
float LR_4 = 1.0;
float4 lightDir5 = {-1.0f, 0.0f, 0.0f, 1.0f};
float4 ambiColor5 = {0.2f, 0.2f, 0.2f, 1.0f};
float4 lightColor5 = {1.0f, 1.0f, 1.0f, 1.0f};
float LR_5 = 1.0;
float4 lightDir6 = {-1.0f, 0.0f, 0.0f, 1.0f};
float4 ambiColor6 = {0.2f, 0.2f, 0.2f, 1.0f};
float4 lightColor6 = {1.0f, 1.0f, 1.0f, 1.0f};
float LR_6 = 1.0;
float4 lightDir7 = {-1.0f, 0.0f, 0.0f, 1.0f};
float4 ambiColor7 = {0.2f, 0.2f, 0.2f, 1.0f};
float4 lightColor7 = {1.0f, 1.0f, 1.0f, 1.0f};
float LR_7 = 1.0;
float4 lightDir8 = {-1.0f, 0.0f, 0.0f, 1.0f};
float4 ambiColor8 = {0.2f, 0.2f, 0.2f, 1.0f};
float4 lightColor8 = {1.0f, 1.0f, 1.0f, 1.0f};
float LR_8 = 1.0;
float specPower = 0.2;
struct VS_INPUT
{ float4 Pos : POSITION;
float3 Tangent : TANGENT;
float3 Binormal : BINORMAL;
float3 Normal : NORMAL;
float2 UV : TEXCOORD0;
};
struct VS_OUTPUT
{ float4 Pos : POSITION;
float2 UV : TEXCOORD0;
float3 Light : TEXCOORD1;
float3 Half : TEXCOORD2;
};
VS_OUTPUT GGBumpVShader(VS_INPUT In, VS_OUTPUT Out)
{ Out.Pos = mul(In.Pos, wvp);
Out.UV = In.UV;
float3x3 TSM = {In.Tangent, -In.Binormal, In.Normal};
TSM = transpose(TSM); // tangent space matrix
float3 temp = -mul(lightDir1.xyz,winv);
float3 WP = temp; // world space position
float3 L = lightDir1 - WP;
float Ld = (1/length(L)); // light range
temp = normalize(mul(temp,TSM)) * (Ld*LR_1)-0.2;
Out.Light = temp;
// OUT.Light1 = normalize(LO) * (Ld*LR_1)-0.2 ; normalize our final lv and add range
float3 temp2 = mul(eyePos.xyz,winv) - In.Pos;
temp2 = normalize(mul(temp2,TSM)) * (Ld*LR_1)-0.2;
Out.Half = normalize(temp + temp2);
return Out;
}
struct PS_INPUT
{ float2 UV : TEXCOORD0;
float3 Light : TEXCOORD1;
float3 Half : TEXCOORD2;
};
struct PS_OUTPUT
{ float4 col : COLOR;
};
PS_OUTPUT GGBumpPShader(PS_INPUT In, PS_OUTPUT Out)
{ float4 baseColour = tex2D(baseSample, In.UV);
float4 tempNorm = tex2D(normalSample, In.UV);
float4 otherLights = tex2D(lightMapSample, In.UV);
float3 normal = 2 * tempNorm.xyz - 1;
float3 tempLightDir = In.Light;
float3 tempHalf = In.Half;
float diffuse = saturate(dot(normal, tempLightDir));
float2 coord2d = float2 (saturate(dot(normal, tempHalf)), specPower);
float light = tempNorm.w * tex2D(specularSample,coord2d);
float3 colour = baseColour * (ambiColor1 + otherLights)
+ (baseColour + light) * diffuse * lightColor1;
// float3 colour = baseColour * ambiColor1 + (baseColour ) * diffuse * lightColor1;
Out.col = float4 (colour, baseColour.w);
return Out;
}
technique t0
{ pass p0
{ VertexShader = compile vs_2_0 GGBumpVShader();
PixelShader = compile ps_2_0 GGBumpPShader();
alphablendenable = true;
blendop = add;
srcBlend = srcAlpha;
destBlend = invSrcAlpha;
cullmode =none;
AlphaTestEnable = true; // these May need to be added if other parts are transparent
AlphaFunc = Greater; // which shouldn't be, such as the face and neck.
AlphaRef = 170;
}
}
technique Light2
{ pass p0
{ VertexShader = compile vs_2_0 GGBumpVShader();
PixelShader = compile ps_2_0 GGBumpPShader();
alphablendenable = true;
blendop = add;
srcBlend = srcAlpha;
destBlend = invSrcAlpha;
cullmode =none;
AlphaTestEnable = true; // these May need to be added if other parts are transparent
AlphaFunc = Greater; // which shouldn't be, such as the face and neck.
AlphaRef = 170;
}
}
and in DBP:
Function MakeLights()
LoadEffect( 2 , "Shader/BumpAlpha2.fx" )
null = make vector4(1)
`null = make vector4(2)
make object sphere 9999,1,4,4
set object light 9999,0
make object sphere 9998,1,4,4
set object light 9998,0
`set vector4 1, object position x(9999),object position y(9999),object position z(9999),0.0
`set vector4 2, object position x(9998),object position y(9998),object position z(9998),0.0
`set effect constant vector 1, "lightDir", 1
endfunction
Function PositionLight()
position object 9999,7,0,-0.5
position object 9998,0,10,10
rang1#=0.6
` rang2#=2.0
set effect constant float 1,"LR_1",rang1#
` set effect constant float 2,"LR_2",rang2#
set vector4 1, object position x(9999),object position y(9999),object position z(9999),0.0
`set vector4 2, object position x(9998),object position y(9998),object position z(9998),0.0
`set vector4 1,object position x(9999),object position y(9999),object position z(9999),0
set effect constant vector 1,"LightDir",1
`set effect constant vector 2,"LightDir",2
endfunction
I still do not understand what lots of the commands in your shader mean, but i am learning.
Thanks a ton.