// new propeller

cbuffer _Globals : register(b0)
{
  float4 g_vParams : packoffset(c0);
  float4 g_aUVShiftData[64] : packoffset(c1);
  float4 bones[192] : packoffset(c65);

  struct
  {
    float4 vPlane;
    float4 vSettings;
  } g_ClipPlane : packoffset(c257);

  float4x4 g_mCloudsShadowsSpace : packoffset(c259);
  float4 g_vCloudsShadowDesc : packoffset(c263);
  float4 specColor : packoffset(c264);
  float4 ControlData : packoffset(c265);
  float4 difColor : packoffset(c266);
  float4 ambient : packoffset(c267);
  float4 lightCount : packoffset(c268);
  float4 g_avLightPos[2] : packoffset(c269);
  float4 g_avLightColor[2] : packoffset(c271);
  float4 g_avConeDir[2] : packoffset(c273);
  float4 g_vAmbientSettings : packoffset(c275);

  struct
  {
    float4 vDesc;
    float4 vFogLayerPlane;
    float4 vFogLayerColor;
    float4 vFogLayerSettings;
    float4 vFogColor;
    float4 vFogDistance;
  } g_FogDesc : packoffset(c276);

  float4x4 g_mViewProj : packoffset(c282);
  float4 g_vCamPos : packoffset(c286);
  float4 g_vSkyColor : packoffset(c287);
  float4 g_vFogK : packoffset(c288);
}



// 3Dmigoto declarations
#define cmp -
Texture1D<float4> IniParams : register(t120);
// Texture2D<float4> StereoParams : register(t125);


void main( 
  float3 v0 : POSITION0,
  float3 v1 : NORMAL0,
  float2 v2 : TEXCOORD0,
  float v3 : BLENDINDICES0,
  out float4 o0 : SV_Position0,
  out float4 o1 : TEXCOORD0,
  out float4 o2 : TEXCOORD1,
  out float4 o3 : TEXCOORD2,
  out float4 o4 : TEXCOORD3,
  out float4 o5 : TEXCOORD4,
  out float4 o6 : COLOR0,
  out float4 o7 : COLOR1,
  out float o8 : SV_ClipDistance0)
{
  float4 r0,r1,r2,r3,r4,r5,r6,r7,r8,r9;
  uint4 bitmask, uiDest;
  float4 fDest;

  float flagOnOff = IniParams.Load(int2(5, 0)).z; // flag on off for propeller
  float zoomFactor = IniParams.Load(0).w; // zoom factor
  r0.x = 3 * v3.x;
  r0.x = (uint)r0.x;
  r1.xyz = v0.xyz;
  r1.w = 1;
  r2.x = dot(r1.xyzw, bones[r0.x].xyzw);
  r0.yz = v3.xx * float2(3,3) + float2(1,2);
  r0.yz = (uint2)r0.yz;
  r2.y = dot(r1.xyzw, bones[r0.y].xyzw);
  r2.z = dot(r1.xyzw, bones[r0.z].xyzw);
  r2.w = 1;
  o0.x = dot(r2.xyzw, g_mViewProj._m00_m10_m20_m30)*zoomFactor;
  o0.y = dot(r2.xyzw, g_mViewProj._m01_m11_m21_m31)*zoomFactor;
  o0.z = dot(r2.xyzw, g_mViewProj._m02_m12_m22_m32);
  o0.w = dot(r2.xyzw, g_mViewProj._m03_m13_m23_m33);
  r0.w = cmp(0.5 < g_ClipPlane.vSettings.x);
  if (r0.w != 0) {
    o8.x = dot(g_ClipPlane.vPlane.xyzw, r2.xyzw);
  } else {
    o8.x = 1;
  }
  o3.x = dot(r2.xyzw, g_mCloudsShadowsSpace._m00_m10_m20_m30);
  r0.w = dot(r2.xyzw, g_mCloudsShadowsSpace._m01_m11_m21_m31);
  o3.y = dot(r2.xyzw, g_mCloudsShadowsSpace._m02_m12_m22_m32);
  r0.w = -g_vCloudsShadowDesc.x + r0.w;
  o3.z = saturate(-r0.w * g_vCloudsShadowDesc.y + 1);
  r1.x = dot(v1.xyz, bones[r0.x].xyz);
  r1.y = dot(v1.xyz, bones[r0.y].xyz);
  r1.z = dot(v1.xyz, bones[r0.z].xyz);
  r0.w = dot(r1.xyz, r1.xyz);
  r0.w = rsqrt(r0.w);
  r1.xyz = r1.xyz * r0.www;
  r3.z = bones[r0.x].w;
  r3.x = bones[r0.y].w;
  r3.y = bones[r0.z].w;
  r0.xyz = -r3.xyz + r2.yzx;
  r0.w = dot(r0.xyz, r0.xyz);
  r0.w = sqrt(r0.w);
  r3.xyz = r1.zxy * r0.xyz;
  r0.xyz = r1.yzx * r0.yzx + -r3.xyz;
  r1.w = dot(r0.xyz, r0.xyz);
  r1.w = rsqrt(r1.w);
  r0.xyz = r1.www * r0.xyz;
  r1.w = -0.5 + r0.w;
  r1.w = saturate(10 * r1.w);
  o5.xyz = r1.www * r0.xyz;
  r0.xyz = g_vCamPos.xyz + -r2.xyz;
  r1.w = dot(r0.xyz, r0.xyz);
  r1.w = rsqrt(r1.w);
  r3.xyz = r1.www * r0.xyz;
  r2.w = (int)lightCount.x;
  r4.xyzw = float4(0,0,0,0);
  r5.xyz = float3(0,0,0);
  r6.xyz = float3(0,0,0);
  r3.w = 0;
  while (true) {
    r5.w = cmp((int)r3.w >= (int)r2.w);
    if (r5.w != 0) break;
    r7.xy = cmp(g_avLightColor[r3.w].xy >= float2(100,100));
    if (r7.x != 0) {
      r5.w = g_avLightColor[r3.w].x + -100;
    } else {
      r5.w = g_avLightColor[r3.w].x;
    }
    if (r7.y != 0) {
      r6.w = g_avLightColor[r3.w].y + -100;
    } else {
      r6.w = g_avLightColor[r3.w].y;
    }
    r7.x = cmp(1 < g_avLightPos[r3.w].w);
    if (r7.x != 0) {
      r7.xyz = g_avLightPos[r3.w].xyz + -r2.xyz;
      r7.w = dot(r7.xyz, r7.xyz);
      r8.x = sqrt(r7.w);
      r8.xyz = r7.xyz / r8.xxx;
      r7.x = r7.w * g_avLightColor[r3.w].w + 1;
      r7.x = 1 / r7.x;
      r7.x = -0.100000001 + r7.x;
      r7.x = saturate(1.11111116 * r7.x);
      r7.y = cmp(2 < g_avLightPos[r3.w].w);
      if (r7.y != 0) {
        r7.y = g_avLightPos[r3.w].w + -3;
        r7.z = dot(r8.xyz, g_avConeDir[r3.w].xyz);
        r7.w = 1 + -abs(r7.z);
        r7.w = sqrt(r7.w);
        r9.x = abs(r7.z) * -0.0187292993 + 0.0742610022;
        r9.x = r9.x * abs(r7.z) + -0.212114394;
        r9.x = r9.x * abs(r7.z) + 1.57072878;
        r9.y = r9.x * r7.w;
        r9.y = r9.y * -2 + 3.14159274;
        r7.z = cmp(r7.z < -r7.z);
        r7.z = r7.z ? r9.y : 0;
        r7.z = r9.x * r7.w + r7.z;
        r7.w = cmp(r7.z < r7.y);
        if (r7.w != 0) {
          r7.w = frac(g_avConeDir[r3.w].w);
          r7.y = r7.z / r7.y;
          r7.y = r7.y + -r7.w;
          r7.z = 1 + -r7.w;
          r7.y = saturate(r7.y / r7.z);
          r7.y = 1 + -r7.y;
        } else {
          r7.y = 0;
        }
        r7.x = r7.x * r7.y;
      }
    } else {
      r8.xyz = -g_avLightPos[r3.w].xyz;
      r7.x = 1;
    }
    r7.y = dot(r8.xyz, r1.xyz);
    r7.y = max(0, r7.y);
    r9.x = r7.y * r5.w;
    r9.y = r7.y * r6.w;
    r9.z = g_avLightColor[r3.w].z * r7.y;
    r7.yzw = r9.xyz * r7.xxx;
    if (r3.w == 0) {
      r8.w = sqrt(r7.x);
      r4.xyzw = r8.xyzw;
      r5.xyz = r7.yzw;
    } else {
      r6.xyz = r9.xyz * r7.xxx + r6.xyz;
    }
    r3.w = (int)r3.w + 1;
  }
  o6.xyz = r5.xyz;
  o7.xyz = r6.xyz;
  r2.x = dot(r3.xyz, r1.xyz);
  r2.y = 50 * difColor.x;
  r2.x = log2(r2.x);
  r2.x = r2.y * r2.x;
  r2.x = exp2(r2.x);
  o6.w = min(1, r2.x);
  r0.xyz = r0.xyz * r1.www + r4.xyz;
  r0.xyz = float3(0.5,0.5,0.5) * r0.xyz;
  r1.w = dot(r0.xyz, r0.xyz);
  r1.w = rsqrt(r1.w);
  o2.xyz = r1.www * r0.xyz;
  o2.w = r4.w;
  o5.w = r0.w;
  o7.w = 0;
  o4.xyz = r1.xyz;
  o1.xy = v2.xy;
  
  if (flagOnOff == 1) o0.w=0;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//   using 3Dmigoto v1.2.57 on Mon Sep 04 22:32:12 2017
//
//
// Buffer Definitions: 
//
// cbuffer $Globals
// {
//
//   float4 g_vParams;                  // Offset:    0 Size:    16 [unused]
//   float4 g_aUVShiftData[64];         // Offset:   16 Size:  1024 [unused]
//   float4 bones[192];                 // Offset: 1040 Size:  3072
//   
//   struct
//   {
//       
//       float4 vPlane;                 // Offset: 4112
//       float4 vSettings;              // Offset: 4128
//
//   } g_ClipPlane;                     // Offset: 4112 Size:    32
//   float4x4 g_mCloudsShadowsSpace;    // Offset: 4144 Size:    64
//   float4 g_vCloudsShadowDesc;        // Offset: 4208 Size:    16
//   float4 specColor;                  // Offset: 4224 Size:    16 [unused]
//   float4 ControlData;                // Offset: 4240 Size:    16 [unused]
//   float4 difColor;                   // Offset: 4256 Size:    16
//   float4 ambient;                    // Offset: 4272 Size:    16 [unused]
//   float4 lightCount;                 // Offset: 4288 Size:    16
//   float4 g_avLightPos[2];            // Offset: 4304 Size:    32
//   float4 g_avLightColor[2];          // Offset: 4336 Size:    32
//   float4 g_avConeDir[2];             // Offset: 4368 Size:    32
//   float4 g_vAmbientSettings;         // Offset: 4400 Size:    16 [unused]
//   
//   struct
//   {
//       
//       float4 vDesc;                  // Offset: 4416
//       float4 vFogLayerPlane;         // Offset: 4432
//       float4 vFogLayerColor;         // Offset: 4448
//       float4 vFogLayerSettings;      // Offset: 4464
//       float4 vFogColor;              // Offset: 4480
//       float4 vFogDistance;           // Offset: 4496
//
//   } g_FogDesc;                       // Offset: 4416 Size:    96 [unused]
//   float4x4 g_mViewProj;              // Offset: 4512 Size:    64
//   float4 g_vCamPos;                  // Offset: 4576 Size:    16
//   float4 g_vSkyColor;                // Offset: 4592 Size:    16 [unused]
//   float4 g_vFogK;                    // Offset: 4608 Size:    16 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// $Globals                          cbuffer      NA          NA    0        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// POSITION                 0   xyz         0     NONE   float   xyz 
// NORMAL                   0   xyz         1     NONE   float   xyz 
// TEXCOORD                 0   xy          2     NONE   float   xy  
// BLENDINDICES             0   x           3     NONE   float   x   
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Position              0   xyzw        0      POS   float   xyzw
// TEXCOORD                 0   xy          1     NONE   float   xy  
// TEXCOORD                 1   xyzw        2     NONE   float   xyzw
// TEXCOORD                 2   xyz         3     NONE   float   xyz 
// TEXCOORD                 3   xyz         4     NONE   float   xyz 
// TEXCOORD                 4   xyzw        5     NONE   float   xyzw
// COLOR                    0   xyzw        6     NONE   float   xyzw
// COLOR                    1   xyzw        7     NONE   float   xyzw
// SV_ClipDistance          0   x           8  CLIPDST   float   x   
//
vs_4_0
dcl_constantbuffer cb0[287], dynamicIndexed
dcl_input v0.xyz
dcl_input v1.xyz
dcl_input v2.xy
dcl_input v3.x
dcl_output_siv o0.xyzw, position
dcl_output o1.xy
dcl_output o2.xyzw
dcl_output o3.xyz
dcl_output o4.xyz
dcl_output o5.xyzw
dcl_output o6.xyzw
dcl_output o7.xyzw
dcl_output_siv o8.x, clip_distance
dcl_temps 10
mul r0.x, v3.x, l(3.000000)
ftou r0.x, r0.x
mov r1.xyz, v0.xyzx
mov r1.w, l(1.000000)
dp4 r2.x, r1.xyzw, cb0[r0.x + 65].xyzw
mad r0.yz, v3.xxxx, l(0.000000, 3.000000, 3.000000, 0.000000), l(0.000000, 1.000000, 2.000000, 0.000000)
ftou r0.yz, r0.yyzy
dp4 r2.y, r1.xyzw, cb0[r0.y + 65].xyzw
dp4 r2.z, r1.xyzw, cb0[r0.z + 65].xyzw
mov r2.w, l(1.000000)
dp4 o0.x, r2.xyzw, cb0[282].xyzw
dp4 o0.y, r2.xyzw, cb0[283].xyzw
dp4 o0.z, r2.xyzw, cb0[284].xyzw
dp4 o0.w, r2.xyzw, cb0[285].xyzw
lt r0.w, l(0.500000), cb0[258].x
if_nz r0.w
  dp4 o8.x, cb0[257].xyzw, r2.xyzw
else 
  mov o8.x, l(1.000000)
endif 
dp4 o3.x, r2.xyzw, cb0[259].xyzw
dp4 r0.w, r2.xyzw, cb0[260].xyzw
dp4 o3.y, r2.xyzw, cb0[261].xyzw
add r0.w, r0.w, -cb0[263].x
mad_sat o3.z, -r0.w, cb0[263].y, l(1.000000)
dp3 r1.x, v1.xyzx, cb0[r0.x + 65].xyzx
dp3 r1.y, v1.xyzx, cb0[r0.y + 65].xyzx
dp3 r1.z, v1.xyzx, cb0[r0.z + 65].xyzx
dp3 r0.w, r1.xyzx, r1.xyzx
rsq r0.w, r0.w
mul r1.xyz, r0.wwww, r1.xyzx
mov r3.z, cb0[r0.x + 65].w
mov r3.x, cb0[r0.y + 65].w
mov r3.y, cb0[r0.z + 65].w
add r0.xyz, r2.yzxy, -r3.xyzx
dp3 r0.w, r0.xyzx, r0.xyzx
sqrt r0.w, r0.w
mul r3.xyz, r0.xyzx, r1.zxyz
mad r0.xyz, r1.yzxy, r0.yzxy, -r3.xyzx
dp3 r1.w, r0.xyzx, r0.xyzx
rsq r1.w, r1.w
mul r0.xyz, r0.xyzx, r1.wwww
add r1.w, r0.w, l(-0.500000)
mul_sat r1.w, r1.w, l(10.000000)
mul o5.xyz, r0.xyzx, r1.wwww
add r0.xyz, -r2.xyzx, cb0[286].xyzx
dp3 r1.w, r0.xyzx, r0.xyzx
rsq r1.w, r1.w
mul r3.xyz, r0.xyzx, r1.wwww
ftoi r2.w, cb0[268].x
mov r4.xyzw, l(0,0,0,0)
mov r5.xyz, l(0,0,0,0)
mov r6.xyz, l(0,0,0,0)
mov r3.w, l(0)
loop 
  ige r5.w, r3.w, r2.w
  breakc_nz r5.w
  ge r7.xy, cb0[r3.w + 271].xyxx, l(100.000000, 100.000000, 0.000000, 0.000000)
  if_nz r7.x
    add r5.w, l(-100.000000), cb0[r3.w + 271].x
  else 
    mov r5.w, cb0[r3.w + 271].x
  endif 
  if_nz r7.y
    add r6.w, l(-100.000000), cb0[r3.w + 271].y
  else 
    mov r6.w, cb0[r3.w + 271].y
  endif 
  lt r7.x, l(1.000000), cb0[r3.w + 269].w
  if_nz r7.x
    add r7.xyz, -r2.xyzx, cb0[r3.w + 269].xyzx
    dp3 r7.w, r7.xyzx, r7.xyzx
    sqrt r8.x, r7.w
    div r8.xyz, r7.xyzx, r8.xxxx
    mad r7.x, r7.w, cb0[r3.w + 271].w, l(1.000000)
    div r7.x, l(1.000000, 1.000000, 1.000000, 1.000000), r7.x
    add r7.x, r7.x, l(-0.100000)
    mul_sat r7.x, r7.x, l(1.11111116)
    lt r7.y, l(2.000000), cb0[r3.w + 269].w
    if_nz r7.y
      add r7.y, l(-3.000000), cb0[r3.w + 269].w
      dp3 r7.z, r8.xyzx, cb0[r3.w + 273].xyzx
      add r7.w, -|r7.z|, l(1.000000)
      sqrt r7.w, r7.w
      mad r9.x, |r7.z|, l(-0.0187292993), l(0.074261)
      mad r9.x, r9.x, |r7.z|, l(-0.212114394)
      mad r9.x, r9.x, |r7.z|, l(1.57072878)
      mul r9.y, r7.w, r9.x
      mad r9.y, r9.y, l(-2.000000), l(3.14159274)
      lt r7.z, r7.z, -r7.z
      and r7.z, r7.z, r9.y
      mad r7.z, r9.x, r7.w, r7.z
      lt r7.w, r7.z, r7.y
      if_nz r7.w
        frc r7.w, cb0[r3.w + 273].w
        div r7.y, r7.z, r7.y
        add r7.y, -r7.w, r7.y
        add r7.z, -r7.w, l(1.000000)
        div_sat r7.y, r7.y, r7.z
        add r7.y, -r7.y, l(1.000000)
      else 
        mov r7.y, l(0)
      endif 
      mul r7.x, r7.y, r7.x
    endif 
  else 
    mov r8.xyz, -cb0[r3.w + 269].xyzx
    mov r7.x, l(1.000000)
  endif 
  dp3 r7.y, r8.xyzx, r1.xyzx
  max r7.y, r7.y, l(0.000000)
  mul r9.x, r5.w, r7.y
  mul r9.y, r6.w, r7.y
  mul r9.z, r7.y, cb0[r3.w + 271].z
  mul r7.yzw, r7.xxxx, r9.xxyz
  if_z r3.w
    sqrt r8.w, r7.x
    mov r4.xyzw, r8.xyzw
    mov r5.xyz, r7.yzwy
  else 
    mad r6.xyz, r9.xyzx, r7.xxxx, r6.xyzx
  endif 
  iadd r3.w, r3.w, l(1)
endloop 
mov o6.xyz, r5.xyzx
mov o7.xyz, r6.xyzx
dp3 r2.x, r3.xyzx, r1.xyzx
mul r2.y, cb0[266].x, l(50.000000)
log r2.x, r2.x
mul r2.x, r2.x, r2.y
exp r2.x, r2.x
min o6.w, r2.x, l(1.000000)
mad r0.xyz, r0.xyzx, r1.wwww, r4.xyzx
mul r0.xyz, r0.xyzx, l(0.500000, 0.500000, 0.500000, 0.000000)
dp3 r1.w, r0.xyzx, r0.xyzx
rsq r1.w, r1.w
mul o2.xyz, r0.xyzx, r1.wwww
mov o2.w, r4.w
mov o5.w, r0.w
mov o7.w, l(0)
mov o4.xyz, r1.xyzx
mov o1.xy, v2.xyxx
ret 
// Approximately 143 instruction slots used

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
