Wingflex Shader

From FlightGear wiki
Jump to navigation Jump to search

The Wingflex Shader, used in the Wingflex Effect displaces the vertices of the object it is applied to in order to achieve a realistic-looking flexing wing.

There are two "modes" available, one is the organic mode used in the Dragon, the other one, introduced in February 2020 also allows the shader to be applied to "normal" wings.

Syntax

Organic

The following snippets are taken from the Dragon.

The effect file

<?xml version="1.0" encoding="utf-8"?>

<PropertyList>
  <name>wingflex</name>
  <inherits-from>Effects/model-wingflex</inherits-from>
  <parameters>
	  <wingflex-type>1</wingflex-type> <!-- 0 = non-organic; 1 = organic -->
    <wingflex-alpha><use>/fdm/jsbsim/systems/animation/wing-alpha-animation-deg</use></wingflex-alpha>
    <wingflex-trailing-alpha><use>/fdm/jsbsim/systems/animation/wing-alpha-trailing-animation-deg</use></wingflex-trailing-alpha>
    <wingsweep-factor><use>/fdm/jsbsim/systems/animation/wingsweep-factor</use></wingsweep-factor>

    <normalmap-enabled type="int"> 1 </normalmap-enabled>
    <normalmap-dds type="int"> 0 </normalmap-dds>
    <normalmap-tiling type="float"> 1.0 </normalmap-tiling>
    <texture n="2">
      <image>Aircraft/Pterosaur/Models/Dragon/body_normals.png</image>
      <filter>linear-mipmap-linear</filter>
      <wrap-s>clamp</wrap-s>
      <wrap-t>clamp</wrap-t>
      <internal-format>normalized</internal-format>
    </texture>
  </parameters>

  <generate>
    <tangent type="int">6</tangent>
    <binormal type="int">7</binormal>
  </generate>

  <technique n="4">
   <pass>
     <program>
       <attribute>
         <name>tangent</name>
         <index>6</index>
       </attribute>
       <attribute>
         <name>binormal</name>
         <index>7</index>
       </attribute>
     </program>
   </pass>
  </technique>

  <technique n="7">
    <pass>
      <program>
        <attribute>
          <name>tangent</name>
          <index>6</index>
        </attribute>
        <attribute>
          <name>binormal</name>
          <index>7</index>
        </attribute>
      </program>
    </pass>
  </technique>

  <technique n="9">
    <pass>
      <program>
        <attribute>
          <name>tangent</name>
          <index>6</index>
        </attribute>
        <attribute>
          <name>binormal</name>
          <index>7</index>
        </attribute>
      </program>
    </pass>
  </technique>

</PropertyList>

The aircraft's model .xml

 
<effect>
   <inherits-from>Aircraft/Pterosaur/Models/Dragon/Effects/wingflex</inherits-from>
   <object-name>WingL</object-name>
   <object-name>WingR</object-name>
 </effect>

Non-organic

The following snippets are taken from the Schleicher Ka 6.

The effect file

(here: Aircraft/[YOUR AIRCRAFT]/Models/Effects/wingflex.eff)

 <?xml version="1.0" encoding="utf-8"?>

<PropertyList>
	<name>wingflex</name>
	<inherits-from>Effects/model-wingflex</inherits-from> <!-- inherit from the wingflex effect, this includes the wingflex shader. The effect itself inherits from model-default -->
	<parameters>
		<wingflex-type>0</wingflex-type> <!-- 0 = non-organic; 1 = organic -->
		<wingflex-z><use>/sim/systems/wingflexer/z-m</use></wingflex-z> <!-- Set this property to one that gives the displacement of the wingtips, in z-direction, in meters-->
		<body-width>0.428</body-width> <!-- This sets an offset, so that the wing root is not yet displaced. Set this to be the width of your aircraft's body. (in m) -->
		<wing-span>15.0</wing-span> <!-- Self-explanatory, the wing span -->
		
		<normalmap-enabled type="int"> 1 </normalmap-enabled> <!-- if you want to include a normal map, set this to 1, else 0 -->
		<normalmap-dds type="int"> 0 </normalmap-dds>
		<normalmap-tiling type="float"> 1.0 </normalmap-tiling>
		<texture n="2">
			<image>Aircraft/Ka6/Models/Effects/normalmap.png</image>
			<filter>linear-mipmap-linear</filter>
			<wrap-s>clamp</wrap-s>
			<wrap-t>clamp</wrap-t>
			<internal-format>normalized</internal-format>
		</texture>
	</parameters>

	<generate>
		<tangent type="int">6</tangent>
		<binormal type="int">7</binormal>
	</generate>

	<technique n="4">
		<pass>
			<program>
				<attribute>
					<name>tangent</name>
					<index>6</index>
				</attribute>
				<attribute>
					<name>binormal</name>
					<index>7</index>
				</attribute>
			</program>
		</pass>
	</technique>

	<technique n="7">
		<pass>
			<program>
				<attribute>
					<name>tangent</name>
					<index>6</index>
					</attribute>
					<attribute>
					<name>binormal</name>
					<index>7</index>
				</attribute>
			</program>
		</pass>
	</technique>

	<technique n="9">
		<pass>
			<program>
				<attribute>
					<name>tangent</name>
					<index>6</index>
					</attribute>
					<attribute>
					<name>binormal</name>
					<index>7</index>
				</attribute>
			</program>
		</pass>
	</technique>

</PropertyList>

The aircraft's model .xml

Applying the effect
<effect>
	<inherits-from>Models/Effects/wingflex</inherits-from>
	<object-name>wings</object-name>
	<object-name>speedbrakes</object-name>
</effect>
Usage of the rotation function
<effect>
	<parameters>
		<rotation-rad><use>fdm/jsbsim/fcs/left-aileron-pos-rad</use></rotation-rad> <!-- A property given the rotation in radians -->
<!-- The following values correspond to the values you would set for a rotation animation. 
E.g., <rotation-x1> should be the same as the <x1-m> inside the <axis> tag of a rotation animation-->
		<rotation-x1>-1.14745</rotation-x1>
		<rotation-y1>-4.59431</rotation-y1>
		<rotation-z1>0.34113</rotation-z1>
		<rotation-x2>-1.39544</rotation-x2>
		<rotation-y2>-6.74625</rotation-y2>
		<rotation-z2>0.46865</rotation-z2>
	</parameters>
	<inherits-from>Models/Effects/wingflex</inherits-from> <!-- point this to the location of the file shown above -->
	<object-name>aileron.L</object-name> <!-- The object to apply this rotation to -->
</effect>

Related content

Wiki articles

Source code