Original Post
So i've implemented Phong lighting a few times ages ago, quite easy. However i seem to be getting this strange artifact with the specular highlight now that im doing it with deferred rendering. I am pretty certain the fact im doing it deferred makes no difference. Screenie:
Object Pass: Shading Pass Phong function: This specular isn't correct is it? If it isn't, can you see what is wrong?
Object Pass:
VS_OUTPUT vs_main( VS_INPUT In )
{
VS_OUTPUT Out;
Out.Pos = mul(float4(In.Pos,1.0), matWorldViewProjection);
Out.PosInWorld = mul(float4(In.Pos,1.0), matWorld);
Out.NormalInWorld = mul(In.Normal, matWorld);
Out.Tex = In.Tex;
return Out;
}
PS_OUTPUT ps_main( PS_INPUT In )
{
PS_OUTPUT Out;
Out.PosInWorld = float4(In.PosInWorld,1.0);
Out.NormalInWorld = float4(In.NormalInWorld,1.0);
Out.Albedo = float4(0,0,0,0);//tex2D(TextureMapSampler, In.Tex);
return Out;
}
PS_OUTPUT ps_main( PS_INPUT In )
{
PS_OUTPUT Out;
float4 Pos = tex2D(PosMapSampler,In.TexCoord);
if (Pos.w==0.0) // If nothing is drawn at this pixel, just output clear color
{
Out.Color = ClearColor;
} // End if
else
{
if ( LightType == 2 ) // Point
{
float3 Normal = normalize( tex2D( NormalMapSampler, In.TexCoord ) );
float3 ToLight = normalize( LightPosition-Pos );
float3 Reflect = normalize( 2.0f * Normal * dot( Normal, ToLight ) - ToLight );
float3 View = normalize( CameraPosition - Pos );
Out.Color = Phong( LightAmbientColour,
LightDiffuseColour,
ToLight,
Normal,
LightSpecularColour,
Reflect,
View );
}
}
return Out;
}
float4 Phong( float4 AmbientColour, // Ia
float4 DiffuseColour, // Id
float3 PointToLightVector, // L
float3 SurfaceNormal, // N
float4 SpecularColour, // Is
float3 ReflectVector, // R
float3 PointToViewer ) // V
{
float4 Ambient = AmbientColour;
float4 Diffuse = DiffuseColour * dot( SurfaceNormal, PointToLightVector );
float4 Specular = SpecularColour * pow(saturate(dot( ReflectVector, PointToViewer )),4);
return Ambient + Diffuse + Specular;
}