<p><strong><em>EDIT</em></strong></p>

<p>While the basic principle of vector calculation below is correct, as Sebastián Mestre pointed out, in lighting you would use the vector from the lighted fragment to the eye position. Therefore, you would in fact use $v = -(point - eye) = eye - point = -point$, so you were actually correct in your "negative" assumption. Still (what might have been more a typo than a misunderstanding), it is the negative position of the lighted fragment, rather than the negative eye (which would still be the origin).</p>

<p>As Sebastián also said in a comment to you, you would usually normalize the view vector after you have calculated it. Sebastián is the MVP.</p>

<hr>

<p>Calculating a vector $v$ from point $A$ to point $B$ is subtracting the values of $B$ from $A$:</p>

<p>$v = \left(\begin{array}{c}x\\y\\z\end{array}\right) = B - A = \left(\begin{array}{c}b_x - a_x\\b_y-a_y\\b_z-a_z\end{array}\right)$</p>

<p>So in your case, you need to subtract the $eye$ point from the point you're calculating light ($pos$) for:</p>

<p>$
v = point -eye
$</p>

<p>Your $eye$ is the origin, so remaining is only the $point$. Therefore: no, it is not the negative position of the lighted point, but the positive position.</p>

CC BY-SA 3.0
2018-02-23T07:01:53.580Z
It is very common (specially in more advanced brdfs) to use the vector that points from the shaded fragment to the eye as the view vector instead. It would be good if you mentioned this in your answer.
Sebastián Mestre
CC BY-SA 3.0
2018-02-23T07:11:07.477Z
you are right, i'll add it
Tare
CC BY-SA 3.0
2018-02-23T06:47:13.970Z
2018-02-23T07:16:05.573Z
2018-02-23T07:16:05.573Z
Tare
<p>It's correct as far as it goes, but there's more. The view vector goes from the shading point to the eye point, but it's normalized (divided by its length so that it has length 1). So if you're shading $p$ and the eye is at the origin, the view vector is $\tfrac{-p}{|-p|}$.</p>

<p>It's not always this simple, because the "eye" isn't always at the origin. In a scanline rasteriser, you use the view transform to move things to the origin, because that's the only way to make the projection work - but not in a ray-tracer. The camera can be anywhere in a ray-tracer, and when you trace secondary rays (for reflections, refractions, or some other effects), it's definitely not in the same place as the camera.</p>

<p>In the case you're working on right now, it sounds like you can just normalize $-p$, but you need to remember that it's really the direction from the shading point to the eye point, so that you can do the right thing when the eye point <em>isn't</em> the origin.</p>

CC BY-SA 3.0
2018-02-23T09:59:35.340Z
2018-02-23T09:59:35.340Z
Dan Hulme
<p>All the books and reference I have read say that the view vector is calculated by subtracting the point where eye is at, from the point where we want to calculate light. But since, eye is at (0, 0, 0) the view vector would be just the negative of the point where eye is at? Is my understanding correct?</p>

CC BY-SA 3.0
2018-02-23T06:47:34.667Z
If the eye is at the origin then the view vector is the negative position (usually also normalized to have length 1)
Sebastián Mestre
<3d>
How to calculate the view vector in Phong Lighting Model?
Manh Nguyen Huu
# How to calculate the view vector in Phong Lighting Model?

(Asked by: username_0 on 2018-02-23)

All the books and reference I have read say that the view vector is calculated by subtracting the point where eye is at, from the point where we want to calculate light. But since, eye is at (0, 0, 0) the view vector would be just the negative of the point where eye is at? Is my understanding correct?

**Tags:** 3d

> **Comments:**
> **username_1**: If the eye is at the origin then the view vector is the negative position (usually also normalized to have length 1)  

---

## 2 answers

### Answer by username_2 on 2018-02-23. Score: 1 | Accepted answer

***EDIT***

While the basic principle of vector calculation below is correct, as username_1 username_1 pointed out, in lighting you would use the vector from the lighted fragment to the eye position. Therefore, you would in fact use $v = -(point - eye) = eye - point = -point$, so you were actually correct in your "negative" assumption. Still (what might have been more a typo than a misunderstanding), it is the negative position of the lighted fragment, rather than the negative eye (which would still be the origin).

As username_1 also said in a comment to you, you would usually normalize the view vector after you have calculated it. username_1 is the MVP.

---

Calculating a vector $v$ from point $A$ to point $B$ is subtracting the values of $B$ from $A$:

$v = \left(\begin{array}{c}x\\y\\z\end{array}\right) = B - A = \left(\begin{array}{c}b\_x - a\_x\\b\_y-a\_y\\b\_z-a\_z\end{array}\right)$

So in your case, you need to subtract the $eye$ point from the point you're calculating light ($pos$) for:

$
v = point -eye
$

Your $eye$ is the origin, so remaining is only the $point$. Therefore: no, it is not the negative position of the lighted point, but the positive position.

> **Comments:**
> **username_1**: It is very common (specially in more advanced brdfs) to use the vector that points from the shaded fragment to the eye as the view vector instead. It would be good if you mentioned this in your answer.  
> **username_2**: you are right, i'll add it  

---

### Answer by username_3 on 2018-02-23. Score: 0

It's correct as far as it goes, but there's more. The view vector goes from the shading point to the eye point, but it's normalized (divided by its length so that it has length 1). So if you're shading $p$ and the eye is at the origin, the view vector is $\tfrac{-p}{|-p|}$.

It's not always this simple, because the "eye" isn't always at the origin. In a scanline rasteriser, you use the view transform to move things to the origin, because that's the only way to make the projection work - but not in a ray-tracer. The camera can be anywhere in a ray-tracer, and when you trace secondary rays (for reflections, refractions, or some other effects), it's definitely not in the same place as the camera.

In the case you're working on right now, it sounds like you can just normalize $-p$, but you need to remember that it's really the direction from the shading point to the eye point, so that you can do the right thing when the eye point *isn't* the origin.


---

