I'm currently making a small 3D renderer and I got stuck in Phong shading.

My questions are:

  1. Into which space should the light coordinate be converted?

    I have my light position at world coordinates (0,0,0). I'd like to calculate "phong shading" after converting all the vertices to screen space (viewport). So Should I convert the light position to screen space too?

  2. Is there a faster way to calculate Phong shading with normal interpolation if the camera's position equals the light's position?


Typically, you calculate lighting in either world-space or view-space (or camera-space). The benefit to calculating it in camera-space is the increased precision, although this may involve introduce additional math operations in shaders depending on your setup. So it wouldn't be in screenspace, or you would need to reconstruct the positions (which could happen in deferred shading depending on your G-buffer layout).

I assume you are talking about a punctual light type (such as a point light). If so, if your light position equals your camera position, then the view and light angles are the same, which can be factored out in the BRDF that you use, so you save a dot product.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.