I’ve been looking at the template code for the phong shader in libs/openFrameworks/gl/shaders and think I might have found a couple of bugs in phong.frag.
The raw interpollated value for v_transformedNormal is handed to the light shaders. I think the normal should be re-normalized to make sure it is truly a normalized value. Adding a line to re-nomalize it before the light loop appears to significantly reduce shading artefacts, particularly in specular highlights, if you’ve got vertex normals that are at quite different angles to each other (e.g. with a low poly count sphere).
In the light calculations the calculation of the halfVector between the light ray and eye ray appear to use a normalized version of the light ray direction but the eye direction appears to be un-normalized. I think this may be causing some effects such as biasing the halfRay, and hence the position of specular highlight, towards the eye-ray direction if the eye is a long way from the surface.
I might be missing something, but changing the code seems to create what looks to me like better shading!
that sounds reasonable, can you send a PR?
Sure. As a complete newbie to the forum, what’s the procedure that I need to follow?
you need to do this through github: https://github.com/openframeworks/openFrameworks you would need to clone the code to your computer from there, fix the problem in a branch and send a pull request from your branch to the openframeworks main repo
if you don’t have experience with github, perhaps just open an isssue there with details about the problem and the solution you propose so others can then fix it in the code
I’ll give it a go! I guess that I need to be given access to the repository to push a new branch. My GitHub ID is ‘andylomas’.
there’s no need for you to be given access. That’s the whole point of the pull request.
there are some guidelines here.
If you are not used to git here is a useful intro.
(if you are not used to git I really recommend you to learn it, it will become super useful for keeping your code well organized)
OK… I think I’ve followed the correct procedure now! I have to admit that all my previous experience with GitHub has been using my own repositories so I haven’t previously had to do a PR to a remote repository. So I’ve been having to go another step up the Git learning curve!
The issue number this is tracked against is #6621: phong.frag: v_transformedNormal and eye should be re-normalized. I think the fix is quite a simple one.