# Phong/Blinn implementation

Hello,

in the JME code , I noticed blinn was implemented that way :

``````...
vec3 H = (viewdir + lightdir) * vec3(0.5);
return pow(max(tangDot(H, norm), 0.0), shiny);
...``````

compared to implementations I found on the web , I was wondering about some differences like

• why mult by 0.5 ? to get a quarter vector ?
• why tangDot instead of dot ?

regards

1. IMO thatâ€™s just wrong, H should be normalize(viewdir + lightdir)
2. tangDot actually returns dot unless you use Vtangents

Note that Vtangents and blinn phong has been removed from master itâ€™s now standard phong only.

ok
thanks

1 Is probably an attempt to get the half-angle vector: http://www.arcsynthesis.org/gltut/Illumination/Tut11%20BlinnPhong%20Model.html#d0e11110
Maybe it works IDK

Yeah half vector is still a direction, so it has to be normalizedâ€¦makes no real sense to multiply it by 0.5

If the incoming vectors are unit vectors I guess it works out to the same thing as normalizing (maybe, Iâ€™m to tired to work it out). So instead of calcualting sqr to get the length as in N+V/|N+V| you just do N+V/2. But no, donâ€™t do that even if it works out to be the same

Actually thatâ€™s a pretty neat optimization
I guess thatâ€™s why itâ€™s like this.

No, it is a mistake and it doesnâ€™t work, whoever did it (me â€¦) is a very bad boy.

Anyways, blinn-phong should always be used which is:

``````vec3 H = normalize(V + L);
float HdotN = max(0.0, dot(H, N));
float spec  = pow(HdotN, shininess);
``````
1 Like

Iâ€™ve set lighting to standard phong which is

``````    vec3 R = reflect(-lightdir, norm);
return pow(max(dot(R, viewdir), 0.0), shiny);
``````

Blinn phong was what we had when LOW_QUALITY was defined and we agreed" we should remove it.

OK after some talk with Kirill, weâ€™re going to switch to blinn-phong in 3.1
It appears that we use phong since a long time, because we thought it was the other way around.