// asmtool.py -I ../.. --fix-unity-lighting-ps --only-autofixed 9c329ed1e215f65a-ps.txt
// 3DMigoto: 9c329ed1e215f65a |    Unity headers extracted from Hidden_Internal-DeferredShading
//    Shader "Hidden/Internal-DeferredShading" {
//      SubShader 1/1 {
//        Pass 1/2 {
//          Tags { "SHADOWSUPPORT"="true" }
//          ZWrite Off
//          Program "fp" {
//            SubProgram "d3d11" {
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from Hidden_Internal-DeferredShading:
//   API d3d11
//   Shader model ps_4_0
//   undeciphered1: 201609010 88 5 0
//   undeciphered1a: 7
//   Keywords { "DIRECTIONAL_COOKIE" "SHADOWS_SCREEN" "UNITY_HDR_ON" }
//   undeciphered2: 1 6 4 6 0 0
//   undeciphered3: 0 0
//   ConstBuffer "$Globals" 1232
//   Vector 48 [_LightDir]
//   Vector 80 [_LightColor]
//   Matrix 112 [unity_WorldToLight]
//   ConstBuffer "UnityPerCamera" 144
//   Vector 64 [_WorldSpaceCameraPos] 3
//   Vector 80 [_ProjectionParams]
//   Vector 112 [_ZBufferParams]
//   ConstBuffer "UnityPerCameraRare" 352
//   Matrix 288 [unity_CameraToWorld]
//   ConstBuffer "UnityShadows" 416
//   Vector 384 [_LightShadowData]
//   Vector 400 [unity_ShadowFadeCenterAndType]
//   SetTexture 0 [_CameraDepthTexture] 2D 0
//   SetTexture 1 [_ShadowMapTexture] 2D 2
//   SetTexture 2 [_LightTexture0] 2D 1
//   SetTexture 3 [_CameraGBufferTexture0] 2D 3
//   SetTexture 4 [_CameraGBufferTexture1] 2D 4
//   SetTexture 5 [_CameraGBufferTexture2] 2D 5
//   BindCB "$Globals" 0
//   BindCB "UnityPerCamera" 1
//   BindCB "UnityPerCameraRare" 2
//   BindCB "UnityShadows" 3
//
// Headers extracted with DarkStarSword's extract_unity55_shaders.py
// https://github.com/DarkStarSword/3d-fixes

//
// Generated by Microsoft (R) D3D Shader Disassembler
//
//   using 3Dmigoto v1.3.16 on Sun Apr 21 17:59:32 2019
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float
// TEXCOORD                 0   xyzw        1     NONE   float   xy w
// TEXCOORD                 1   xyz         2     NONE   float   xyz
// TEXCOORD                 3      w        2     NONE   float      w
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target                0   xyzw        0   TARGET   float   xyzw
//
ps_4_0
dcl_constantbuffer cb0[11], immediateIndexed
dcl_constantbuffer cb1[9], immediateIndexed
dcl_constantbuffer cb2[22], immediateIndexed
dcl_constantbuffer cb3[26], 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_sampler s5, 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_texture2d (float,float,float,float) t4
dcl_resource_texture2d (float,float,float,float) t5
dcl_input_ps linear v1.xyw
dcl_input_ps linear v2.xyz
dcl_output o0.xyzw
dcl_temps 12

// New input from vertex shader with unity_CameraInvProjection[0].x:
dcl_input_ps linear v2.w
dcl_constantbuffer cb10[4], immediateIndexed

// 3DMigoto StereoParams:
dcl_resource_texture2d (float,float,float,float) t125

ld_indexable(texture2d)(float,float,float,float) r7.xyzw, l(0, 0, 0, 0), t125.xyzw


// Unity reflection/specular fix inserted with DarkStarSword's asmtool.py:
// asmtool.py -I ../.. --fix-unity-lighting-ps --only-autofixed 9c329ed1e215f65a-ps.txt

mul r7.w, -r7.x, r7.y
ne r9.x, l(0.0, 0.0, 0.0, 0.0), v2.w
if_nz r9.x
  mul r7.w, r7.w, v2.w
  mad r8.xyz, -r7.wwww, cb2[18].xyzw, cb1[4].xyzw
else
  mad r8.xyz, -r7.wwww, cb10[0].xyzw, cb1[4].xyzw
endif

div r0.x, cb1[5].z, v2.z
mul r0.xyz, r0.xxxx, v2.xyzx
div r1.xy, v1.xyxx, v1.wwww
sample r2.xyzw, r1.xyxx, t0.xyzw, s0
mad r0.w, cb1[7].x, r2.x, cb1[7].y
div r0.w, l(1.000000, 1.000000, 1.000000, 1.000000), r0.w
mul r2.xyz, r0.wwww, r0.xyzx

// copy depth from r2.z to r10.x:
mov r10.x, r2.z


// Unity light/shadow fix (pixel shader stage) inserted with DarkStarSword's asmtool.py:
// asmtool.py -I ../.. --fix-unity-lighting-ps --only-autofixed 9c329ed1e215f65a-ps.txt

add r11.x, r10.x, -r7.y
mul r11.x, r7.x, r11.x
ne r7.w, l(0.0, 0.0, 0.0, 0.0), v2.w
if_nz r7.w
  mad r2.x, -r11.x, v2.w, r2.x
endif

mul r3.xyz, r2.yyyy, cb2[19].xyzx
mad r2.xyw, cb2[18].xyxz, r2.xxxx, r3.xyxz
mad r2.xyw, cb2[20].xyxz, r2.zzzz, r2.xyxw
add r2.xyw, r2.xyxw, cb2[21].xyxz

if_z r7.w
  mad r2.xyw, -r11.xxxx, cb10[0].xyxz, r2.xyzw
endif

add r3.xyz, r2.xywx, -cb3[25].xyzx
dp3 r0.x, r3.xyzx, r3.xyzx
sqrt r0.x, r0.x
mad r0.x, -r0.z, r0.w, r0.x
mad r0.x, cb3[25].w, r0.x, r2.z
mad_sat r0.x, r0.x, cb3[24].z, cb3[24].w
sample r3.xyzw, r1.xyxx, t1.xyzw, s2
add r0.y, -r3.x, l(1.000000)
mad r0.x, r0.x, r0.y, r3.x
mul r0.yz, r2.yyyy, cb0[8].xxyx
mad r0.yz, cb0[7].xxyx, r2.xxxx, r0.yyzy
mad r0.yz, cb0[9].xxyx, r2.wwww, r0.yyzy
add r2.xyz, r2.xywx, -r8.xyzx
add r0.yz, r0.yyzy, cb0[10].xxyx
sample_b r3.xyzw, r0.yzyy, t2.xyzw, s1, l(-8.000000)
mul r0.x, r0.x, r3.w
mul r0.xyz, r0.xxxx, cb0[5].xyzx
dp3 r0.w, r2.xyzx, r2.xyzx
rsq r0.w, r0.w
mad r3.xyz, -r2.xyzx, r0.wwww, -cb0[3].xyzx
mul r2.xyz, r0.wwww, r2.xyzx
dp3 r0.w, r3.xyzx, r3.xyzx
max r0.w, r0.w, l(0.001000)
rsq r0.w, r0.w
mul r3.xyz, r0.wwww, r3.xyzx
sample r4.xyzw, r1.xyxx, t5.xyzw, s5
mad r4.xyz, r4.xyzx, l(2.000000, 2.000000, 2.000000, 0.000000), l(-1.000000, -1.000000, -1.000000, 0.000000)
dp3 r0.w, r4.xyzx, r4.xyzx
rsq r0.w, r0.w
mul r4.xyz, r0.wwww, r4.xyzx
dp3_sat r0.w, r4.xyzx, r3.xyzx
dp3_sat r1.z, -cb0[3].xyzx, r3.xyzx
sample r3.xyzw, r1.xyxx, t4.xyzw, s4
sample r5.xyzw, r1.xyxx, t3.xyzw, s3
add r6.xyzw, -r3.wxyz, l(1.000000, 1.000000, 1.000000, 1.000000)
mul r1.x, r6.x, r6.x
mul r1.y, r1.x, r1.x
mad r1.w, r0.w, r1.y, -r0.w
mad r0.w, r1.w, r0.w, l(1.000000)
mad r0.w, r0.w, r0.w, l(1.000000012E-007)
mul r1.y, r1.y, l(0.318309873)
div r0.w, r1.y, r0.w
dp3 r1.y, r4.xyzx, -r2.xyzx
dp3_sat r1.w, r4.xyzx, -cb0[3].xyzx
mad r2.x, -r6.x, r6.x, l(1.000000)
mad r2.y, |r1.y|, r2.x, r1.x
mad r1.x, r1.w, r2.x, r1.x
mul r1.x, r1.x, |r1.y|
add r1.y, -|r1.y|, l(1.000000)
mad r1.x, r1.w, r2.y, r1.x
add r1.x, r1.x, l(0.000010)
div r1.x, l(0.500000), r1.x
mul r0.w, r0.w, r1.x
mul r0.w, r0.w, l(3.14159274)
mul r0.w, r1.w, r0.w
max r0.w, r0.w, l(0.000000)
dp3 r1.x, r3.xyzx, r3.xyzx
ne r1.x, r1.x, l(0.000000)
and r1.x, r1.x, l(0x3f800000)
mul r0.w, r0.w, r1.x
mul r2.xyz, r0.xyzx, r0.wwww
add r0.w, -r1.z, l(1.000000)
mul r1.x, r0.w, r0.w
mul r1.x, r1.x, r1.x
mul r0.w, r0.w, r1.x
mad r3.xyz, r6.yzwy, r0.wwww, r3.xyzx
mul r2.xyz, r2.xyzx, r3.xyzx
add r0.w, r1.z, r1.z
mul r0.w, r1.z, r0.w
mad r0.w, r0.w, r6.x, l(-0.500000)
mul r1.x, r1.y, r1.y
mul r1.x, r1.x, r1.x
mul r1.x, r1.y, r1.x
mad r1.x, r0.w, r1.x, l(1.000000)
add r1.y, -r1.w, l(1.000000)
mul r1.z, r1.y, r1.y
mul r1.z, r1.z, r1.z
mul r1.y, r1.y, r1.z
mad r0.w, r0.w, r1.y, l(1.000000)
mul r0.w, r1.x, r0.w
mul r0.w, r1.w, r0.w
mul r0.xyz, r0.wwww, r0.xyzx
mad o0.xyz, r5.xyzx, r0.xyzx, r2.xyzx
mov o0.w, l(1.000000)
ret
// Approximately 0 instruction slots used