Hi!
I've implemented the Blinn-Phong shading model some time ago and noticed that even though the diffuse component looks smooth, the specular one doesn't (it looks good on flat surfaces). Look at the screenshot (ignore the crappy shadows):
[attachment=29608:Captura de Tela (10).png]
These are my vertex and pixel shaders (I've simplified it a lot and removed shadow mapping):
cbuffer cbChangesOnTime: register(b0)
{
float4 SunColor;
float3 SunDir;
float4 AmbientColor;
}
cbuffer cbChangesEveryFrame: register(b1)
{
matrix World;
matrix View;
matrix Projection;
matrix LightView;
matrix LightProjection;
float3 CameraPosition;
float4 DiffuseColor;
float4 SpecularColor;
float SpecularPower;
float AmbientIntensity;
}
struct VSInput
{
float4 pos: POSITION;
float2 uv: TEXCOORD;
float3 norm: NORMAL;
};
struct PSShadowedInput
{
float4 pos: SV_POSITION;
float2 uv: TEXCOORD;
float3 norm: NORMAL;
float4 worldPos: POSITION;
float4 lightViewPos: POSITION2;
};
///////////////////////////////
// This is the Vertex Shader //
///////////////////////////////
PSShadowedInput VSShadowed(VSInput input)
{
PSShadowedInput output;
output.pos = mul(World, input.pos);
output.pos = mul(View, output.pos);
output.pos = mul(Projection, output.pos);
output.uv = input.uv;
output.norm = normalize(mul((float3x3)World, input.norm));
output.worldPos = mul(World, input.pos);
/* SHADOW MAPPING */
return output;
}
//////////////////////////////
// This is the Pixel Shader //
//////////////////////////////
float4 PSShadowedLambertian(PSShadowedInput input) : SV_Target
{
float3 ViewDirection = normalize(CameraPosition - input.worldPos.xyz);
float4 Diffuse = max(dot(-SunDir, input.norm), 0.0f) * SunColor * DiffuseColor;
float4 Specular = pow(max(dot(input.norm, normalize(-SunDir + ViewDirection)), 0.0f), SpecularPower) * SpecularColor;
float4 Ambient = AmbientColor * AmbientIntensity * DiffuseColor;
/* SHADOW MAPPING */
return pow(max(Diffuse + Specular + Ambient, 0.0f), 1.0f / 2.2f);
}
What am I doing wrong? What's missing?
Thank you for spending your time reading this topic.