1
0
Fork 0

Implement rotation into wingflex shader

This commit is contained in:
Delta Echo 2020-02-08 10:12:30 +01:00 committed by James Turner
parent 784ebe28a9
commit e727d6d4e3
2 changed files with 123 additions and 12 deletions

View file

@ -150,6 +150,14 @@
<wingsweep-factor>0.0</wingsweep-factor>
<wingflex-z>0.0</wingflex-z>
<wing-span>15.0</wing-span>
<!-- Sub: rotation -->
<rotation-rad type="float">0.0</rotation-rad>
<rotation-x1 type="float">0.0</rotation-x1>
<rotation-y1 type="float">0.0</rotation-y1>
<rotation-z1 type="float">0.0</rotation-z1>
<rotation-x2 type="float">0.0</rotation-x2>
<rotation-y2 type="float">0.0</rotation-y2>
<rotation-z2 type="float">0.0</rotation-z2>
<!-- END Wingflex -->
<cloudpos1_x><use>/local-weather/cloud-shadows/cloudpos-x[0]</use></cloudpos1_x>
<cloudpos1_y><use>/local-weather/cloud-shadows/cloudpos-y[0]</use></cloudpos1_y>
@ -539,6 +547,48 @@
<type>float</type>
<value><use>wing-span</use></value>
</uniform>
<uniform>
<name>rotation_rad</name>
<type>float</type>
<value><use>rotation-rad</use></value>
</uniform>
<uniform>
<name>rotation_x1</name>
<type>float</type>
<value><use>rotation-x1</use></value>
</uniform>
<uniform>
<name>rotation_y1</name>
<type>float</type>
<value><use>rotation-y1</use></value>
</uniform>
<uniform>
<name>rotation_z1</name>
<type>float</type>
<value><use>rotation-z1</use></value>
</uniform>
<uniform>
<name>rotation_x2</name>
<type>float</type>
<value><use>rotation-x2</use></value>
</uniform>
<uniform>
<name>rotation_y2</name>
<type>float</type>
<value><use>rotation-y2</use></value>
</uniform>
<uniform>
<name>rotation_z2</name>
<type>float</type>
<value><use>rotation-z2</use></value>
</uniform>
<!-- NORMAL MAP -->
<!-- normalmap is used-->

View file

@ -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;
}