openframeworks / openframeworks/openFrameworks
phong.frag: v_transformedNormal and eye should be re-normalized
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 10.4k
- Forks
- 2.6k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 9
Description
There appears to be shading bugs caused by the v_transformedNormal and eye not being re-normalized in libs/openFrameworks/gl/shaders/phong.frag
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. This appears to 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.
The suggestion is to normalize v_transformedNormal before it is handed to the lights, as well as normalizing the eye vector in the functions for the point and spot light types.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in libs/openFrameworks/gl/shaders/phong.frag and inspect how v_transformedNormal and the eye vector are passed into the light calculations. Done means both vectors are re-normalized as described and shading artifacts, especially specular highlights on low-poly geometry, are reduced.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100