Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Fragment shader
- #version 420
- out vec4 color;
- in vec3 o_position;
- void main() {
- color = vec4(o_position+0.5, 1.0);
- }
- // Vertex shader
- #version 420
- layout(location=0) in vec3 position;
- out vec3 o_position;
- uniform vec4 rot_quaternion = vec4(1, 0.0, 0.0, 0.0);
- vec4 hamilton_product(vec4, vec4);
- void main() {
- //rotate by performing the hamilton product of rot_quaternion on position, then performing the hamilton product of the result with rot-quaternion conjugate.
- vec4 rotated = hamilton_product(rot_quaternion, vec4(0, position));
- rotated = hamilton_product(rotated, vec4(rot_quaternion.x, rot_quaternion.yzw*-1));
- float width = 1024.0,
- height = 768.0,
- a_ratio = width/height,
- v_angle = 45,
- scale_fac = 1/tan(radians(v_angle)),
- near = 0.1,
- far = 100.0;
- vec4 pos_4d = vec4(rotated.yz, rotated.w+3, 1);
- mat4 projection = mat4(scale_fac,0,0,0,
- 0,a_ratio*scale_fac,0,0,
- 0,0,1*(near+far)/(far-near),-2*((far*near)/(far-near)),
- 0,0,1,0);
- vec4 final = pos_4d*projection;
- o_position = position;
- gl_Position = vec4(final);
- }
- vec4 hamilton_product(vec4 q1, vec4 q2){
- return vec4(q1.x*q2.x - q1.y*q2.y - q1.z*q2.z - q1.w*q2.w,
- q1.x*q2.y + q1.y*q2.x + q1.z*q2.w - q1.w*q2.z,
- q1.x*q2.z - q1.y*q2.w + q1.z*q2.x + q1.w*q2.y,
- q1.x*q2.w + q1.y*q2.z - q1.z*q2.y + q1.w*q2.x);
- }
Advertisement
Add Comment
Please, Sign In to add comment