RenderMonkey / GLSL camera & viewpos

597 views Asked by At

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.

1

There are 1 answers

0
Tara On

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

  1. Define it in your shader like this:

    uniform vec4 vViewPosition;
    
  2. 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.