Im looking at doing some reflection shader. How do I access the eye vector?
The vector between the camera and the vertex.
Thanks!
Im looking at doing some reflection shader. How do I access the eye vector?
The vector between the camera and the vertex.
Thanks!
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!
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
@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.
Perseid I am super late to the party but in Godot 4, in fragment processor, VIEW gives us direction from fragment to camera in view space.
For eye vector we need opposite of that (Camera to fragment).
And to get that in world space something like following should work.
vec3 eye_direction = (INV_VIEW_MATRIX * vec4(-VIEW, 1.0)).xyz;
// last argument of vec4 doesn't really matter, it can be 0.0, 1.0
Also there is CAMERA_DIRECTION_WORLD
© 2022 - 2024 — McMap. All rights reserved.