Hello,
currently i try to port an bumpmapping shader but i am not able to get a good result. My problem are the 2 lines in the vertex shader (marked in red)where in the original implementation vecLightDir and vecEye is used. I tried to map this to vecSunDir, vecViewDir ... but i always get a result like shown in the pictures above.
The next problem is the roof of the house model. It is tiled into 6 surfaces, pointing to the same area in the texture.
The shader calculates the light impact for each area and not for the whole roof (The lightning is for each surface dark on the upper right side and bright on the lower left side and not for the whole roof). Is there something what can be changed in the shader or is it necessary that the roof is only one surface to get the proper light calculation.
The demo project can be downloaded with
Link to BumpMapping Shader (10 MB).
Any help is appreciated.
Code:
material bumpmapping_version2 {
effect
"
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Define your needed values
float4x4 matWorldViewProj;
float4x4 matWorld;
float4 vecLight;
float4 vecSunDir;
float4 vecViewDir;
float4 vecViewPos;
// Define your textures
texture entSkin1;
texture entSkin2;
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Texture settings
sampler ColorMapSampler = sampler_state
{
Texture = <entSkin1>;
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Clamp;
AddressV = Clamp;
};
sampler BumpMapSampler = sampler_state
{
Texture = <entSkin2>;
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Clamp;
AddressV = Clamp;
};
// Define the output of your vertexshader
struct VS_OUT
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;
float3 Light : TEXCOORD1;
float3 View : TEXCOORD2;
};
struct VS_IN
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD;
float3 Normal : NORMAL;
float3 Tangent : TANGENT;
};
//////////////////////////////////////////////////////////////////////////////////////////////////////
// vertexshader
VS_OUT vs( VS_IN In )
{
VS_OUT Out = ( VS_OUT ) 0; // Declare your output
Out.Pos = mul( In.Pos, matWorldViewProj ); // Transform the ouput to the view
float3x3 worldToTangentSpace;
worldToTangentSpace[0]=mul(In.Tangent, matWorld);
worldToTangentSpace[1]=mul(cross(In.Tangent,In.Normal), matWorld);
worldToTangentSpace[2]=mul(In.Normal, matWorld);
Out.Tex=In.Tex;
float4 PosWorld = mul(In.Pos, matWorld);
Out.Light = mul(worldToTangentSpace, vecLight);
// In the Original Shader: Out.Light = mul(worldToTangentSpace, vecLightDir);
Out.View = mul(worldToTangentSpace, vecViewPos - PosWorld);
// In the Original Shader: Out.View = mul(worldToTangentSpace, vecEye - PosWorld);
return Out;
}
float4 ps(
float2 Tex : TEXCOORD0,
float3 Light: TEXCOORD1,
float3 View : TEXCOORD2
) : COLOR
{
float4 Color = tex2D(ColorMapSampler, Tex);
float3 Normal = (2*(tex2D(BumpMapSampler,Tex)))-1.0;
float3 LightDir = normalize(Light);
float3 ViewDir = normalize(View);
float Diffuse=saturate(dot(Normal,LightDir));
float3 Reflect = normalize(2*Diffuse * Normal - LightDir);
float Specular = pow(saturate(dot(Reflect,ViewDir)),3);
return 0.2 * Color + Color * Diffuse + Specular;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
//
technique mytechnique
{
// Define your passes
pass p0
{
VertexShader = compile vs_2_0 vs();
PixelShader = compile ps_2_0 ps();
}
}
";
}