-
-
Save ArieLeo/fa3afb76a6253c1e91f2ce543784bf23 to your computer and use it in GitHub Desktop.
Build a 4x4 look at matrix in cginc
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
| #ifndef _LOOK_AT_MATRIX_ | |
| #define _LOOK_AT_MATRIX_ | |
| float4x4 look_at_matrix(float3 at, float3 eye, float3 up) { | |
| float3 zaxis = normalize(at - eye); | |
| float3 xaxis = normalize(cross(up, zaxis)); | |
| float3 yaxis = cross(zaxis, xaxis); | |
| return float4x4( | |
| xaxis.x, yaxis.x, zaxis.x, 0, | |
| xaxis.y, yaxis.y, zaxis.y, 0, | |
| xaxis.z, yaxis.z, zaxis.z, 0, | |
| 0, 0, 0, 1 | |
| ); | |
| } | |
| #endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment