Created
April 29, 2023 22:33
-
-
Save moonraker22/b0c22daf37b09260246cd4e9a14909c9 to your computer and use it in GitHub Desktop.
get world space in three js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vec3 worldCoordinatesFromDepth(float depth) { | |
float z = depth * 2.0 - 1.0; | |
vec4 clipSpaceCoordinate = vec4(vUv * 2.0 - 1.0, z, 1.0); | |
vec4 viewSpaceCoordinate = projectionMatrixInverse * clipSpaceCoordinate; | |
viewSpaceCoordinate /= viewSpaceCoordinate.w; | |
vec4 worldSpaceCoordinates = viewMatrixInverse * viewSpaceCoordinate; | |
return worldSpaceCoordinates.xyz; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment