//Sky and water PS.
// ---- Created with 3Dmigoto v1.3.6 on Sat Mar 17 09:09:20 2018

cbuffer PS_CONSTANT_BUFFER : register(b0)
{

  struct
  {
    float4 vLightCol0;
    float4 vLightCol1;
    float4 vLightCol2;
    float4 vLightCol3;
    float4 vLightPosX;
    float4 vLightPosY;
    float4 vLightPosZ;
    float4 vLightFactor;
    float4 vLightAmb;
  } lightAttr : packoffset(c0);

  float4 vMaterialDiffuse : packoffset(c9);
  float4 vTC0ScaleOffset : packoffset(c10);
  float4 vFogColor : packoffset(c11);
  float4 vFogParameter1020 : packoffset(c12);
  float4 vFogParameter1021 : packoffset(c13);
  float fFogModification : packoffset(c14);
  int iBlendMode : packoffset(c14.y);
  int alpha_test : packoffset(c14.z);
  int alpha_test_func : packoffset(c14.w);
  float alpha_ref : packoffset(c15);
}

SamplerState sampler_TexMain_s : register(s0);
Texture2D<float4> TexMain : register(t0);


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


void main(
  float4 v0 : SV_POSITION0,
  float3 v1 : TEXCOORD1,
  float4 v2 : COLOR0,
  float4 v3 : TEXCOORD0,
  float4 v4 : TEXCOORD2,
  float4 v5 : TEXCOORD3,
  out float4 o0 : SV_Target0)
{
  float4 r0,r1,r2,r3,r4,r5;
  uint4 bitmask, uiDest;
  float4 fDest;

  float4 iniparams = IniParams.Load(0);
  float4 iniparams7 = IniParams.Load(int2(7,0));
  
  r0.x = dot(v1.xyz, v1.xyz);
  r0.x = rsqrt(r0.x);
  r0.xyz = v1.xyz * r0.xxx;
  r1.xy = vTC0ScaleOffset.zw + v3.xy;
  r1.xy = vTC0ScaleOffset.xy * r1.xy;
  r2.xyz = lightAttr.vLightPosX.xyz + -v4.xxx;
  r3.xyz = lightAttr.vLightPosY.xyz + -v4.yyy;
  r4.xyz = lightAttr.vLightPosZ.xyz + -v4.zzz;
  r5.xyz = r3.xyz * r3.xyz;
  r5.xyz = r2.xyz * r2.xyz + r5.xyz;
  r5.xyz = r4.xyz * r4.xyz + r5.xyz;
  r5.xyz = -r5.xyz * lightAttr.vLightFactor.xyz + float3(1,1,1);
  r5.xyz = max(float3(0,0,0), r5.xyz);
  r3.xyz = r3.xyz * r0.yyy;
  r0.xyw = r0.xxx * r2.xyz + r3.xyz;
  r0.xyz = r0.zzz * r4.xyz + r0.xyw;
  r2.xyz = cmp(r0.xyz >= float3(0,0,0));
  r2.xyz = r2.xyz ? float3(1,1,1) : 0;
  r0.xyz = r2.xyz * r0.xyz;
  r0.xyz = r5.xyz * r0.xyz;
  r2.xyz = lightAttr.vLightCol1.xyz * r0.yyy;
  r0.xyw = lightAttr.vLightCol0.xyz * r0.xxx + r2.xyz;
  r0.xyz = lightAttr.vLightCol2.xyz * r0.zzz + r0.xyw;
  r0.xyz = lightAttr.vLightCol3.xyz + r0.xyz;
  r0.xyz = v2.xyz * r0.xyz;
  r0.xyz = saturate(vMaterialDiffuse.xyz * r0.xyz);
  r0.w = cmp(iBlendMode < 2);
  r2.xyz = r0.xyz + r0.xyz;
  r0.xyz = r0.www ? r2.xyz : r0.xyz;
  r1.xyzw = TexMain.Sample(sampler_TexMain_s, r1.xy).xyzw;
  r0.w = lightAttr.vLightAmb.w;
  r2.xyzw = r1.xyzw * r0.xyzw;
  r3.xy = cmp(iBlendMode == int2(1,2));
  r0.xyz = r0.xyz * r1.xyz + lightAttr.vLightAmb.www;
  r0.w = lightAttr.vLightAmb.w + r1.w;
  r4.xyz = r0.xyz;
  r4.w = r1.w;
  r0.xyzw = r3.yyyy ? r0.xyzw : r4.xyzw;
  r0.xyzw = r3.xxxx ? r1.xyzw : r0.xyzw;
  r0.xyzw = iBlendMode ? r0.xyzw : r2.xyzw;
  r1.x = vFogParameter1021.w / v5.w;
  r1.x = vFogParameter1020.w + r1.x;
  r1.x = saturate(fFogModification + r1.x);
  
  //My bloom. Only applied to the sky texture.
  if (iniparams.w!=1 && iniparams7.w==20)
  {
	r0.xyz=pow(r0.xyz, iniparams.w*(1-r0.xyz));
  }
  
  r0.xyz = -vFogColor.xyz + r0.xyz;
  o0.xyz = r1.xxx * r0.xyz + vFogColor.xyz;
  if (alpha_test != 0) {
    r0.x = cmp(alpha_test_func == 1);
    if (r0.x != 0) {
      r0.x = -1;
    } else {
      r0.y = cmp(alpha_test_func == 2);
      if (r0.y != 0) {
        r0.y = cmp(r0.w < alpha_ref);
        r0.x = r0.y ? 1 : -1;
      } else {
        r0.y = cmp(alpha_test_func == 3);
        if (r0.y != 0) {
          r0.y = cmp(r0.w == alpha_ref);
          r0.x = r0.y ? 1 : -1;
        } else {
          r0.y = cmp(alpha_ref >= r0.w);
          r0.z = cmp(alpha_ref < r0.w);
          r0.yz = r0.yz ? float2(1.40129846e-045,1.40129846e-045) : float2(-1,-1);
          r1.x = cmp(r0.w != alpha_ref);
          r2.xyzw = cmp(alpha_test_func == int4(4,5,6,7));
          r1.y = cmp(r0.w >= alpha_ref);
          r1.xy = r1.xy ? float2(1,1) : float2(-1,-1);
          r1.y = r2.w ? r1.y : 1;
          r1.x = r2.z ? r1.x : r1.y;
          r0.z = r2.y ? r0.z : r1.x;
          r0.x = r2.x ? r0.y : r0.z;
        }
      }
    }
    r0.x = (int)r0.x;
    r0.x = cmp(r0.x < 0);
    if (r0.x != 0) discard;
  }
  o0.w = r0.w;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 6.3.9600.16384
//
//   using 3Dmigoto v1.3.6 on Sat Mar 17 09:09:20 2018
//
//
// Buffer Definitions:
//
// cbuffer PS_CONSTANT_BUFFER
// {
//
//   struct LightAttr
//   {
//
//       float4 vLightCol0;             // Offset:    0
//       float4 vLightCol1;             // Offset:   16
//       float4 vLightCol2;             // Offset:   32
//       float4 vLightCol3;             // Offset:   48
//       float4 vLightPosX;             // Offset:   64
//       float4 vLightPosY;             // Offset:   80
//       float4 vLightPosZ;             // Offset:   96
//       float4 vLightFactor;           // Offset:  112
//       float4 vLightAmb;              // Offset:  128
//
//   } lightAttr;                       // Offset:    0 Size:   144
//   float4 vMaterialDiffuse;           // Offset:  144 Size:    16
//   float4 vTC0ScaleOffset;            // Offset:  160 Size:    16
//   float4 vFogColor;                  // Offset:  176 Size:    16
//   float4 vFogParameter1020;          // Offset:  192 Size:    16
//   float4 vFogParameter1021;          // Offset:  208 Size:    16
//   float fFogModification;            // Offset:  224 Size:     4
//   int iBlendMode;                    // Offset:  228 Size:     4
//   int alpha_test;                    // Offset:  232 Size:     4
//   int alpha_test_func;               // Offset:  236 Size:     4
//   float alpha_ref;                   // Offset:  240 Size:     4
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// sampler_TexMain                   sampler      NA          NA    0        1
// TexMain                           texture  float4          2d    0        1
// PS_CONSTANT_BUFFER                cbuffer      NA          NA    0        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float
// TEXCOORD                 1   xyz         1     NONE   float   xyz
// COLOR                    0   xyzw        2     NONE   float   xyz
// TEXCOORD                 0   xy          3     NONE   float   xy
// TEXCOORD                 2   xyz         4     NONE   float   xyz
// TEXCOORD                 3   xyzw        5     NONE   float      w
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target                0   xyzw        0   TARGET   float   xyzw
//
ps_5_0
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb0[16], immediateIndexed
dcl_sampler s0, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_input_ps linear v1.xyz
dcl_input_ps linear v2.xyz
dcl_input_ps linear v3.xy
dcl_input_ps linear v4.xyz
dcl_input_ps linear v5.w
dcl_output o0.xyzw
dcl_temps 6
dp3 r0.x, v1.xyzx, v1.xyzx
rsq r0.x, r0.x
mul r0.xyz, r0.xxxx, v1.xyzx
add r1.xy, v3.xyxx, cb0[10].zwzz
mul r1.xy, r1.xyxx, cb0[10].xyxx
add r2.xyz, -v4.xxxx, cb0[4].xyzx
add r3.xyz, -v4.yyyy, cb0[5].xyzx
add r4.xyz, -v4.zzzz, cb0[6].xyzx
mul r5.xyz, r3.xyzx, r3.xyzx
mad r5.xyz, r2.xyzx, r2.xyzx, r5.xyzx
mad r5.xyz, r4.xyzx, r4.xyzx, r5.xyzx
mad r5.xyz, -r5.xyzx, cb0[7].xyzx, l(1.000000, 1.000000, 1.000000, 0.000000)
max r5.xyz, r5.xyzx, l(0.000000, 0.000000, 0.000000, 0.000000)
mul r3.xyz, r0.yyyy, r3.xyzx
mad r0.xyw, r0.xxxx, r2.xyxz, r3.xyxz
mad r0.xyz, r0.zzzz, r4.xyzx, r0.xywx
ge r2.xyz, r0.xyzx, l(0.000000, 0.000000, 0.000000, 0.000000)
and r2.xyz, r2.xyzx, l(0x3f800000, 0x3f800000, 0x3f800000, 0)
mul r0.xyz, r0.xyzx, r2.xyzx
mul r0.xyz, r0.xyzx, r5.xyzx
mul r2.xyz, r0.yyyy, cb0[1].xyzx
mad r0.xyw, cb0[0].xyxz, r0.xxxx, r2.xyxz
mad r0.xyz, cb0[2].xyzx, r0.zzzz, r0.xywx
add r0.xyz, r0.xyzx, cb0[3].xyzx
mul r0.xyz, r0.xyzx, v2.xyzx
mul_sat r0.xyz, r0.xyzx, cb0[9].xyzx
ilt r0.w, cb0[14].y, l(2)
add r2.xyz, r0.xyzx, r0.xyzx
movc r0.xyz, r0.wwww, r2.xyzx, r0.xyzx
sample_indexable(texture2d)(float,float,float,float) r1.xyzw, r1.xyxx, t0.xyzw, s0
mov r0.w, cb0[8].w
mul r2.xyzw, r0.xyzw, r1.xyzw
ieq r3.xy, cb0[14].yyyy, l(1, 2, 0, 0)
mad r0.xyz, r0.xyzx, r1.xyzx, cb0[8].wwww
add r0.w, r1.w, cb0[8].w
mov r4.xyz, r0.xyzx
mov r4.w, r1.w
movc r0.xyzw, r3.yyyy, r0.xyzw, r4.xyzw
movc r0.xyzw, r3.xxxx, r1.xyzw, r0.xyzw
movc r0.xyzw, cb0[14].yyyy, r0.xyzw, r2.xyzw
div r1.x, cb0[13].w, v5.w
add r1.x, r1.x, cb0[12].w
add_sat r1.x, r1.x, cb0[14].x
add r0.xyz, r0.xyzx, -cb0[11].xyzx
mad o0.xyz, r1.xxxx, r0.xyzx, cb0[11].xyzx
if_nz cb0[14].z
  ieq r0.x, cb0[14].w, l(1)
  if_nz r0.x
    mov r0.x, l(-1)
  else
    ieq r0.y, cb0[14].w, l(2)
    if_nz r0.y
      lt r0.y, r0.w, cb0[15].x
      movc r0.x, r0.y, l(1), l(-1)
    else
      ieq r0.y, cb0[14].w, l(3)
      if_nz r0.y
        eq r0.y, r0.w, cb0[15].x
        movc r0.x, r0.y, l(1), l(-1)
      else
        ge r0.y, cb0[15].x, r0.w
        lt r0.z, cb0[15].x, r0.w
        movc r0.yz, r0.yyzy, l(0,1,1,0), l(0,-1,-1,0)
        ne r1.x, r0.w, cb0[15].x
        ieq r2.xyzw, cb0[14].wwww, l(4, 5, 6, 7)
        ge r1.y, r0.w, cb0[15].x
        movc r1.xy, r1.xyxx, l(1,1,0,0), l(-1,-1,0,0)
        movc r1.y, r2.w, r1.y, l(1)
        movc r1.x, r2.z, r1.x, r1.y
        movc r0.z, r2.y, r0.z, r1.x
        movc r0.x, r2.x, r0.y, r0.z
      endif
    endif
  endif
  itof r0.x, r0.x
  lt r0.x, r0.x, l(0.000000)
  discard_nz r0.x
endif
mov o0.w, r0.w
ret
// Approximately 80 instruction slots used

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