How do I make the vec3 viewpos follow the values of the camera? Presumably they should be the same but I don't know how to access the camera's position values.
Asked
Active
Viewed 588 times
1 Answers
0
If I understood you correctly, you want to know the position of the camera in world space.
If so, it's quite simple: 1. Right-click your effect in your workspace and then select: Add Variable > Float > Predefined > vViewPosition
Define it in your shader like this:
uniform vec4 vViewPosition;
Use it however you like. Example vertex shader:
uniform vec4 vViewPosition; void main( void ) { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; float dist = distance(gl_Vertex.xyz, vViewPosition.xyz); }
I hope that helped.

Tara
- 1,673
- 22
- 30