The 3D application has a static camera:
float eyeX = 0.0f;
float eyeY = 0.0f;
float eyeZ = 0.0f;
Matrix.setLookAtM(viewMatrix, 0, eyeX, eyeY, eyeZ,
0f, 0f, -4f, 0f, 1.0f, 0.0f)
Then this vector is used for the eye coordinates in the shader?:
const vec4 eyePos = vec4(0.0, 0.0, 0.0, 0.0);
Or need additional transformations?
Note: Read the post What exactly are eye space coordinates? but I still have doubts because my fog shader is not working. In this shader, the distance from the observer to the object is calculated:
uniform mat4 u_vMatrix;
in vec4 a_position;
out float v_eyeDist;
const vec4 eyePos = vec4(0.0, 0.0, 0.0, 0.0);
...
void main() {
...
vec4 viewPos = u_vMatrix * a_position;
v_eyeDist = sqrt(pow((viewPos.x - eyePos.x), 2.0) +
pow((viewPos.y - eyePos.y), 2.0) +
pow((viewPos.z - eyePos.z), 2.0));
...
}
Thanks in advance!
Solution: On the advice Rabbid76, I used length() function, as well as a model-view matrix.
uniform mat4 u_mvMatrix; // model-view matrix
in vec4 a_position;
out float v_eyeDist;
...
void main() {
...
vec4 viewPos = u_mvMatrix * a_position;
v_eyeDist = length(viewPos);
...
}