//point lights
// ---- Created with 3Dmigoto v1.2.39 on Wed Jun 22 09:54:42 2016

cbuffer _Globals : register(b0)
{
  float4x4 LocalToWorld : packoffset(c0);
  float4x4 ScreenToWorldMatrix : packoffset(c4);
  bool bDecompressSceneColor : packoffset(c8);
  float4 FirstDensityFunctionParameters : packoffset(c9);
  float4 SecondDensityFunctionParameters : packoffset(c10);
  float StartDistance : packoffset(c11);
  float4 PackedParameters : packoffset(c12);
  float4 MinMaxBlurClamp : packoffset(c13);
  float4 LightColorAndFalloffExponent : packoffset(c14);
  float3 DistanceFieldParameters : packoffset(c15);
  float4x4 ScreenToShadowMatrix : packoffset(c16);
  float4 ShadowBufferAndTexelSize : packoffset(c20);
  float ShadowOverrideFactor : packoffset(c21);
  float SSSMultiplier : packoffset(c21.y);
  bool bReceiveDynamicShadows : packoffset(c21.z);
  bool bEnableDistanceShadowFading : packoffset(c21.w);
  float2 DistanceFadeParameters : packoffset(c22);
  float4 IBLPositionAndWeight0 : packoffset(c23);
  float4 IBLPositionAndWeight1 : packoffset(c24);
  float4 IBLPositionAndWeight2 : packoffset(c25);
  float4 IBLPositionAndWeight3 : packoffset(c26);
  float4x4 IBLProxyOBB0 : packoffset(c27);
  float4x4 IBLProxyOBB1 : packoffset(c31);
  float4x4 IBLProxyOBB2 : packoffset(c35);
  float4 IBLUseProxyVolume : packoffset(c39);
  float4x4 IBLLastProxyOBB0 : packoffset(c40);
  float4x4 IBLLastProxyOBB1 : packoffset(c44);
  float4x4 IBLLastProxyOBB2 : packoffset(c48);
  float4 IBLUseLastProxyVolume : packoffset(c52);
  float ForcedIBLWeight : packoffset(c53);
  float AdditionalReflections : packoffset(c53.y);
  float4x4 InvViewProjectionMatrix : packoffset(c54);
  float3 CameraWorldPos : packoffset(c58);
  float3 ActorWorldPos : packoffset(c59);
  float4 ObjectWorldPositionAndRadius : packoffset(c60);
  float3 ObjectOrientation : packoffset(c61);
  float3 ObjectPostProjectionPosition : packoffset(c62);
  float3 ObjectNDCPosition : packoffset(c63);
  float4 ObjectMacroUVScales : packoffset(c64);
  float3 FoliageImpulseDirection : packoffset(c65);
  float4 FoliageNormalizedRotationAxisAndAngle : packoffset(c66);
  float4 WindDirectionAndSpeed : packoffset(c67);
  float3x3 LocalToWorldMatrix : packoffset(c68);
  float3x3 WorldToLocalMatrix : packoffset(c71);
  float3x3 WorldToViewMatrix : packoffset(c74);
  float3x3 ViewToWorldMatrix : packoffset(c77);
  float4 UniformPixelVector_0 : packoffset(c80);
  float4 UniformPixelVector_1 : packoffset(c81);
  float4 UniformPixelScalars_0 : packoffset(c82);
  float3 TemporalAAParameters : packoffset(c83);
  float4x4 PreviousLocalToWorld : packoffset(c84);
  float LocalToWorldRotDeterminantFlip : packoffset(c88);
  float3x3 WorldToLocal : packoffset(c89);
  float4 LightmapCoordinateScaleBias : packoffset(c92);
  float4 ShadowmapCoordinateScaleBias : packoffset(c93);
  float4x4 ScreenToWorld : packoffset(c94);
  float4 FogCameraPosition : packoffset(c98);
  float FaceScale : packoffset(c99);
  float4 DepthFilterSampleOffsets[2] : packoffset(c100);
  float InvMaxIntegral : packoffset(c102);
  float MaxDistance : packoffset(c102.y);
}

cbuffer PSOffsetConstants : register(b2)
{
  float4 ScreenPositionScaleBias : packoffset(c0);
  float4 MinZ_MaxZRatio : packoffset(c1);
  float NvStereoEnabled : packoffset(c2);
  float4 DiffuseOverrideParameter : packoffset(c3);
  float4 SpecularOverrideParameter : packoffset(c4);
  float4 CameraPositionPS : packoffset(c5);
  float4 ScreenAndTexelSize : packoffset(c6);
}

SamplerState SceneDepthTextureSampler_s : register(s0);
Texture2D<float4> SceneDepthTexture : register(t0);


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


void main( 
  float4 v0 : TEXCOORD10,
  float4 v1 : TEXCOORD11,
  float4 v2 : COLOR0,
  float4 v3 : TEXCOORD5,
  out float4 o0 : SV_Target0)
{
  float4 r0,r1,r2,r3,r4,r5;
  uint4 bitmask, uiDest;
  float4 fDest;

  r0.xy = v3.xy / v3.ww;
  r0.zw = r0.xy * ScreenPositionScaleBias.xy + ScreenPositionScaleBias.wz;
  r0.z = SceneDepthTexture.Sample(SceneDepthTextureSampler_s, r0.zw).x;
  r0.z = r0.z * MinZ_MaxZRatio.z + -MinZ_MaxZRatio.w;
  r0.z = 1 / r0.z;
  r0.z = min(MaxDistance, r0.z);
  r0.z = dot(r0.zzzz, float4(0.25,0.25,0.25,0.25));
  r0.z = min(65535, r0.z);
  r0.z = min(v3.z, r0.z);
  r0.xy = r0.xy * r0.zz;

float4 stereo = StereoParams.Load(0);
r0.x -= stereo.x*(r0.z - stereo.y);

  r1.xyz = ScreenToWorld._m01_m11_m21 * r0.yyy;
  r0.xyw = ScreenToWorld._m00_m10_m20 * r0.xxx + r1.xyz;
  r0.xyz = ScreenToWorld._m02_m12_m22 * r0.zzz + r0.xyw;
  r0.xyz = ScreenToWorld._m03_m13_m23 + r0.xyz;
  r1.xyz = FogCameraPosition.xyz + -r0.xyz;
  r0.xyz = -SecondDensityFunctionParameters.xyz + r0.xyz;
  r2.y = dot(r1.xyz, r0.xyz);
  r2.x = dot(r1.xyz, r1.xyz);
  r2.z = dot(r0.xyz, r0.xyz);
  r0.x = r2.y + r2.y;
  r0.y = -SecondDensityFunctionParameters.w * SecondDensityFunctionParameters.w + r2.z;
  r1.xyzw = float4(4,0.333333343,1,1) * r2.xxyz;
  r0.y = r1.x * r0.y;
  r0.x = r0.x * r0.x + -r0.y;
  r3.x = sqrt(r0.x);
  r0.x = cmp(r0.x >= 0);
  r3.y = -r3.x;
  r0.yz = r2.yy * float2(2,2) + r3.xy;
  r0.w = 9.99999975e-005 + r2.x;
  r1.x = sqrt(r2.x);
  r0.w = 0.5 / r0.w;
  r2.xy = saturate(-r0.yz * r0.ww);
  r3.w = r2.x;
  r0.y = StartDistance / r1.x;
  r0.y = 1 + -r0.y;
  r0.y = min(r0.y, r2.y);
  r2.z = max(r0.y, r2.x);
  r4.xy = r2.xz * r2.xz;
  r3.xy = r4.xy * r2.xz;
  r3.z = r4.x;
  r5.x = dot(r1.yzw, r3.xzw);
  r4.z = r3.y;
  r4.w = r2.z;
  r5.y = dot(r1.zyw, r4.yzw);
  r0.y = SecondDensityFunctionParameters.w * SecondDensityFunctionParameters.w;
  r0.yz = r5.xy / r0.yy;
  r0.yz = r2.xz + -r0.yz;
  r0.y = FirstDensityFunctionParameters.x * r0.y;
  r0.y = FirstDensityFunctionParameters.x * r0.z + -r0.y;
  r0.y = r0.y * r1.x;
  r0.x = r0.x ? r0.y : 0;
  o0.x = FaceScale * r0.x;
  o0.yzw = float3(0,0,0);
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//   using 3Dmigoto v1.2.39 on Wed Jun 22 09:54:42 2016
//
//
// Buffer Definitions: 
//
// cbuffer $Globals
// {
//
//   float4x4 LocalToWorld;             // Offset:    0 Size:    64 [unused]
//   float4x4 ScreenToWorldMatrix;      // Offset:   64 Size:    64 [unused]
//   bool bDecompressSceneColor;        // Offset:  128 Size:     4 [unused]
//   float4 FirstDensityFunctionParameters;// Offset:  144 Size:    16
//   float4 SecondDensityFunctionParameters;// Offset:  160 Size:    16
//   float StartDistance;               // Offset:  176 Size:     4
//   float4 PackedParameters;           // Offset:  192 Size:    16 [unused]
//   float4 MinMaxBlurClamp;            // Offset:  208 Size:    16 [unused]
//   float4 LightColorAndFalloffExponent;// Offset:  224 Size:    16 [unused]
//   float3 DistanceFieldParameters;    // Offset:  240 Size:    12 [unused]
//   float4x4 ScreenToShadowMatrix;     // Offset:  256 Size:    64 [unused]
//   float4 ShadowBufferAndTexelSize;   // Offset:  320 Size:    16 [unused]
//   float ShadowOverrideFactor;        // Offset:  336 Size:     4 [unused]
//   float SSSMultiplier;               // Offset:  340 Size:     4 [unused]
//   bool bReceiveDynamicShadows;       // Offset:  344 Size:     4 [unused]
//   bool bEnableDistanceShadowFading;  // Offset:  348 Size:     4 [unused]
//   float2 DistanceFadeParameters;     // Offset:  352 Size:     8 [unused]
//   float4 IBLPositionAndWeight0;      // Offset:  368 Size:    16 [unused]
//   float4 IBLPositionAndWeight1;      // Offset:  384 Size:    16 [unused]
//   float4 IBLPositionAndWeight2;      // Offset:  400 Size:    16 [unused]
//   float4 IBLPositionAndWeight3;      // Offset:  416 Size:    16 [unused]
//   float4x4 IBLProxyOBB0;             // Offset:  432 Size:    64 [unused]
//   float4x4 IBLProxyOBB1;             // Offset:  496 Size:    64 [unused]
//   float4x4 IBLProxyOBB2;             // Offset:  560 Size:    64 [unused]
//   float4 IBLUseProxyVolume;          // Offset:  624 Size:    16 [unused]
//   float4x4 IBLLastProxyOBB0;         // Offset:  640 Size:    64 [unused]
//   float4x4 IBLLastProxyOBB1;         // Offset:  704 Size:    64 [unused]
//   float4x4 IBLLastProxyOBB2;         // Offset:  768 Size:    64 [unused]
//   float4 IBLUseLastProxyVolume;      // Offset:  832 Size:    16 [unused]
//   float ForcedIBLWeight;             // Offset:  848 Size:     4 [unused]
//   float AdditionalReflections;       // Offset:  852 Size:     4 [unused]
//   float4x4 InvViewProjectionMatrix;  // Offset:  864 Size:    64 [unused]
//   float3 CameraWorldPos;             // Offset:  928 Size:    12 [unused]
//   float3 ActorWorldPos;              // Offset:  944 Size:    12 [unused]
//   float4 ObjectWorldPositionAndRadius;// Offset:  960 Size:    16 [unused]
//   float3 ObjectOrientation;          // Offset:  976 Size:    12 [unused]
//   float3 ObjectPostProjectionPosition;// Offset:  992 Size:    12 [unused]
//   float3 ObjectNDCPosition;          // Offset: 1008 Size:    12 [unused]
//   float4 ObjectMacroUVScales;        // Offset: 1024 Size:    16 [unused]
//   float3 FoliageImpulseDirection;    // Offset: 1040 Size:    12 [unused]
//   float4 FoliageNormalizedRotationAxisAndAngle;// Offset: 1056 Size:    16 [unused]
//   float4 WindDirectionAndSpeed;      // Offset: 1072 Size:    16 [unused]
//   float3x3 LocalToWorldMatrix;       // Offset: 1088 Size:    44 [unused]
//   float3x3 WorldToLocalMatrix;       // Offset: 1136 Size:    44 [unused]
//   float3x3 WorldToViewMatrix;        // Offset: 1184 Size:    44 [unused]
//   float3x3 ViewToWorldMatrix;        // Offset: 1232 Size:    44 [unused]
//   float4 UniformPixelVector_0;       // Offset: 1280 Size:    16 [unused]
//   float4 UniformPixelVector_1;       // Offset: 1296 Size:    16 [unused]
//   float4 UniformPixelScalars_0;      // Offset: 1312 Size:    16 [unused]
//   float3 TemporalAAParameters;       // Offset: 1328 Size:    12 [unused]
//   float4x4 PreviousLocalToWorld;     // Offset: 1344 Size:    64 [unused]
//   float LocalToWorldRotDeterminantFlip;// Offset: 1408 Size:     4 [unused]
//   float3x3 WorldToLocal;             // Offset: 1424 Size:    44 [unused]
//   float4 LightmapCoordinateScaleBias;// Offset: 1472 Size:    16 [unused]
//   float4 ShadowmapCoordinateScaleBias;// Offset: 1488 Size:    16 [unused]
//   float4x4 ScreenToWorld;            // Offset: 1504 Size:    64
//   float4 FogCameraPosition;          // Offset: 1568 Size:    16
//   float FaceScale;                   // Offset: 1584 Size:     4
//   float4 DepthFilterSampleOffsets[2];// Offset: 1600 Size:    32 [unused]
//   float InvMaxIntegral;              // Offset: 1632 Size:     4 [unused]
//   float MaxDistance;                 // Offset: 1636 Size:     4
//
// }
//
// cbuffer PSOffsetConstants
// {
//
//   float4 ScreenPositionScaleBias;    // Offset:    0 Size:    16
//   float4 MinZ_MaxZRatio;             // Offset:   16 Size:    16
//   float NvStereoEnabled;             // Offset:   32 Size:     4 [unused]
//   float4 DiffuseOverrideParameter;   // Offset:   48 Size:    16 [unused]
//   float4 SpecularOverrideParameter;  // Offset:   64 Size:    16 [unused]
//   float4 CameraPositionPS;           // Offset:   80 Size:    16 [unused]
//   float4 ScreenAndTexelSize;         // Offset:   96 Size:    16 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// SceneDepthTextureSampler          sampler      NA          NA    0        1
// SceneDepthTexture                 texture  float4          2d    0        1
// $Globals                          cbuffer      NA          NA    0        1
// PSOffsetConstants                 cbuffer      NA          NA    2        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// TEXCOORD                10   xyzw        0     NONE   float       
// TEXCOORD                11   xyzw        1     NONE   float       
// COLOR                    0   xyzw        2     NONE   float       
// TEXCOORD                 5   xyzw        3     NONE   float   xyzw
//
//
// 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[103], immediateIndexed
dcl_constantbuffer cb2[2], immediateIndexed
dcl_sampler s0, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_input_ps linear v3.xyzw
dcl_output o0.xyzw
dcl_temps 6
div r0.xy, v3.xyxx, v3.wwww
mad r0.zw, r0.xxxy, cb2[0].xxxy, cb2[0].wwwz
sample_indexable(texture2d)(float,float,float,float) r0.z, r0.zwzz, t0.yzxw, s0
mad r0.z, r0.z, cb2[1].z, -cb2[1].w
div r0.z, l(1.000000, 1.000000, 1.000000, 1.000000), r0.z
min r0.z, r0.z, cb0[102].y
dp4 r0.z, r0.zzzz, l(0.250000, 0.250000, 0.250000, 0.250000)
min r0.z, r0.z, l(65535.000000)
min r0.z, r0.z, v3.z
mul r0.xy, r0.zzzz, r0.xyxx
mul r1.xyz, r0.yyyy, cb0[95].xyzx
mad r0.xyw, cb0[94].xyxz, r0.xxxx, r1.xyxz
mad r0.xyz, cb0[96].xyzx, r0.zzzz, r0.xywx
add r0.xyz, r0.xyzx, cb0[97].xyzx
add r1.xyz, -r0.xyzx, cb0[98].xyzx
add r0.xyz, r0.xyzx, -cb0[10].xyzx
dp3 r2.y, r1.xyzx, r0.xyzx
dp3 r2.x, r1.xyzx, r1.xyzx
dp3 r2.z, r0.xyzx, r0.xyzx
add r0.x, r2.y, r2.y
mad r0.y, -cb0[10].w, cb0[10].w, r2.z
mul r1.xyzw, r2.xxyz, l(4.000000, 0.333333343, 1.000000, 1.000000)
mul r0.y, r0.y, r1.x
mad r0.x, r0.x, r0.x, -r0.y
sqrt r3.x, r0.x
ge r0.x, r0.x, l(0.000000)
mov r3.y, -r3.x
mad r0.yz, r2.yyyy, l(0.000000, 2.000000, 2.000000, 0.000000), r3.xxyx
add r0.w, r2.x, l(0.000100)
sqrt r1.x, r2.x
div r0.w, l(0.500000), r0.w
mul_sat r2.xy, r0.wwww, -r0.yzyy
mov r3.w, r2.x
div r0.y, cb0[11].x, r1.x
add r0.y, -r0.y, l(1.000000)
min r0.y, r2.y, r0.y
max r2.z, r2.x, r0.y
mul r4.xy, r2.xzxx, r2.xzxx
mul r3.xy, r2.xzxx, r4.xyxx
mov r3.z, r4.x
dp3 r5.x, r1.yzwy, r3.xzwx
mov r4.z, r3.y
mov r4.w, r2.z
dp3 r5.y, r1.zywz, r4.yzwy
mul r0.y, cb0[10].w, cb0[10].w
div r0.yz, r5.xxyx, r0.yyyy
add r0.yz, -r0.yyzy, r2.xxzx
mul r0.y, r0.y, cb0[9].x
mad r0.y, cb0[9].x, r0.z, -r0.y
mul r0.y, r1.x, r0.y
and r0.x, r0.y, r0.x
mul o0.x, r0.x, cb0[99].x
mov o0.yzw, l(0,0,0,0)
ret 
// Approximately 54 instruction slots used

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