Created
April 29, 2020 06:03
-
-
Save actarian/13a30a3442aaad933a22d9216c961a8d to your computer and use it in GitHub Desktop.
modelViewMatrix for vscode-glsl-canvas
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
| mat4 rotate(float angle, vec3 axis) { | |
| vec3 a = normalize(axis); float s = sin(angle); float c = cos(angle); float n = 1.0 - c; | |
| return mat4(n * a.x * a.x + c, n * a.x * a.y - a.z * s, n * a.z * a.x + a.y * s, 0.0, n * a.x * a.y + a.z * s, n * a.y * a.y + c, n * a.y * a.z - a.x * s, 0.0, n * a.z * a.x - a.y * s, n * a.y * a.z + a.x * s, n * a.z * a.z + c, 0.0, 0.0, 0.0, 0.0, 1.0); | |
| } | |
| mat4 translate(vec3 t) { | |
| return mat4(1.0, 0.0, 0.0, t.x, 0.0, 1.0, 0.0, t.y, 0.0, 0.0, 1.0, t.z, 0.0, 0.0, 0.0, 1.0); | |
| } | |
| mat4 scale(vec3 s) { | |
| return mat4(s.x, 0.0, 0.0, 0.0, 0.0, s.y, 0.0, 0.0, 0.0, 0.0, s.z, 0.0, 0.0, 0.0, 0.0, 1.0); | |
| } | |
| void main(void) { | |
| mat4 ms = scale(vec3(1.0)); | |
| mat4 mr = rotate(u_time, vec3(0.0, 1.0, 0.0)); | |
| mat4 mt = translate(vec3(0.0, 0.0, -9.0 + cos(u_time) * 3.0)); | |
| v_position = a_position * ms * mr * mt; | |
| v_position = u_projectionMatrix * v_position; | |
| v_normal = a_normal * mr; | |
| v_texcoord = a_texcoord; | |
| v_color = a_color; | |
| gl_Position = v_position; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment