<p>Operations between two vectors do not make sense unless both vectors are in the same space. So you must either transform the camera position into object space or transform the object position into camera space. I would suggest the latter, since you already likely have a matrix lying around for doing that for other reasons (lighting, etc).</p>

CC BY-SA 4.0
2019-08-06T15:26:22.720Z
2019-08-06T15:26:22.720Z
Nicol Bolas
<p>in the vertex shader I have the vertex position <code>vpos</code> which is in object space and I want to get the vector going from the camera to <code>vpos</code>. Can I just do <code>vpos - cameraPos</code> or do I need to do some matrix multiplication with the model-view inverse because <code>vPos</code> and <code>cameraPos</code> are not in the same space?</p>

<opengl><matrix>
Camera position in vertex shader
Voko
# Camera position in vertex shader

(Asked by: username_0 on 2019-08-06)

in the vertex shader I have the vertex position `vpos` which is in object space and I want to get the vector going from the camera to `vpos`. Can I just do `vpos - cameraPos` or do I need to do some matrix multiplication with the model-view inverse because `vPos` and `cameraPos` are not in the same space?

**Tags:** opengl, matrix


---

## 1 answers

### Answer by username_1 on 2019-08-06. Score: 2 | Accepted answer

Operations between two vectors do not make sense unless both vectors are in the same space. So you must either transform the camera position into object space or transform the object position into camera space. I would suggest the latter, since you already likely have a matrix lying around for doing that for other reasons (lighting, etc).


---

