From 88bd9e97a49d38d491e43bbce16a8a71fbe1b90f Mon Sep 17 00:00:00 2001 From: Thorsten Renk Date: Sun, 8 Nov 2015 22:34:12 +0200 Subject: [PATCH] Wing motion shader, currently adapted for Pterosaur Dragon model --- Effects/model-wingflex-organic.eff | 1765 +++++++++++++++++++++++ Shaders/model-ALS-wingflex-organic.vert | 143 ++ 2 files changed, 1908 insertions(+) create mode 100644 Effects/model-wingflex-organic.eff create mode 100644 Shaders/model-ALS-wingflex-organic.vert diff --git a/Effects/model-wingflex-organic.eff b/Effects/model-wingflex-organic.eff new file mode 100644 index 000000000..2887867c4 --- /dev/null +++ b/Effects/model-wingflex-organic.eff @@ -0,0 +1,1765 @@ + + + Effects/model-wingflex-organic + Effects/model-default + + + + + + 0 + 0 + 1.0 + + Aircraft/Generic/Effects/null_bumpspec.png + 2d + linear-mipmap-linear + clamp + clamp + normalized + + + 0 + 0 + 1.0 + 1.0 1.0 1.0 + 1.0 + 1.0 1.0 1.0 + 1.0 + 1.0 1.0 1.0 + 1.0 + 1.0 1.0 1.0 + 0 + 0.0 + + Aircraft/Generic/Effects/greymap.png + 2d + linear-mipmap-linear + clamp + clamp + normalized + + + 0 + 0.0 + 0 + 0 + + Aircraft/Generic/Effects/ReflectMaps/reflectmap.png + 2d + linear-mipmap-linear + clamp + clamp + normalized + + + + cubemap + + + + + + Aircraft/Generic/Effects/CubeMaps/fair-sky/fair-sky_px.png + Aircraft/Generic/Effects/CubeMaps/fair-sky/fair-sky_nx.png + Aircraft/Generic/Effects/CubeMaps/fair-sky/fair-sky_py.png + Aircraft/Generic/Effects/CubeMaps/fair-sky/fair-sky_ny.png + Aircraft/Generic/Effects/CubeMaps/fair-sky/fair-sky_pz.png + Aircraft/Generic/Effects/CubeMaps/fair-sky/fair-sky_nz.png + + + + + 0.1 + + Aircraft/Generic/Effects/Gradients.png + 2d + linear-mipmap-linear + repeat + repeat + normalized + + + 0.01 + 0.25 + + + 0 + 10 + + Textures/Terrain/void.png + 2d + linear-mipmap-linear + repeat + repeat + normalized + + + + 0 + + 0 + 0 + 0.0 0.0 0.0 + 0.0 + 0.0 0.0 0.0 + 0.0 + 0.0 0.0 0.0 + 0.0 + + 0.05 + opaque + false + + 1 + RenderBin + + + smooth + + orientation/model/heading-deg + + + orientation/model/pitch-deg + + + orientation/model/roll-deg + + + position/model/longitude-deg + + + position/model/latitude-deg + + + /environment/ground-visibility-m + /environment/visibility-m + /environment/ground-haze-thickness-m + /rendering/scene/scattering + /environment/terminator-relative-position-m + /sim/rendering/shaders/skydome + /environment/surface/wetness + /environment/rain-norm + 0.0 + 0.0 + 0.0 + /local-weather/cloud-shadows/cloudpos-x[0] + /local-weather/cloud-shadows/cloudpos-y[0] + /local-weather/cloud-shadows/cloudpos-x[1] + /local-weather/cloud-shadows/cloudpos-y[1] + /local-weather/cloud-shadows/cloudpos-x[2] + /local-weather/cloud-shadows/cloudpos-y[2] + /local-weather/cloud-shadows/cloudpos-x[3] + /local-weather/cloud-shadows/cloudpos-y[3] + /local-weather/cloud-shadows/cloudpos-x[4] + /local-weather/cloud-shadows/cloudpos-y[4] + /local-weather/cloud-shadows/cloudpos-x[5] + /local-weather/cloud-shadows/cloudpos-y[5] + /local-weather/cloud-shadows/cloudpos-x[6] + /local-weather/cloud-shadows/cloudpos-y[6] + /local-weather/cloud-shadows/cloudpos-x[7] + /local-weather/cloud-shadows/cloudpos-y[7] + /local-weather/cloud-shadows/cloudpos-x[8] + /local-weather/cloud-shadows/cloudpos-y[8] + /local-weather/cloud-shadows/cloudpos-x[9] + /local-weather/cloud-shadows/cloudpos-y[9] + /local-weather/cloud-shadows/cloudpos-x[10] + /local-weather/cloud-shadows/cloudpos-y[10] + /local-weather/cloud-shadows/cloudpos-x[11] + /local-weather/cloud-shadows/cloudpos-y[11] + /local-weather/cloud-shadows/cloudpos-x[12] + /local-weather/cloud-shadows/cloudpos-y[12] + /local-weather/cloud-shadows/cloudpos-x[13] + /local-weather/cloud-shadows/cloudpos-y[13] + /local-weather/cloud-shadows/cloudpos-x[14] + /local-weather/cloud-shadows/cloudpos-y[14] + /local-weather/cloud-shadows/cloudpos-x[15] + /local-weather/cloud-shadows/cloudpos-y[15] + /local-weather/cloud-shadows/cloudpos-x[16] + /local-weather/cloud-shadows/cloudpos-y[16] + /local-weather/cloud-shadows/cloudpos-x[17] + /local-weather/cloud-shadows/cloudpos-y[17] + /local-weather/cloud-shadows/cloudpos-x[18] + /local-weather/cloud-shadows/cloudpos-y[18] + /local-weather/cloud-shadows/cloudpos-x[19] + /local-weather/cloud-shadows/cloudpos-y[19] + /local-weather/cloud-shadows/cloud-shadow-flag + /sim/rendering/rembrandt/enabled + + + + + + + + + /sim/rendering/shaders/skydome + /sim/rendering/shaders/quality-level + /sim/rendering/shaders/model + + + 2.0 + + + + GL_ARB_shader_objects + GL_ARB_shading_language_100 + GL_ARB_vertex_shader + GL_ARB_fragment_shader + + + + + + true + + + material/active + + + material/ambient + + + material/diffuse + + + material/specular + + + material/emissive + + + material/shininess + + + material/color-mode + + + + + blend/active + + + blend/source + + + blend/destination + + + + shade-model + + + cull-face + + + rendering-hint + + + transparent + + + transparent + + + + render-bin/bin-number + + + render-bin/bin-name + + + + + 0 + + texture[0]/image + + + texture[0]/type + + + texture[0]/filter + + + texture[0]/wrap-s + + + texture[0]/wrap-t + + + texture[0]/internal-format + + + + + 1 + noise + + + + 2 + + texture[2]/image + + + texture[2]/type + + + texture[2]/filter + + + texture[2]/wrap-s + + + texture[2]/wrap-t + + + texture[2]/internal-format + + + + + 3 + + texture[3]/image + + + texture[3]/type + + + texture[3]/filter + + + texture[3]/wrap-s + + + texture[3]/wrap-t + + + texture[3]/internal-format + + + + + 4 + + texture[4]/image + + + texture[4]/type + + + texture[4]/filter + + + texture[4]/wrap-s + + + texture[4]/wrap-t + + + texture[4]/internal-format + + + + + 5 + + texture[5]/type + + + + + + + texture[5]/images + + + + + + 6 + + texture[6]/image + + + texture[6]/type + + + texture[6]/filter + + + texture[6]/wrap-s + + + texture[6]/wrap-t + + + texture[6]/internal-format + + + + + 7 + + texture[7]/image + + + texture[7]/type + + + texture[7]/filter + + + texture[7]/wrap-s + + + texture[7]/wrap-t + + + texture[7]/internal-format + + + + + vertex-program-two-side + + + + Shaders/model-ALS-wingflex-organic.vert + Shaders/model-ALS-ultra.frag + Shaders/cloud-shadowfunc.frag + Shaders/hazes.frag + Shaders/secondary_lights.frag + Shaders/noise.frag + + + + BaseTex + sampler-2d + 0 + + + + ReflNoiseTex + sampler-3d + 1 + + + + NormalTex + sampler-2d + 2 + + + + LightMapTex + sampler-2d + 3 + + + + ReflMapTex + sampler-2d + 4 + + + + Environment + sampler-cube + 5 + + + + ReflGradientsTex + sampler-2d + 6 + + + + GrainTex + sampler-2d + 7 + + + + wingflex_alpha + float + wingflex-alpha + + + + wingflex_trailing_alpha + float + wingflex-trailing-alpha + + + + wingsweep_factor + float + wingsweep-factor + + + + + + nmap_enabled + int + + normalmap-enabled + + + + + + nmap_dds + int + + normalmap-dds + + + + + nmap_tile + float + + normalmap-tiling + + + + + + + lightmap_enabled + int + + lightmap-enabled + + + + + lightmap_multi + int + + lightmap-multi + + + + + lightmap_r_factor + float + + lightmap-factor[0] + + + + + lightmap_r_color + float-vec3 + + lightmap-color[0] + + + + + lightmap_g_factor + float + + lightmap-factor[1] + + + + + lightmap_g_color + float-vec3 + + lightmap-color[1] + + + + + lightmap_b_factor + float + + lightmap-factor[2] + + + + + lightmap_b_color + float-vec3 + + lightmap-color[2] + + + + + lightmap_a_factor + float + + lightmap-factor[3] + + + + + lightmap_a_color + float-vec3 + + lightmap-color[3] + + + + + darkmap_factor + float + + darkmap-factor + + + + + + refl_enabled + int + + reflection-enabled + + + + + refl_correction + float + + reflection-correction + + + + + + refl_map + int + + reflect-map-enabled + + + + + refl_dynamic + int + + reflection-dynamic + + + + + + refl_rainbow + float + + reflection-rainbow + + + + + + refl_fresnel + float + + reflection-fresnel + + + + + + refl_noise + float + + reflection-noise + + + + + + dirt_enabled + int + + dirt-enabled + + + + + dirt_multi + int + + dirt-multi + + + + + dirt_r_color + float-vec3 + + dirt-color[0] + + + + + dirt_r_factor + float + + dirt-factor[0] + + + + + dirt_g_color + float-vec3 + + dirt-color[1] + + + + + dirt_g_factor + float + + dirt-factor[1] + + + + + dirt_b_color + float-vec3 + + dirt-color[2] + + + + + dirt_b_factor + float + + dirt-factor[2] + + + + + + + grain_texture_enabled + int + + grain-texture-enabled + + + + + grain_magnification + float + + grain-magnification + + + + + + rain_enabled + int + + rain-enabled + + + + + + amb_correction + float + + ambient-correction + + + + + hdg + float + + model-hdg + + + + + pitch + float + + model-pitch + + + + + roll + float + + model-roll + + + + + + visibility + float + + visibility + + + + avisibility + float + + avisibility + + + + hazeLayerAltitude + float + + lthickness + + + + scattering + float + + scattering + + + + terminator + float + + terminator + + + + ground_scattering + float + + ground_scattering + + + + terminator + float + + terminator + + + + terrain_alt + float + + terrain_alt + + + + overcast + float + + overcast + + + + eye_alt + float + + eye_alt + + + + cloud_self_shading + float + cloud_self_shading + + + moonlight + float + moonlight + + + air_pollution + float + air_pollution + + + rain_norm + float + rnorm + + + wetness + float + wetness + + + view_pitch_offset + float + view_pitch_offset + + + view_heading_offset + float + view_heading_offset + + + field_of_view + float + view_fov + + + landing_light1_offset + float + landing_light1_offset + + + landing_light2_offset + float + landing_light2_offset + + + landing_light3_offset + float + landing_light3_offset + + + cloudpos1_x + float + cloudpos1_x + + + cloudpos1_y + float + cloudpos1_y + + + cloudpos2_x + float + cloudpos2_x + + + cloudpos2_y + float + cloudpos2_y + + + cloudpos3_x + float + cloudpos3_x + + + cloudpos3_y + float + cloudpos3_y + + + cloudpos4_x + float + cloudpos4_x + + + cloudpos4_y + float + cloudpos4_y + + + cloudpos5_x + float + cloudpos5_x + + + cloudpos5_y + float + cloudpos5_y + + + cloudpos6_x + float + cloudpos6_x + + + cloudpos6_y + float + cloudpos6_y + + + cloudpos7_x + float + cloudpos7_x + + + cloudpos7_y + float + cloudpos7_y + + + cloudpos8_x + float + cloudpos8_x + + + cloudpos8_y + float + cloudpos8_y + + + cloudpos9_x + float + cloudpos9_x + + + cloudpos9_y + float + cloudpos9_y + + + cloudpos10_x + float + cloudpos10_x + + + cloudpos10_y + float + cloudpos10_y + + + cloudpos11_x + float + cloudpos11_x + + + cloudpos11_y + float + cloudpos11_y + + + cloudpos12_x + float + cloudpos12_x + + + cloudpos12_y + float + cloudpos12_y + + + cloudpos13_x + float + cloudpos13_x + + + cloudpos13_y + float + cloudpos13_y + + + cloudpos14_x + float + cloudpos14_x + + + cloudpos14_y + float + cloudpos14_y + + + cloudpos15_x + float + cloudpos15_x + + + cloudpos15_y + float + cloudpos15_y + + + cloudpos16_x + float + cloudpos16_x + + + cloudpos16_y + float + cloudpos16_y + + + cloudpos17_x + float + cloudpos17_x + + + cloudpos17_y + float + cloudpos17_y + + + cloudpos18_x + float + cloudpos18_x + + + cloudpos18_y + float + cloudpos18_y + + + cloudpos19_x + float + cloudpos19_x + + + cloudpos19_y + float + cloudpos19_y + + + cloudpos20_x + float + cloudpos20_x + + + cloudpos20_y + float + cloudpos20_y + + + cloud_shadow_flag + int + cloud_shadow_flag + + + use_searchlight + int + use_searchlight + + + use_landing_light + int + use_landing_light + + + use_alt_landing_light + int + use_alt_landing_light + + + display_xsize + int + display_xsize + + + display_ysize + int + display_ysize + + + darkmap_enabled + int + darkmap-enabled + + + + + rembrandt_enabled + int + + rembrandt + + + + + + + + + + /sim/rendering/shaders/quality-level + /sim/rendering/shaders/model + + + 2.0 + + + + GL_ARB_shader_objects + GL_ARB_shading_language_100 + GL_ARB_vertex_shader + GL_ARB_fragment_shader + + + + + + true + + + material/active + + + material/ambient + + + material/diffuse + + + material/specular + + + material/emissive + + + material/shininess + + + material/color-mode + + + + + blend/active + + + blend/source + + + blend/destination + + + + shade-model + + + cull-face + + + rendering-hint + + + transparent + + + transparent + + + + render-bin/bin-number + + + render-bin/bin-name + + + + + 0 + + texture[0]/image + + + texture[0]/type + + + texture[0]/filter + + + texture[0]/wrap-s + + + texture[0]/wrap-t + + + texture[0]/internal-format + + + + + 1 + noise + + + + 2 + + texture[2]/image + + + texture[2]/type + + + texture[2]/filter + + + texture[2]/wrap-s + + + texture[2]/wrap-t + + + texture[2]/internal-format + + + + + 3 + + texture[3]/image + + + texture[3]/type + + + texture[3]/filter + + + texture[3]/wrap-s + + + texture[3]/wrap-t + + + texture[3]/internal-format + + + + + 4 + + texture[4]/image + + + texture[4]/type + + + texture[4]/filter + + + texture[4]/wrap-s + + + texture[4]/wrap-t + + + texture[4]/internal-format + + + + + 5 + + texture[5]/type + + + + + + + texture[5]/images + + + + + + 6 + + texture[6]/image + + + texture[6]/type + + + texture[6]/filter + + + texture[6]/wrap-s + + + texture[6]/wrap-t + + + texture[6]/internal-format + + + + + vertex-program-two-side + + + + Shaders/ubershader.vert + Shaders/include_fog.frag + Shaders/ubershader.frag + + + + BaseTex + sampler-2d + 0 + + + + ReflNoiseTex + sampler-3d + 1 + + + + NormalTex + sampler-2d + 2 + + + + LightMapTex + sampler-2d + 3 + + + + ReflMapTex + sampler-2d + 4 + + + + Environment + sampler-cube + 5 + + + + ReflGradientsTex + sampler-2d + 6 + + + + + + nmap_enabled + int + + normalmap-enabled + + + + + + nmap_dds + int + + normalmap-dds + + + + + nmap_tile + float + + normalmap-tiling + + + + + + + lightmap_enabled + int + + lightmap-enabled + + + + + lightmap_multi + int + + lightmap-multi + + + + + lightmap_r_factor + float + + lightmap-factor[0] + + + + + lightmap_r_color + float-vec3 + + lightmap-color[0] + + + + + lightmap_g_factor + float + + lightmap-factor[1] + + + + + lightmap_g_color + float-vec3 + + lightmap-color[1] + + + + + lightmap_b_factor + float + + lightmap-factor[2] + + + + + lightmap_b_color + float-vec3 + + lightmap-color[2] + + + + + lightmap_a_factor + float + + lightmap-factor[3] + + + + + lightmap_a_color + float-vec3 + + lightmap-color[3] + + + + + + refl_enabled + int + + reflection-enabled + + + + + refl_correction + float + + reflection-correction + + + + + + refl_map + int + + reflect-map-enabled + + + + + refl_dynamic + int + + reflection-dynamic + + + + + + refl_rainbow + float + + reflection-rainbow + + + + + + refl_fresnel + float + + reflection-fresnel + + + + + + refl_noise + float + + reflection-noise + + + + + + dirt_enabled + int + + dirt-enabled + + + + + dirt_multi + int + + dirt-multi + + + + + dirt_r_color + float-vec3 + + dirt-color[0] + + + + + dirt_r_factor + float + + dirt-factor[0] + + + + + dirt_g_color + float-vec3 + + dirt-color[1] + + + + + dirt_g_factor + float + + dirt-factor[1] + + + + + dirt_b_color + float-vec3 + + dirt-color[2] + + + + + dirt_b_factor + float + + dirt-factor[2] + + + + + + amb_correction + float + + ambient-correction + + + + + + lonDeg + float + + pos-lon + + + + + latDeg + float + + pos-lat + + + + + + + fogType + int + + fogtype + + + + + rembrandt_enabled + int + + rembrandt + + + + + diff --git a/Shaders/model-ALS-wingflex-organic.vert b/Shaders/model-ALS-wingflex-organic.vert new file mode 100644 index 000000000..9a5c556ac --- /dev/null +++ b/Shaders/model-ALS-wingflex-organic.vert @@ -0,0 +1,143 @@ +// -*- mode: C; -*- +// Licence: GPL v2 +// based on +// © Emilian Huminiuc and Vivian Meazza 2011 +// addition for wingflex mesh distortion by Thorsten Renk 2015 + +#version 120 + +varying vec3 rawpos; +varying vec3 VNormal; +varying vec3 VTangent; +varying vec3 VBinormal; +varying vec3 vViewVec; +varying vec3 reflVec; +varying vec3 vertVec; + +varying float alpha; + +attribute vec3 tangent; +attribute vec3 binormal; + +uniform float pitch; +uniform float roll; +uniform float hdg; +uniform float wingflex_alpha; +uniform float wingflex_trailing_alpha; +uniform int refl_dynamic; +uniform int nmap_enabled; +uniform int shader_qual; +uniform int rembrandt_enabled; + +//////Fog Include/////////// +// uniform int fogType; +// void fog_Func(int type); +//////////////////////////// + +void rotationMatrixPR(in float sinRx, in float cosRx, in float sinRy, in float cosRy, out mat4 rotmat) +{ + rotmat = mat4( cosRy , sinRx * sinRy , cosRx * sinRy, 0.0, + 0.0 , cosRx , -sinRx * cosRx, 0.0, + -sinRy, sinRx * cosRy, cosRx * cosRy , 0.0, + 0.0 , 0.0 , 0.0 , 1.0 ); +} + +void rotationMatrixH(in float sinRz, in float cosRz, out mat4 rotmat) +{ + rotmat = mat4( cosRz, -sinRz, 0.0, 0.0, + sinRz, cosRz, 0.0, 0.0, + 0.0 , 0.0 , 1.0, 0.0, + 0.0 , 0.0 , 0.0, 1.0 ); +} + +void main(void) +{ + vec4 vertex = gl_Vertex; + + float x_factor = max((abs(vertex.x) - 1.2),0); + float y_factor = max(vertex.y,0.0); + float flex_factor1 = wingflex_alpha; + float flex_factor2 = wingflex_trailing_alpha; + + if (flex_factor1<0.0) {flex_factor1 *=0.7;} + if (flex_factor2<0.0) {flex_factor1 *=0.7;} + + // basic flapping motion is parabolic + 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; + + + rawpos = vertex.xyz; + vec4 ecPosition = gl_ModelViewMatrix * vertex; + + VNormal = normalize(gl_NormalMatrix * gl_Normal); + + vec3 n = normalize(gl_Normal); + vec3 tempTangent = cross(n, vec3(1.0,0.0,0.0)); + vec3 tempBinormal = cross(n, tempTangent); + + if (nmap_enabled > 0){ + tempTangent = tangent; + tempBinormal = binormal; + } + + VTangent = normalize(gl_NormalMatrix * tempTangent); + VBinormal = normalize(gl_NormalMatrix * tempBinormal); + vec3 t = tempTangent; + vec3 b = tempBinormal; + + // Super hack: if diffuse material alpha is less than 1, assume a + // transparency animation is at work + if (gl_FrontMaterial.diffuse.a < 1.0) + alpha = gl_FrontMaterial.diffuse.a; + else + alpha = gl_Color.a; + + // Vertex in eye coordinates + vertVec = ecPosition.xyz; + vViewVec.x = dot(t, vertVec); + vViewVec.y = dot(b, vertVec); + vViewVec.z = dot(n, vertVec); + + // calculate the reflection vector + vec4 reflect_eye = vec4(reflect(vertVec, VNormal), 0.0); + vec3 reflVec_stat = normalize(gl_ModelViewMatrixInverse * reflect_eye).xyz; + if (refl_dynamic > 0){ + //prepare rotation matrix + mat4 RotMatPR; + mat4 RotMatH; + float _roll = roll; + if (_roll>90.0 || _roll < -90.0) + { + _roll = -_roll; + } + float cosRx = cos(radians(_roll)); + float sinRx = sin(radians(_roll)); + float cosRy = cos(radians(-pitch)); + float sinRy = sin(radians(-pitch)); + float cosRz = cos(radians(hdg)); + float sinRz = sin(radians(hdg)); + rotationMatrixPR(sinRx, cosRx, sinRy, cosRy, RotMatPR); + rotationMatrixH(sinRz, cosRz, RotMatH); + vec3 reflVec_dyn = (RotMatH * (RotMatPR * normalize(gl_ModelViewMatrixInverse * reflect_eye))).xyz; + + reflVec = reflVec_dyn; + } else { + reflVec = reflVec_stat; + } + + if(rembrandt_enabled < 1){ + gl_FrontColor = gl_FrontMaterial.emission + gl_Color + * (gl_LightModel.ambient + gl_LightSource[0].ambient); + } else { + gl_FrontColor = gl_Color; + } + gl_Position = gl_ModelViewProjectionMatrix * vertex; + //gl_Position = ftransform(); + gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; +}