•      Sign In
• Create Account

### #ActualMJP

Posted 13 November 2012 - 04:04 PM

Your specular calculations are really weird, you seem to be combining bits from Phong and Blinn-Phong. Blinn-Phong uses N dot H, where N is the surface normal. You're using the direction of the light reflected about the surface normal, which is incorrect. You'll also want to multiply specular by N dot L, since this is implicit in all BRDF's and also prevents a few artifacts that can occur. Here's a revised version of your code:

float3 directionToLight = normalize(lightPosition - In.WorldPosition)
float3 norm = normalize(In.WorldNormal);

float nDotL = saturate(dot(directionToLight, norm));

// Calculate the half angle: the half the angle between our light direction and camera view
// Note: CameraView should be equal to (cameraPosition - worldPosition)
float3 halfAngle = normalize(normalize(in.CameraView) + directionToLight);

//Get Specular component
specular = pow(saturate(dot(norm, halfAngle)), specularPower) * specularLightColor * specularIntensity * nDotL;


To make that look even better you can add the normalization term to your specular.

As for spot lights, the only difference between a point light and a spot light is an additional attenuation term. Typically for a point light you use some attenuation term that you multiply into the light intensity that's based on the distance from the surface to the light source. For a spot light you can use this same distance attenutation, and then multiply it with an additional term based on the light direction and cone angles.

### #2MJP

Posted 13 November 2012 - 04:03 PM

Your specular calculations are really weird, you seem to be combining bits from Phong and Blinn-Phong. Blinn-Phong uses N dot H, where N is the surface normal. You're using the direction of the light reflected about the surface normal, which is incorrect. You'll also want to multiply specular by N dot L, since this is implicit in all BRDF's and also prevents a few artifacts that can occur. Here's a revised version of your code:

float3 directionToLight = normalize(lightPosition - In.WorldPosition)
float3 norm = normalize(In.WorldNormal);

float nDotL = saturate(dot(directionToLight, norm));

// Calculate the half angle: the half the angle between our light direction and camera view
// Note: CameraView should be equal to (cameraPosition - worldPosition)
float3 halfAngle = normalize(normalize(in.CameraView) + directionToLight);

//Get Specular component
specular = pow(saturate(dot(norm, halfAngle)), specularPower) * specularLightColor * specularIntensity * nDotL;


To make that look even better you can add the normalization term to your specular.

As for spot lights, the only difference between a point light and a spot light is an additional attenuation term. Typically for a point light you use some attenuation term that you multiply into the light intensity that's based on the distance from the surface to the light source. For a spot light you can use this same distance attenutation, and then multiply it with an additional term based on the light direction and cone angles.

### #1MJP

Posted 13 November 2012 - 04:03 PM

Your specular calculations are really weird, you seem to be combining bits from Phong and Blinn-Phong. Blinn-Phong uses N dot H, where N is the surface normal. You're using the direction of the light reflected about the surface normal, which is incorrect. You'll also want to multiply specular by N dot L, since this is implicit in all BRDF's and also prevents a few artifacts that can occur. Here's a revised version of your code:

float3 directionToLight = normalize(lightPosition - In.WorldPosition)
float3 norm = normalize(In.WorldNormal);

float nDotL = saturate(dot(directionToLight, norm));

// Calculate the half angle: the half the angle between our light direction and camera view
// Note: CameraView should be equal to normalize(cameraPosition - worldPosition)
float3 halfAngle = normalize(in.CameraView + directionToLight);

//Get Specular component
specular = pow(saturate(dot(norm, halfAngle)), specularPower) * specularLightColor * specularIntensity * nDotL;


To make that look even better you can add the normalization term to your specular.

As for spot lights, the only difference between a point light and a spot light is an additional attenuation term. Typically for a point light you use some attenuation term that you multiply into the light intensity that's based on the distance from the surface to the light source. For a spot light you can use this same distance attenutation, and then multiply it with an additional term based on the light direction and cone angles.

PARTNERS