From be7e278f1cc119f2a2930161151394a8360fd49c Mon Sep 17 00:00:00 2001 From: Delta Echo Date: Fri, 31 Jan 2020 16:52:20 +0100 Subject: [PATCH] Improve wingflex shader+effect --- ...ingflex-organic.eff => model-wingflex.eff} | 34 ++++++- ...x-organic.vert => model-ALS-wingflex.vert} | 89 ++++++++++++------- 2 files changed, 87 insertions(+), 36 deletions(-) rename Effects/{model-wingflex-organic.eff => model-wingflex.eff} (94%) rename Shaders/{model-ALS-wingflex-organic.vert => model-ALS-wingflex.vert} (65%) diff --git a/Effects/model-wingflex-organic.eff b/Effects/model-wingflex.eff similarity index 94% rename from Effects/model-wingflex-organic.eff rename to Effects/model-wingflex.eff index 76987e27c..454254d5c 100644 --- a/Effects/model-wingflex-organic.eff +++ b/Effects/model-wingflex.eff @@ -1,6 +1,6 @@ - Effects/model-wingflex-organic + Effects/model-wingflex Effects/model-default @@ -142,9 +142,15 @@ /sim/rendering/shaders/skydome /environment/surface/wetness /environment/rain-norm + + 0 + 0.7 0.0 0.0 0.0 + 0.0 + 15.0 + /local-weather/cloud-shadows/cloudpos-x[0] /local-weather/cloud-shadows/cloudpos-y[0] /local-weather/cloud-shadows/cloudpos-x[1] @@ -435,7 +441,7 @@ - Shaders/model-ALS-wingflex-organic.vert + Shaders/model-ALS-wingflex.vert Shaders/model-ALS-ultra.frag Shaders/cloud-shadowfunc.frag Shaders/hazes.frag @@ -492,6 +498,12 @@ 7 + + organic + bool + organic + + wingflex_alpha float @@ -510,6 +522,24 @@ wingsweep-factor + + wingflex_z + float + wingflex-z + + + + body_width + float + body-width + + + + wing_span + float + wing-span + + diff --git a/Shaders/model-ALS-wingflex-organic.vert b/Shaders/model-ALS-wingflex.vert similarity index 65% rename from Shaders/model-ALS-wingflex-organic.vert rename to Shaders/model-ALS-wingflex.vert index db847ddef..5dc8ac563 100644 --- a/Shaders/model-ALS-wingflex-organic.vert +++ b/Shaders/model-ALS-wingflex.vert @@ -22,9 +22,13 @@ attribute vec3 binormal; uniform float pitch; uniform float roll; uniform float hdg; +uniform bool organic; +uniform float body_width; uniform float wingflex_alpha; uniform float wingflex_trailing_alpha; uniform float wingsweep_factor; +uniform float wingflex_z; +uniform float wing_span; uniform int refl_dynamic; uniform int nmap_enabled; uniform int shader_qual; @@ -54,47 +58,64 @@ void rotationMatrixH(in float sinRz, in float cosRz, out mat4 rotmat) void main(void) { vec4 vertex = gl_Vertex; + + if ( organic ) { + float arm_reach = 4.8; + + float x_factor = max((abs(vertex.x) - body_width),0); + float y_factor = max(vertex.y,0.0); + float flex_factor1 = wingflex_alpha * (1.0 - wingsweep_factor); + float flex_factor2 = wingflex_trailing_alpha * (1.0 -wingsweep_factor); - float body_width = 0.7; - float arm_reach = 4.8; + if (flex_factor1<0.0) {flex_factor1 *=0.7;} + if (flex_factor2<0.0) {flex_factor1 *=0.7;} - float x_factor = max((abs(vertex.x) - body_width),0); - float y_factor = max(vertex.y,0.0); - float flex_factor1 = wingflex_alpha * (1.0 - wingsweep_factor); - float flex_factor2 = wingflex_trailing_alpha * (1.0 -wingsweep_factor); + // basic flapping motion is linear to arm_reach, then parabolic + + float intercept_point = 0.1 * arm_reach * arm_reach * flex_factor1; + + if (x_factor < arm_reach) + { + vertex.z += x_factor/arm_reach * intercept_point; + } + + else + { + vertex.z += 0.1 * x_factor * x_factor * flex_factor1; + } + + // upward stroke is slightly forward-swept, downward stroke a bit backward + vertex.y += -0.25 * abs(x_factor) * flex_factor1; + + //trailing edge lags the motion + vertex.z += 0.2 * y_factor * x_factor * flex_factor2; - if (flex_factor1<0.0) {flex_factor1 *=0.7;} - if (flex_factor2<0.0) {flex_factor1 *=0.7;} + // if the wings are folded, we sweep them back + vertex.y += 0.5 * x_factor * wingsweep_factor; + float sweep_x = 0.5; + if (vertex.x > 0.0) {sweep_x = - 0.5;} - // basic flapping motion is linear to arm_reach, then parabolic - - float intercept_point = 0.1 * arm_reach * arm_reach * flex_factor1; - - if (x_factor < arm_reach) - { - vertex.z += x_factor/arm_reach * intercept_point; + vertex.x+= sweep_x * (1.0 + 0.5 *x_factor) * wingsweep_factor; + } else { + 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); } - - else - { - vertex.z += 0.1 * x_factor * x_factor * flex_factor1; - } - - // upward stroke is slightly forward-swept, downward stroke a bit backward - vertex.y += -0.25 * abs(x_factor) * flex_factor1; - - //trailing edge lags the motion - vertex.z += 0.2 * y_factor * x_factor * flex_factor2; - - - // if the wings are folded, we sweep them back - vertex.y += 0.5 * x_factor * wingsweep_factor; - float sweep_x = 0.5; - if (vertex.x > 0.0) {sweep_x = - 0.5;} - - vertex.x+= sweep_x * (1.0 + 0.5 *x_factor) * wingsweep_factor; + float deflection = wingflex_z * (distance*distance)/(wing_span*wing_span); + + vertex.z += deflection; + vertex.y -= deflection/wing_span; + } rawpos = vertex.xyz;