// Glass Halo PS

cbuffer _Globals : register(b4)
{
  float2 gm_vTextureSizeInv : packoffset(c0);
  float1 TextureNormal_01_BumpScale : packoffset(c0.z);
  float Fresnel_01_Power : packoffset(c0.w);
  float Fresnel_01_Minimum : packoffset(c1);
  float Fresnel_01_Maximum : packoffset(c1.y);
  float4 Multiply_04_V2 : packoffset(c2);
  float3 ColorModulate_02_Color2 : packoffset(c3);
  float3 ColorAdd_02_Color2 : packoffset(c4);
}

cbuffer _cbSharedPerViewData : register(b1)
{

  struct
  {
    row_major float4x4 mProjection;
    row_major float4x4 mViewToViewport;
    row_major float4x4 mViewToWorld;
    float4 vViewRemap;
    float4 vViewDepthRemap;
    float4 vEyeVectorUL;
    float4 vEyeVectorLR;
    float4 v4ShadowRange;
    float4 vViewSpaceUpVector;
    float4 vGlobalLitFactor;
    float4 vViewportSize;
    float4 vEngineTime;
    float4 vShaderColor0;
    float4 vShaderColor1;
    float4 vShaderColor2;
    float4 vShaderColor3;
    float4 vShaderColor4;
    float4 vClipPlane;
  } cbSharedPerViewData : packoffset(c0);

}

SamplerState samplerRefraction2D_s : register(s0);
SamplerState samplerRefractionMask2D_s : register(s1);
SamplerState samplerDiffuse_01_s : register(s2);
SamplerState samplerTextureNormal_01_s : register(s3);
SamplerState samplerTextureCube_01_s : register(s4);
Texture2D<float4> mapRefraction2D : register(t0);
Texture2D<float4> mapRefractionMask2D : register(t1);
Texture2D<float4> mapDiffuse_01 : register(t2);
Texture2D<float4> mapTextureNormal_01 : register(t3);
TextureCube<float4> mapTextureCube_01 : register(t4);


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


void main( 
  float4 v0 : SV_POSITION0,
  float4 v1 : TEXCOORD0,
  float4 v2 : TEXCOORD2,
  float4 v3 : TEXCOORD3,
  float4 v4 : TEXCOORD4,
  float4 v5 : TEXCOORD5,
  float4 v6 : TEXCOORD6,
  float4 v7 : TEXCOORD7,
  out float4 o0 : SV_TARGET0)
{
  float4 r0,r1,r2,r3,r4;
  uint4 bitmask, uiDest;
  float4 fDest;

  
  
  r0.x = dot(-v1.xyz, -v1.xyz);
  r0.x = rsqrt(r0.x);
  r0.xyz = -v1.xyz * r0.xxx;
  r0.w = dot(v3.xyz, v3.xyz);
  r0.w = rsqrt(r0.w);
  r1.xyz = v3.xyz * r0.www;
  r0.x = saturate(dot(r0.xyz, r1.xyz));
  r0.x = 1 + -r0.x;
  r0.x = log2(r0.x);
  r0.x = Fresnel_01_Power * r0.x;
  r0.x = exp2(r0.x);
  r0.y = Fresnel_01_Maximum + -Fresnel_01_Minimum;
  r0.x = r0.x * r0.y + Fresnel_01_Minimum;
  r1.xyzw = mapTextureNormal_01.Sample(samplerTextureNormal_01_s, v2.xy).xyzw;
  
  float4 r22;
  r22.w = 1 / r1.z;
  
  r0.yz = float2(-0.5,-0.5) + r1.xy;
  r0.yz = saturate(r0.yz * TextureNormal_01_BumpScale + float2(0.5,0.5));
  r0.yz = float2(-0.5,-0.5) + r0.yz;
  r0.yz = r0.yz + r0.yz;
  r1.xyz = v5.xyz * r0.zzz;
  r1.xyz = v4.xyz * r0.yyy + r1.xyz;
  r0.y = dot(r0.yz, r0.yz);
  r0.y = min(1, r0.y);
  r0.y = 1 + -r0.y;
  r0.y = sqrt(r0.y);
  r0.yzw = v3.xyz * r0.yyy + r1.xyz;
  r1.x = dot(v1.xyz, r0.yzw);
  r1.x = r1.x + r1.x;
  r1.xyz = r0.yzw * -r1.xxx + v1.xyz;
  r0.yz = cbSharedPerViewData.vViewportSize.xy * -r0.yz;
  r2.xyz = cbSharedPerViewData.mViewToWorld._m10_m12_m11 * r1.yyy;
  r1.xyw = r1.xxx * cbSharedPerViewData.mViewToWorld._m00_m02_m01 + r2.xyz;
  r1.xyz = r1.zzz * cbSharedPerViewData.mViewToWorld._m20_m22_m21 + r1.xyw;
  r1.xyzw = mapTextureCube_01.Sample(samplerTextureCube_01_s, r1.xyz).xyzw;
  r0.w = Multiply_04_V2.x * r1.w;
  r1.xyz = ColorAdd_02_Color2.xyz + r1.xyz;
  r1.xyz = ColorModulate_02_Color2.xyz * r1.xyz;
  r0.w = 16 * r0.w;
  r0.w = exp2(r0.w);
  r1.xyz = r1.xyz * r0.www;
  r1.xyz = r1.xyz * r0.xxx;
  r2.xyzw = mapDiffuse_01.Sample(samplerDiffuse_01_s, v2.xy).xyzw;
  r1.xyz = r2.xyz * r1.xyz;
  r0.xw = float2(10,10) * r0.yz;
  r3.xyz = cbSharedPerViewData.mViewToViewport._m10_m11_m13 * v1.yyy;
  
  float4 stereo = StereoParams.Load(0);
  //v1.x -= -stereo.x * (r22.w - stereo.y) / -cbSharedPerViewData.mProjection._m00 / stereo.y;
  
  
  
  r3.xyz = v1.xxx * cbSharedPerViewData.mViewToViewport._m00_m01_m03 + r3.xyz;
  r3.xyz = v1.zzz * cbSharedPerViewData.mViewToViewport._m20_m21_m23 + r3.xyz;
  r3.xyz = v1.www * cbSharedPerViewData.mViewToViewport._m30_m31_m33 + r3.xyz;
  r3.xy = r3.xy / r3.zz;
  r0.yz = -r0.yz * float2(10,10) + r3.xy;
  r4.xyzw = mapRefractionMask2D.SampleLevel(samplerRefractionMask2D_s, r0.yz, 0).xyzw;
  r0.y = cmp(0.5 < r4.x);
  r0.y = r0.y ? 1.000000 : 0;
  r0.xy = -r0.xw * r0.yy + r3.xy;
  r0.xyzw = mapRefraction2D.SampleLevel(samplerRefraction2D_s, r0.xy, 0).xyzw;
  r1.w = cmp(0 >= r0.w);
  r1.w = r1.w ? 1.000000 : 0;
  r3.xyz = r0.xyz / r0.www;
  r0.xyz = -r3.xyz + r0.xyz;
  r0.xyz = r1.www * r0.xyz + r3.xyz;
  r0.xyz = r0.xyz * r2.xyz + r1.xyz;
  o0.xyz = v6.xyz * r0.xyz;
  o0.w = 1;
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.27.952.3022
//
//   using 3Dmigoto v1.2.19 on Tue Dec 22 16:23:16 2015
//
//
// Buffer Definitions: 
//
// cbuffer $Globals
// {
//
//   float2 gm_vTextureSizeInv;         // Offset:    0 Size:     8 [unused]
//   float1 TextureNormal_01_BumpScale; // Offset:    8 Size:     4
//   float Fresnel_01_Power;            // Offset:   12 Size:     4
//   float Fresnel_01_Minimum;          // Offset:   16 Size:     4
//   float Fresnel_01_Maximum;          // Offset:   20 Size:     4
//   float4 Multiply_04_V2;             // Offset:   32 Size:    16
//   float3 ColorModulate_02_Color2;    // Offset:   48 Size:    12
//   float3 ColorAdd_02_Color2;         // Offset:   64 Size:    12
//
// }
//
// cbuffer _cbSharedPerViewData
// {
//
//   struct
//   {
//       
//       row_major float4x4 mProjection;// Offset:    0
//       row_major float4x4 mViewToViewport;// Offset:   64
//       row_major float4x4 mViewToWorld;// Offset:  128
//       float4 vViewRemap;             // Offset:  192
//       float4 vViewDepthRemap;        // Offset:  208
//       float4 vEyeVectorUL;           // Offset:  224
//       float4 vEyeVectorLR;           // Offset:  240
//       float4 v4ShadowRange;          // Offset:  256
//       float4 vViewSpaceUpVector;     // Offset:  272
//       float4 vGlobalLitFactor;       // Offset:  288
//       float4 vViewportSize;          // Offset:  304
//       float4 vEngineTime;            // Offset:  320
//       float4 vShaderColor0;          // Offset:  336
//       float4 vShaderColor1;          // Offset:  352
//       float4 vShaderColor2;          // Offset:  368
//       float4 vShaderColor3;          // Offset:  384
//       float4 vShaderColor4;          // Offset:  400
//       float4 vClipPlane;             // Offset:  416
//
//   } cbSharedPerViewData;             // Offset:    0 Size:   432
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// samplerRefraction2D               sampler      NA          NA    0        1
// samplerRefractionMask2D           sampler      NA          NA    1        1
// samplerDiffuse_01                 sampler      NA          NA    2        1
// samplerTextureNormal_01           sampler      NA          NA    3        1
// samplerTextureCube_01             sampler      NA          NA    4        1
// mapRefraction2D                   texture  float4          2d    0        1
// mapRefractionMask2D               texture  float4          2d    1        1
// mapDiffuse_01                     texture  float4          2d    2        1
// mapTextureNormal_01               texture  float4          2d    3        1
// mapTextureCube_01                 texture  float4        cube    4        1
// _cbSharedPerViewData              cbuffer      NA          NA    1        1
// $Globals                          cbuffer      NA          NA    4        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float       
// TEXCOORD                 0   xyzw        1     NONE   float   xyzw
// TEXCOORD                 2   xyzw        2     NONE   float   xy  
// TEXCOORD                 3   xyzw        3     NONE   float   xyz 
// TEXCOORD                 4   xyzw        4     NONE   float   xyz 
// TEXCOORD                 5   xyzw        5     NONE   float   xyz 
// TEXCOORD                 6   xyzw        6     NONE   float   xyz 
// TEXCOORD                 7   xyzw        7     NONE   float       
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_TARGET                0   xyzw        0   TARGET   float   xyzw
//
ps_4_0
dcl_constantbuffer cb4[5], immediateIndexed
dcl_constantbuffer cb1[20], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, mode_default
dcl_sampler s2, mode_default
dcl_sampler s3, mode_default
dcl_sampler s4, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t1
dcl_resource_texture2d (float,float,float,float) t2
dcl_resource_texture2d (float,float,float,float) t3
dcl_resource_texturecube (float,float,float,float) t4
dcl_input_ps linear v1.xyzw
dcl_input_ps linear v2.xy
dcl_input_ps linear v3.xyz
dcl_input_ps linear v4.xyz
dcl_input_ps linear v5.xyz
dcl_input_ps linear v6.xyz
dcl_output o0.xyzw
dcl_temps 5
dp3 r0.x, -v1.xyzx, -v1.xyzx
rsq r0.x, r0.x
mul r0.xyz, r0.xxxx, -v1.xyzx
dp3 r0.w, v3.xyzx, v3.xyzx
rsq r0.w, r0.w
mul r1.xyz, r0.wwww, v3.xyzx
dp3_sat r0.x, r0.xyzx, r1.xyzx
add r0.x, -r0.x, l(1.000000)
log r0.x, r0.x
mul r0.x, r0.x, cb4[0].w
exp r0.x, r0.x
add r0.y, -cb4[1].x, cb4[1].y
mad r0.x, r0.x, r0.y, cb4[1].x
sample r1.xyzw, v2.xyxx, t3.xyzw, s3
add r0.yz, r1.xxyx, l(0.000000, -0.500000, -0.500000, 0.000000)
mad_sat r0.yz, r0.yyzy, cb4[0].zzzz, l(0.000000, 0.500000, 0.500000, 0.000000)
add r0.yz, r0.yyzy, l(0.000000, -0.500000, -0.500000, 0.000000)
add r0.yz, r0.yyzy, r0.yyzy
mul r1.xyz, r0.zzzz, v5.xyzx
mad r1.xyz, v4.xyzx, r0.yyyy, r1.xyzx
dp2 r0.y, r0.yzyy, r0.yzyy
min r0.y, r0.y, l(1.000000)
add r0.y, -r0.y, l(1.000000)
sqrt r0.y, r0.y
mad r0.yzw, v3.xxyz, r0.yyyy, r1.xxyz
dp3 r1.x, v1.xyzx, r0.yzwy
add r1.x, r1.x, r1.x
mad r1.xyz, r0.yzwy, -r1.xxxx, v1.xyzx
mul r0.yz, -r0.yyzy, cb1[19].xxyx
mul r2.xyz, r1.yyyy, cb1[9].xzyx
mad r1.xyw, r1.xxxx, cb1[8].xzxy, r2.xyxz
mad r1.xyz, r1.zzzz, cb1[10].xzyx, r1.xywx
sample r1.xyzw, r1.xyzx, t4.xyzw, s4
mul r0.w, r1.w, cb4[2].x
add r1.xyz, r1.xyzx, cb4[4].xyzx
mul r1.xyz, r1.xyzx, cb4[3].xyzx
mul r0.w, r0.w, l(16.000000)
exp r0.w, r0.w
mul r1.xyz, r0.wwww, r1.xyzx
mul r1.xyz, r0.xxxx, r1.xyzx
sample r2.xyzw, v2.xyxx, t2.xyzw, s2
mul r1.xyz, r1.xyzx, r2.xyzx
mul r0.xw, r0.yyyz, l(10.000000, 0.000000, 0.000000, 10.000000)
mul r3.xyz, v1.yyyy, cb1[5].xywx
mad r3.xyz, v1.xxxx, cb1[4].xywx, r3.xyzx
mad r3.xyz, v1.zzzz, cb1[6].xywx, r3.xyzx
mad r3.xyz, v1.wwww, cb1[7].xywx, r3.xyzx
div r3.xy, r3.xyxx, r3.zzzz
mad r0.yz, -r0.yyzy, l(0.000000, 10.000000, 10.000000, 0.000000), r3.xxyx
sample_l r4.xyzw, r0.yzyy, t1.xyzw, s1, l(0.000000)
lt r0.y, l(0.500000), r4.x
and r0.y, r0.y, l(0x3f800000)
mad r0.xy, -r0.xwxx, r0.yyyy, r3.xyxx
sample_l r0.xyzw, r0.xyxx, t0.xyzw, s0, l(0.000000)
ge r1.w, l(0.000000), r0.w
and r1.w, r1.w, l(0x3f800000)
div r3.xyz, r0.xyzx, r0.wwww
add r0.xyz, r0.xyzx, -r3.xyzx
mad r0.xyz, r1.wwww, r0.xyzx, r3.xyzx
mad r0.xyz, r0.xyzx, r2.xyzx, r1.xyzx
mul o0.xyz, r0.xyzx, v6.xyzx
mov o0.w, l(1.000000)
ret 
// Approximately 63 instruction slots used

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