Original Post
Well, after i've searched for documents on the web for different illumination models, i tried to implement diffuse lighting in my terrain viewer, but the result is very ... you can see for yourself:
the terrain consists of 256 Patches, wich you can clearly see at the "shadowed" side of the terrain. i don't know what is wrong here. i'll simpli post the code for the shader: i think the code is right, but i don't know why there are clearly visible edges.
float4x4 matWorldViewProjection;
float4x4 matRotation;
texture SkinTexture;
float4 WireFrameColor;
float4 vecLightDir = {0.0, 1.0, 1.0, 1.0};
float4 ambient = {0.05, 0.0, 0.0, 1.0};
struct VS_OUTPUT
{
float4 Pos : POSITION;
float2 Tex0 : TEXCOORD0;
float2 Tex1 : TEXCOORD1;
float4 Hemi : Color0;
};
VS_OUTPUT VS(float4 Pos: POSITION, float3 Normal: NORMAL, float2 Tex0 : TEXCOORD0, float2 Tex1 : TEXCOORD1)
{
VS_OUTPUT Out = (VS_OUTPUT) 0;
Out.Pos = mul(Pos, matWorldViewProjection);
Out.Tex0 = Tex0;
Out.Tex1 = Tex1;
Out.Hemi = saturate(dot(vecLightDir, normalize(mul(Normal, matRotation))));
return Out;
}
sampler SkinSampler = sampler_state
{
texture = (SkinTexture);
MIPFILTER = LINEAR;
MINFILTER = LINEAR;
MAGFILTER = LINEAR;
};
float4 PS(float2 Tex0 : TEXCOORD0, float4 Hemi : Color0) : COLOR
{
return ambient + tex2D(SkinSampler, Tex0) * Hemi;
//return tex2D(SkinSampler, Tex0);
}
technique DiffuseLighting
{
pass P1
{
CullMode = CCW;
VertexShader = compile vs_1_1 VS();
PixelShader = compile ps_1_1 PS();
}
}
