raytracer part 10 (blinn VS phong)

Published June 22, 2005
Advertisement
So I was using the standard Phong lighting equation. But it didn't match the teachers reference pic. So I checked his old notes, found a description of using the half vector (i.e. Blinn's variant).

Blinn's approximation sucks according to me...

Phong
if( (*nearestObject)->material().shininess() > 0.0 ){	const cVector3<> viewDirection = ray.direction();	const cVector3<> reflection = directionToLight - Real(2.0) * dotLN * surfaceNormal;	const Real dotVR = Dot( viewDirection, reflection );	if( dotVR > 0 )	{		// Apply specular (phong) lightiing		const Real specular = pow( dotVR, (*nearestObject)->material().shininess() ) * (*nearestObject)->material().specular();		color += specular * light->color() * shade;	}}



Blinn
if( (*nearestObject)->material().shininess() > 0.0 ){	const cVector3<> viewDirection = -ray.direction(); // should be directionToViewer?	const cVector3<> sumLV = directionToLight + viewDirection;	const cVector3<> halfway = sumLV / sumLV.length();	const Real dotHN = Dot( halfway, surfaceNormal );	if( dotHN > 0 )	{		// Apply specular (Blinn's Phong) lightiing		const Real specular = pow( dotHN, (*nearestObject)->material().shininess() ) * (*nearestObject)->material().specular();		color += specular * light->color() * shade; // NOTE: this is subject to attune	}}


Image compare, Phong to the left and Blinn to the right

VS


And the judge:
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement