Guest User

Untitled

a guest
Sep 4th, 2023
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Godot GLSL 1.53 KB | Source Code | 0 0
  1. //Fragment shader
  2. #version 420
  3. out vec4 color;
  4. in vec3 o_position;
  5.  
  6. void main() {
  7.     color = vec4(o_position+0.5, 1.0);
  8. }
  9.  
  10. // Vertex shader
  11. #version 420
  12. layout(location=0) in vec3 position;
  13. out vec3 o_position;
  14.  
  15. uniform vec4 rot_quaternion = vec4(1, 0.0, 0.0, 0.0);
  16.  
  17. vec4 hamilton_product(vec4, vec4);
  18.  
  19. void main() {
  20.     //rotate by performing the hamilton product of rot_quaternion on position, then performing the hamilton product of the result with rot-quaternion conjugate.
  21.     vec4 rotated = hamilton_product(rot_quaternion, vec4(0, position));
  22.     rotated = hamilton_product(rotated, vec4(rot_quaternion.x, rot_quaternion.yzw*-1));
  23.    
  24.    
  25.     float width = 1024.0,
  26.         height = 768.0,
  27.         a_ratio = width/height,
  28.         v_angle = 45,
  29.         scale_fac = 1/tan(radians(v_angle)),
  30.         near = 0.1,
  31.         far = 100.0;
  32.        
  33.     vec4 pos_4d = vec4(rotated.yz, rotated.w+3, 1);
  34.     mat4 projection = mat4(scale_fac,0,0,0,
  35.                            0,a_ratio*scale_fac,0,0,
  36.                            0,0,1*(near+far)/(far-near),-2*((far*near)/(far-near)),
  37.                            0,0,1,0);
  38.     vec4 final = pos_4d*projection;
  39.    
  40.     o_position = position;
  41.     gl_Position = vec4(final);
  42. }
  43.  
  44.  
  45. vec4 hamilton_product(vec4 q1, vec4 q2){
  46.     return vec4(q1.x*q2.x - q1.y*q2.y - q1.z*q2.z - q1.w*q2.w,
  47.                 q1.x*q2.y + q1.y*q2.x + q1.z*q2.w - q1.w*q2.z,
  48.                 q1.x*q2.z - q1.y*q2.w + q1.z*q2.x + q1.w*q2.y,
  49.                 q1.x*q2.w + q1.y*q2.z - q1.z*q2.y + q1.w*q2.x);
  50.    
  51. }
Advertisement
Add Comment
Please, Sign In to add comment