Hi,
meine alten verhassten Shader mal wieder... ich will gar nicht wissen wie man mich für diese frage verkloppen wird
Also ich wollte neulich mal den Normalmapping-Shader aus dem Shader Tutorial auf 8 Lichter umschreiben, 8 Lichter sind jetzt mehr oder weniger gut untergebracht. NUR die Beleuchtungsrichtung passt nicht richtig das ganze sieht so auf dem modell(nur der Kopf das andere zeug benutzt einen anderen Normal-Mappingshader, der auf dem Kopf nicht gut aussieht) aus:

ja die hachfresse ist beabsichtigt grin
so berechne ich die richtungen(im vertex shader) blush
Code:
OutLightDir0 = normalize(mul(matTangent, vecLightPos[0]-InPos.xyz));


und so wende ich sie im(pixel shader)
Code:
Diffuse[0] = DiffuseIntensity * saturate(dot(InLightDir0, BumpNormal));
	Diffuse[0] *= vecLightColor[0];
	R = normalize(2 * dot(BumpNormal, InLightDir0) * BumpNormal - InLightDir0);
	InViewDir = normalize(InViewDir);
	Specular[0] = pow(saturate(dot(R, InViewDir)), SpecularPower) * SpecularIntensity;
...
...
...
	float4 Color = tex2D(ColorMapSampler, InTex);
	
	return (Ambient + Diffuse[0] + Specular[0]) * Color;



wer sich jetzt fragt was wie zusammen hängt hier der ganze shader:
Code:
static const float AmbientIntensity	= 1.0f;
static const float DiffuseIntensity = 1.0f;
static const float SpecularIntensity = 1.0f;
static const float SpecularPower = 9.0f;
float4x4 matWorldViewProj;
float4x4 matWorld;
float4 vecAmbient;
float4 vecViewPos;
float4 vecLightColor[8];
float4 vecLightPos[8];

float3x3 matTangent;

texture entSkin1;
sampler ColorMapSampler = sampler_state
{
	Texture = <entSkin1>;
	MipFilter = LINEAR;
};

texture entSkin2;
sampler NormalMapSampler = sampler_state
{
	Texture = <entSkin2>;
	MipFilter = NONE;
};

void NormalMapVS(	in float4 InPos	: POSITION,
in float3 InNormal	: NORMAL,
in float2 InTex		: TEXCOORD0,
in float4 InTangent	: TEXCOORD2,

out float4 OutPos	: POSITION,
out float2 OutTex	: TEXCOORD0,
out float3 OutViewDir: TEXCOORD1,
out float3 OutLightDir0: TEXCOORD2,)
{
	OutPos = mul(InPos, matWorldViewProj);
	OutTex = InTex;
	matTangent[0] = mul(InTangent.xyz, matWorld);
	matTangent[1] = mul(cross(InTangent.xyz,InNormal)*InTangent.w, matWorld);
	matTangent[2] = mul(InNormal, matWorld);
	
	OutViewDir = normalize(mul(matTangent, vecViewPos - mul(InPos, matWorld)));
	
	OutLightDir0 = normalize(mul(matTangent, vecLightPos[0]-InPos.xyz));
}


float4 NormalMapPS(	in float2 InTex  : TEXCOORD0, in float3 InViewDir	: TEXCOORD1, in float3 inPos  :  TEXCOORD3,
in float3 InLightDir0	: TEXCOORD4) : COLOR
{
	float3 BumpNormal = 2 * tex2D(NormalMapSampler, InTex) - 1;
	float4 Ambient = AmbientIntensity * vecAmbient;
	float4 Diffuse[8];
	float Specular[8];	
	float3 R;
	
	Diffuse[0] = DiffuseIntensity * saturate(dot(InLightDir0, BumpNormal));
	Diffuse[0] *= vecLightColor[0];
	R = normalize(2 * dot(BumpNormal, InLightDir0) * BumpNormal - InLightDir0);
	InViewDir = normalize(InViewDir);
	Specular[0] = pow(saturate(dot(R, InViewDir)), SpecularPower) * SpecularIntensity;
	
	float4 Color = tex2D(ColorMapSampler, InTex);
	
	return (Ambient + Diffuse[0] + Specular[0]) * Color;
}

technique SpecularTechnique
{
	pass P0
	{
		VertexShader = compile vs_3_0 NormalMapVS();
		PixelShader  = compile ps_3_0 NormalMapPS();
	}
}


und es ist das ganze nur für 8 lichter, ich hab den shader entsprechend gekürzt, damit er nicht solang ist...
xxxxxxx


Es ist immer wieder erstaunlich, dass Leute die riesen Scripte schreiben die einfachsten sachen nicht können zb. mich mit SIEBEN x zu schreiben! tongue