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 :smile:

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 :smile:

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 :smile:

Actually that’s a pretty neat optimization :stuck_out_tongue:
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.