From e727d6d4e31c68f1247d790c97110026ada013ea Mon Sep 17 00:00:00 2001 From: Delta Echo Date: Sat, 8 Feb 2020 10:12:30 +0100 Subject: [PATCH] Implement rotation into wingflex shader --- Effects/model-wingflex.eff | 50 +++++++++++++++++++ Shaders/model-ALS-wingflex.vert | 85 ++++++++++++++++++++++++++++----- 2 files changed, 123 insertions(+), 12 deletions(-) diff --git a/Effects/model-wingflex.eff b/Effects/model-wingflex.eff index dc609fb08..c6c3babb5 100644 --- a/Effects/model-wingflex.eff +++ b/Effects/model-wingflex.eff @@ -150,6 +150,14 @@ 0.0 0.0 15.0 + + 0.0 + 0.0 + 0.0 + 0.0 + 0.0 + 0.0 + 0.0 /local-weather/cloud-shadows/cloudpos-x[0] /local-weather/cloud-shadows/cloudpos-y[0] @@ -539,6 +547,48 @@ float wing-span + + + rotation_rad + float + rotation-rad + + + + rotation_x1 + float + rotation-x1 + + + + rotation_y1 + float + rotation-y1 + + + + rotation_z1 + float + rotation-z1 + + + + rotation_x2 + float + rotation-x2 + + + + rotation_y2 + float + rotation-y2 + + + + rotation_z2 + float + rotation-z2 + diff --git a/Shaders/model-ALS-wingflex.vert b/Shaders/model-ALS-wingflex.vert index b7e1d4d78..a8d06d94c 100644 --- a/Shaders/model-ALS-wingflex.vert +++ b/Shaders/model-ALS-wingflex.vert @@ -29,6 +29,13 @@ uniform float wingflex_trailing_alpha; uniform float wingsweep_factor; uniform float wingflex_z; uniform float wing_span; +uniform float rotation_x1; +uniform float rotation_y1; +uniform float rotation_z1; +uniform float rotation_x2; +uniform float rotation_y2; +uniform float rotation_z2; +uniform float rotation_rad; uniform int refl_dynamic; uniform int nmap_enabled; uniform int shader_qual; @@ -55,6 +62,28 @@ void rotationMatrixH(in float sinRz, in float cosRz, out mat4 rotmat) 0.0 , 0.0 , 0.0, 1.0 ); } +vec2 calc_deflection(float y){ + float distance; + if(y < body_width && y > -body_width){ + //this part does not move + distance = 0; + }else if(y > body_width){ + distance = y - (body_width/2); + }else if(y < -body_width){ + distance = y - ((-1*body_width)/2); + } + float max_dist = (wing_span-body_width)/2; + float deflection = wingflex_z * (distance*distance)/(max_dist*max_dist); + float delta_y; + if(y<0){ + delta_y = deflection/wing_span; + }else{ + delta_y = -deflection/wing_span; + } + vec2 returned = vec2 ( deflection, delta_y ); + return returned; +} + void main(void) { vec4 vertex = gl_Vertex; @@ -63,19 +92,49 @@ void main(void) float x_factor = max((abs(vertex.x) - body_width),0); float y_factor = max(vertex.y,0.0); - float distance; - if(vertex.y < body_width && vertex.y > -body_width){ - //this part does not move - distance = 0; - }else if(vertex.y > body_width){ - distance = vertex.y - (body_width/2); - }else if(vertex.y < -body_width){ - distance = vertex.y - ((-1*body_width)/2); - } - float deflection = wingflex_z * (distance*distance)/(wing_span*wing_span); + vec2 deflection=calc_deflection(vertex.y); + + vertex.z += deflection[0]; + vertex.y += deflection[1]; + + if(rotation_rad != 0){ + vec2 defl1=calc_deflection(rotation_y1); + vec2 defl2=calc_deflection(rotation_y2); + float rot_y1 = rotation_y1; + float rot_z1 = rotation_z1; + float rot_y2 = rotation_y2; + float rot_z2 = rotation_z2; + rot_y1 -= defl1[1]; + rot_z1 += defl1[0]; + rot_y2 -= defl2[1]; + rot_z2 += defl2[0]; + //Calculate rotation + vec3 normal; + normal[0]=rotation_x2-rotation_x1; + normal[1]=rot_y2-rot_y1; + normal[2]=rot_z2-rot_z1; + normal = normalize(normal); + float tmp = (1-cos(rotation_rad)); + mat4 rotation_matrix = mat4( + pow(normal[0],2)*tmp+cos(rotation_rad), normal[1]*normal[0]*tmp-normal[2]*sin(rotation_rad), normal[2]*normal[0]*tmp+normal[1]*sin(rotation_rad), 0.0, + normal[0]*normal[1]*tmp+normal[2]*sin(rotation_rad), pow(normal[1],2)*tmp+cos(rotation_rad), normal[2]*normal[1]*tmp-normal[0]*sin(rotation_rad), 0.0, + normal[0]*normal[2]*tmp-normal[1]*sin(rotation_rad), normal[1]*normal[2]*tmp+normal[0]*sin(rotation_rad), pow(normal[2],2)*tmp+cos(rotation_rad), 0.0, + 0.0, 0.0, 0.0, 1.0 + ); + vec4 old_point; + old_point[0]=vertex.x; + old_point[1]=vertex.y; + old_point[2]=vertex.z; + old_point[3]=1.0; + rotation_matrix[3][0] = rotation_x1 - rotation_x1*rotation_matrix[0][0] - rot_y1*rotation_matrix[1][0] - rot_z1*rotation_matrix[2][0]; + rotation_matrix[3][1] = rot_y1 - rotation_x1*rotation_matrix[0][1] - rot_y1*rotation_matrix[1][1] - rot_z1*rotation_matrix[2][1]; + rotation_matrix[3][2] = rot_z1 - rotation_x1*rotation_matrix[0][2] - rot_y1*rotation_matrix[1][2] - rot_z1*rotation_matrix[2][2]; + vec4 new_point=rotation_matrix*old_point; + vertex.x=new_point[0]; + vertex.y=new_point[1]; + vertex.z=new_point[2]; + } - vertex.z += deflection; - vertex.y -= deflection/wing_span; } else if (wingflex_type == 1 ) { float arm_reach = 4.8; @@ -115,6 +174,8 @@ void main(void) if (vertex.x > 0.0) {sweep_x = - 0.5;} vertex.x+= sweep_x * (1.0 + 0.5 *x_factor) * wingsweep_factor; + + }