#distance from camera in shaders
30 messages · Page 1 of 1 (latest)
Hi.
It's pleasure to helping you.
To calculate the distance from the camera to an object along the Z-axis in WebGL, you need to consider the camera's position and the object's position in the 3D space.
const distanceZ = cameraPosition.z - objectPosition.z;
make a sense?
for now yes
but i need distance to object uv.y
is any attribute in vertex shader that gives me camera position to current uv pixel?
I see.
Just a minutes.
hello/
hi friend.
The UV.y coordinate can be obtained from the texture coordinates of the object.
hello? If you want, plz send me DM.
okay?
varying float distToCamera;
void main() {
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4( position, 1.0 );
vUv = uv;
distToCamera = gl_Position.z;
}```
this one works
simpler than i thought
ok, thx
But how can we contact?
discord pw i guess