Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #version 330 core
- layout (location = 0) in vec3 vertex_position;
- layout (location = 1) in vec3 vertex_normal;
- layout (location = 2) in vec2 vertex_texture;
- uniform mat4 view_projection;
- uniform vec3 scale;
- uniform vec4 orientation;
- uniform vec3 translation;
- out vec3 FragPosition;
- out vec2 TexCoords;
- out vec3 NormalWorldSpace;
- vec3 transform_vertex(vec4 rotation, vec3 vertex);
- void main() {
- FragPosition = transform_vertex(orientation, scale * vertex_position) + translation;
- NormalWorldSpace = transform_vertex(orientation, (vec3(1.0) / scale) * vertex_normal); // doesn't take translation into account
- TexCoords = vertex_texture;
- gl_Position = view_projection * vec4(FragPosition, 1.0);
- }
- // Transforms the vector using a quaternion, assuming that the output does not alias with the input.
- vec3 transform_vertex(vec4 rotation, vec3 v) {
- float x2 = rotation.x + rotation.x;
- float y2 = rotation.y + rotation.y;
- float z2 = rotation.z + rotation.z;
- float xx2 = rotation.x * x2;
- float xy2 = rotation.x * y2;
- float xz2 = rotation.x * z2;
- float yy2 = rotation.y * y2;
- float yz2 = rotation.y * z2;
- float zz2 = rotation.z * z2;
- float wx2 = rotation.w * x2;
- float wy2 = rotation.w * y2;
- float wz2 = rotation.w * z2;
- // Defer the component setting since they're used in computation.
- vec3 result;
- result.x = v.x * (1f - yy2 - zz2) + v.y * (xy2 - wz2) + v.z * (xz2 + wy2);
- result.y = v.x * (xy2 + wz2) + v.y * (1f - xx2 - zz2) + v.z * (yz2 - wx2);
- result.z = v.x * (xz2 - wy2) + v.y * (yz2 + wx2) + v.z * (1f - xx2 - yy2);
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment