Original Post
Hi,
I'm working on a spotlight shader and am stumped on the specular component calculation, most specular calculations assume an angle of reflectance from the lights position against the normal of the object in question (the light being assumed to be omini in this instance).
Here is a standard omni representation...
[source lang="cpp"]
float3 directionToLight= normalize(lightPosition - In.WorldPosition)
float3 norm = normalize( reflect( -directionToLight, normalize(In.WorldNormal) ) );
// Calculate the half angle: the half the angle between our light direction and camera view
float3 halfAngle = normalize( In.CameraView - directionToLight);
//Get Specular component
specular = pow( saturate( dot( norm, halfAngle ) ), specularPower ) * specularLightColor * specularIntensity;
[/source]
The Spotlight is a different beast as it has direction as well as position, and this calculation is not physically correct as the light source could be rotated away from from the object and the calculation would yield a result for a positive specular value. Does anyone have any good examples of the correct specular calculation?
Thanks in advance.
I'm working on a spotlight shader and am stumped on the specular component calculation, most specular calculations assume an angle of reflectance from the lights position against the normal of the object in question (the light being assumed to be omini in this instance).
Here is a standard omni representation...
[source lang="cpp"]
float3 directionToLight= normalize(lightPosition - In.WorldPosition)
float3 norm = normalize( reflect( -directionToLight, normalize(In.WorldNormal) ) );
// Calculate the half angle: the half the angle between our light direction and camera view
float3 halfAngle = normalize( In.CameraView - directionToLight);
//Get Specular component
specular = pow( saturate( dot( norm, halfAngle ) ), specularPower ) * specularLightColor * specularIntensity;
[/source]
The Spotlight is a different beast as it has direction as well as position, and this calculation is not physically correct as the light source could be rotated away from from the object and the calculation would yield a result for a positive specular value. Does anyone have any good examples of the correct specular calculation?
Thanks in advance.