# Specular light flickering with high specular power

I'm having some issues with specular lights, to be more specific, the specular color seems to be flickering when I set high power, like 512 (I set the specular color to green, so you can see better):

https://i.sstatic.net/SNAmA.gif

And when a power like 32 is used, everything seems ok:

pin.NormalW = normalize(pin.NormalW);

float3 toEyeW = normalize(gEyePosW - pin.PosW);

float4 ambient = float4(0.0f, 0.0f, 0.0f, 0.0f);
float4 diffuse = float4(0.0f, 0.0f, 0.0f, 0.0f);
float4 spec    = float4(0.0f, 0.0f, 0.0f, 0.0f);

// Sum the light contribution from each light source
float4 A, D, S;

ComputeDirectionalLight(gMaterial, gDirLight, pin.NormalW, toEyeW, A, D, S);

ambient += A;
diffuse += D;
spec    += S;

float4 litColor = ambient + diffuse + spec;

litColor.a = gMaterial.Diffuse.a;

return litColor;


ComputeDirectionalLight function:

void ComputeDirectionalLight(Material mat, DirectionalLight L,
float3 normal, float3 toEye,
out float4 ambient,
out float4 diffuse,
out float4 spec)
{
// Initialize outputs.
ambient = float4(0.0f, 0.0f, 0.0f, 0.0f);
diffuse = float4(0.0f, 0.0f, 0.0f, 0.0f);
spec = float4(0.0f, 0.0f, 0.0f, 0.0f);

// The light vector aims opposite the direction the light rays travel.
float3 lightVec = -L.Direction;

ambient = mat.Ambient * L.Ambient;

// Add diffuse and specular term, provided the surface is in
// the line of site of the light.

float diffuseFactor = dot(lightVec, normal);

// Flatten to avoid dynamic branching.
[flatten]
if (diffuseFactor > 0.0f)
{
float3 v = reflect(-lightVec, normal);
float specFactor = pow(max(dot(v, toEye), 0.0f), mat.Specular.w);

diffuse = diffuseFactor * mat.Diffuse * L.Diffuse;
spec = specFactor * mat.Specular * L.Specular;
}
}


I'm using DirectX 11.

• This does not look like traditional specular highlight.. Are you sure you are making one? Commented Nov 24, 2014 at 6:03
• What do you mean? Maybe It's because directional light source is almost in front of the sphere?
– user41092
Commented Nov 24, 2014 at 9:31
• Distance to light source is not used in the specular equation. Commented Nov 24, 2014 at 10:53