Skip to content

Instantly share code, notes, and snippets.

@otanodesignco
Created August 2, 2023 07:23
Show Gist options
  • Save otanodesignco/1b93b7aa594d49df90d434badf1eb053 to your computer and use it in GitHub Desktop.
Save otanodesignco/1b93b7aa594d49df90d434badf1eb053 to your computer and use it in GitHub Desktop.
glsl view position of the camera based on the model position in three.js
/* calculate view position of the camera */
out vec3 vViewDirection;
void main()
{
vec4 worldPosition = modelMatrix * vec4( position, 1.0 );
vViewDirection = normalize( cameraPosition - worldPosition.xyz );
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment