Hi,
I've managed to create working effect/ shader which has a flexible number of directional and point lights, based on the given scene and available shader model.
Next thing I want to do is go to per pixel lighting instead of per vertex.
At the moment I have the normal of the vertex available in the pixel shader, but I don't use it..
Can someone give me some pointers on how to go to work to achieve per pixel lighting in my effect?
The code:
VS_OUTPUT VS_function(VS_INPUT input)
{
VS_OUTPUT Out = (VS_OUTPUT)0;
float4 worldPosition = mul(input.Pos, World);
Out.Pos = mul(worldPosition, ViewProj);
float4 normal = mul(input.Normal, WorldInvTransp);
Out.Normal = normal;
Out.TexCoord = input.TexCoord;
Out.wPos = worldPosition;
// DIRECTIONAL LIGHT
float dirIntensity[MaxDirectionalLights];
float dirTotal = 0.0f;
for(int i=0;i<MaxDirectionalLights;i++)
{
dirIntensity[i] = dot(normal, DirLightDir[i]);
dirTotal += saturate(DirLightCol[i] * DirLightInt[i] * dirIntensity[i]);
}
Out.Color = dirTotal;
return Out;
}
float4 PS_function(VS_OUTPUT input): COLOR0
{
float4 textureColor = tex2D(textureSampler, input.TexCoord);
float4 amb = AmbientColor * AmbientIntensity * MatAmb;
float4 diff = input.Color * MatDiff;
float distt[MaxPointLights];
float att[MaxPointLights];
float4 att_total = 0.0f;
float4 attcolored;
for(int i=0;i<MaxPointLights;i++)
{
distt[i] = distance(PointLightPos[i], input.wPos);
att[i] = 1 - saturate((distt[i] - PointLightFPRange[i]) / PointLightRange[i]);
att[i] = (pow(att[i], 2)) * PointLightInt[i];
attcolored = att[i] * PointLightCol[i];
att_total += attcolored;
}
return saturate((diff + amb + att_total) * textureColor);
}
I've read several tutorials on per pixel lighting, but up till now can't manage to implement it in my existing effect/shader.
Here are two screenshots of the current result, which by the way looks ok even on low poly (the ground):