How to get eye vector? Cam vector/view vector?

supagusupagu Posts: 5Member

Im looking at doing some reflection shader.
How do I access the eye vector?

The vector between the camera and the vertex.

Thanks!

Comments

  • TwistedTwiglegTwistedTwigleg Posts: 1,499Admin

    I’m not very experienced with shaders by any means, so please take the following with a grain of salt.

    According to the documentation it looks like there are several ways to get to camera space/vector depending on where you are in the shader.

    I think the camera vector is the same as the eye vector. I know the camera vector is supposed to be used for things like depth and figuring out the distance a object is from the camera, so... Yeah, I dunno.

    For vertex shaders, you might be able to use INV_CAMERA_MATRIX or/or MODELVIEW_MATRIX. For fragment shaders, you CAMERA_MATRIX or VIEW.

    There is also some videos about making 2D and 3D water in the documentation. I do not know if they use the camera vector or not though.

    Hopefully this helps!

  • supagusupagu Posts: 5Member
    edited May 15

    VIEW is a start, but I want to get that in world space, I tried this:

    vec3 world_view = (CAMERA_MATRIX * vec4(VIEW, 0.0)).xyz;

    I'm not exactly sure this is right

  • TwistedTwiglegTwistedTwigleg Posts: 1,499Admin

    @supagu said:
    VIEW is a start, but I want to get that in world space, I tried this:

    vec3 world_view = (CAMERA_MATRIX * vec4(VIEW, 0.0)).xyz;

    I'm not exactly sure this is right

    Glad VIEW is helping.
    As for the code, I have no idea. Sorry! I have very little shader experience.

    Looking at the documentation, that does look like it would be the right solution for converting from the camera view to world space.

    Maybe add COLOR = world_view.xyz and see what it looks like? I don't know if it would help or not though.

Sign In or Register to comment.