// asmtool.py -I ../.. --fix-unity-reflection --only-autofixed ca04e285be95a31a-ps.txt
// 3DMigoto: ca04e285be95a31a |    Unity headers extracted from Legacy Shaders_Specular
//    Shader "Legacy Shaders/Specular" {
//      Fallback "Legacy Shaders/VertexLit"
//      SubShader 1/1 {
//        LOD 300
//        Tags { "RenderType"="Opaque" }
//        Pass 1/6 {
//          Name "FORWARD"
//          Tags { "LIGHTMODE"="FORWARDBASE" "RenderType"="Opaque" "SHADOWSUPPORT"="true" }
//          Program "fp" {
//            SubProgram "d3d11" {
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from Legacy Shaders_Specular:
//   API d3d11
//   Shader model ps_4_0
//   undeciphered1: 201609010 66 6 4
//   undeciphered1a: 7
//   Keywords { "DIRECTIONAL" "SHADOWS_SCREEN" }
//   undeciphered2: 1 3 6 3 0 0
//   undeciphered3: 0 0
//   ConstBuffer "$Globals" 1136
//   Vector 32 [_LightColor0]
//   Vector 48 [_SpecColor]
//   Vector 1088 [_Color]
//   Float 1104 [_Shininess]
//   ConstBuffer "UnityPerCamera" 144
//   Vector 64 [_WorldSpaceCameraPos] 3
//   ConstBuffer "UnityLighting" 752
//   Vector 0 [_WorldSpaceLightPos0]
//   Vector 608 [unity_SHAr]
//   Vector 624 [unity_SHAg]
//   Vector 640 [unity_SHAb]
//   Vector 720 [unity_OcclusionMaskSelector]
//   ConstBuffer "UnityShadows" 416
//   Vector 384 [_LightShadowData]
//   Vector 400 [unity_ShadowFadeCenterAndType]
//   ConstBuffer "UnityPerFrame" 384
//   Matrix 144 [unity_MatrixV]
//   ConstBuffer "UnityProbeVolume" 112
//   Vector 0 [unity_ProbeVolumeParams]
//   Vector 80 [unity_ProbeVolumeSizeInv] 3
//   Vector 96 [unity_ProbeVolumeMin] 3
//   Matrix 16 [unity_ProbeVolumeWorldToObject]
//   SetTexture 0 [_MainTex] 2D 2
//   SetTexture 1 [_ShadowMapTexture] 2D 1
//   SetTexture 2 [unity_ProbeVolumeSH] 3D 0
//   BindCB "$Globals" 0
//   BindCB "UnityPerCamera" 1
//   BindCB "UnityLighting" 2
//   BindCB "UnityShadows" 3
//   BindCB "UnityPerFrame" 4
//   BindCB "UnityProbeVolume" 5
//
// 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 18:02:00 2019
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float
// TEXCOORD                 0   xy          1     NONE   float   xy
// TEXCOORD                 1   xyz         2     NONE   float   xyz
// TEXCOORD                 2   xyz         3     NONE   float   xyz
// TEXCOORD                 3   xyz         4     NONE   float   xyz
// TEXCOORD                 4   xyzw        5     NONE   float   xy w
// TEXCOORD                 6   xyzw        6     NONE   float
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target                0   xyzw        0   TARGET   float   xyzw
//
ps_4_0
dcl_constantbuffer cb0[70], immediateIndexed
dcl_constantbuffer cb1[9], immediateIndexed
dcl_constantbuffer cb2[46], immediateIndexed
dcl_constantbuffer cb3[26], immediateIndexed
dcl_constantbuffer cb4[12], immediateIndexed
dcl_constantbuffer cb5[7], immediateIndexed
dcl_sampler s0, mode_default
dcl_sampler s1, mode_default
dcl_sampler s2, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t1
dcl_resource_texture3d (float,float,float,float) t2
dcl_input_ps linear v1.xy
dcl_input_ps linear v2.xyz
dcl_input_ps linear v3.xyz
dcl_input_ps linear v4.xyz
dcl_input_ps linear v5.xyw
dcl_output o0.xyzw
dcl_temps 9
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-reflection --only-autofixed ca04e285be95a31a-ps.txt

mul r7.w, -r7.x, r7.y
mad r8.xyz, -r7.wwww, cb10[0].xyzw, cb1[4].xyzw

add r0.xyz, -v3.xyzx, r8.xyzx
dp3 r0.w, r0.xyzx, r0.xyzx
rsq r0.w, r0.w
sample r1.xyzw, v1.xyxx, t0.xyzw, s2
mul r1.xyz, r1.xyzx, cb0[68].xyzx
mov r2.x, cb4[9].z
mov r2.y, cb4[10].z
mov r2.z, cb4[11].z
dp3 r2.x, r0.xyzx, r2.xyzx
add r2.yzw, v3.xxyz, -cb3[25].xxyz
dp3 r2.y, r2.yzwy, r2.yzwy
sqrt r2.y, r2.y
add r2.y, -r2.x, r2.y
mad r2.x, cb3[25].w, r2.y, r2.x
mad_sat r2.x, r2.x, cb3[24].z, cb3[24].w
eq r2.y, cb5[0].x, l(1.000000)
if_nz r2.y
  eq r2.z, cb5[0].y, l(1.000000)
  mul r3.xyz, v3.yyyy, cb5[2].xyzx
  mad r3.xyz, cb5[1].xyzx, v3.xxxx, r3.xyzx
  mad r3.xyz, cb5[3].xyzx, v3.zzzz, r3.xyzx
  add r3.xyz, r3.xyzx, cb5[4].xyzx
  movc r3.xyz, r2.zzzz, r3.xyzx, v3.xyzx
  add r3.xyz, r3.xyzx, -cb5[6].xyzx
  mul r3.yzw, r3.xxyz, cb5[5].xxyz
  mad r2.z, r3.y, l(0.250000), l(0.750000)
  mad r2.w, cb5[0].z, l(0.500000), l(0.750000)
  max r3.x, r2.w, r2.z
  sample r3.xyzw, r3.xzwx, t2.xyzw, s0
else
  mov r3.xyzw, l(1.000000,1.000000,1.000000,1.000000)
endif
dp4_sat r2.z, r3.xyzw, cb2[45].xyzw
div r3.xy, v5.xyxx, v5.wwww
sample r3.xyzw, r3.xyxx, t1.xyzw, s1
add r2.z, r2.z, -r3.x
mad r2.x, r2.x, r2.z, r3.x
mul r2.xzw, r2.xxxx, cb0[2].xxyz
if_nz r2.y
  eq r2.y, cb5[0].y, l(1.000000)
  mul r3.xyz, v3.yyyy, cb5[2].xyzx
  mad r3.xyz, cb5[1].xyzx, v3.xxxx, r3.xyzx
  mad r3.xyz, cb5[3].xyzx, v3.zzzz, r3.xyzx
  add r3.xyz, r3.xyzx, cb5[4].xyzx
  movc r3.xyz, r2.yyyy, r3.xyzx, v3.xyzx
  add r3.xyz, r3.xyzx, -cb5[6].xyzx
  mul r3.yzw, r3.xxyz, cb5[5].xxyz
  mul r2.y, r3.y, l(0.250000)
  mul r3.y, cb5[0].z, l(0.500000)
  mad r4.x, -cb5[0].z, l(0.500000), l(0.250000)
  max r2.y, r2.y, r3.y
  min r3.x, r4.x, r2.y
  sample r4.xyzw, r3.xzwx, t2.xyzw, s0
  add r5.xyz, r3.xzwx, l(0.250000, 0.000000, 0.000000, 0.000000)
  sample r5.xyzw, r5.xyzx, t2.xyzw, s0
  add r3.xyz, r3.xzwx, l(0.500000, 0.000000, 0.000000, 0.000000)
  sample r3.xyzw, r3.xyzx, t2.xyzw, s0
  mov r6.xyz, v2.xyzx
  mov r6.w, l(1.000000)
  dp4 r4.x, r4.xyzw, r6.xyzw
  dp4 r4.y, r5.xyzw, r6.xyzw
  dp4 r4.z, r3.xyzw, r6.xyzw
else
  mov r3.xyz, v2.xyzx
  mov r3.w, l(1.000000)
  dp4 r4.x, cb2[38].xyzw, r3.xyzw
  dp4 r4.y, cb2[39].xyzw, r3.xyzw
  dp4 r4.z, cb2[40].xyzw, r3.xyzw
endif
add r3.xyz, r4.xyzx, v4.xyzx
max r3.xyz, r3.xyzx, l(0.000000, 0.000000, 0.000000, 0.000000)
mad r0.xyz, r0.xyzx, r0.wwww, cb2[0].xyzx
dp3 r0.w, r0.xyzx, r0.xyzx
rsq r0.w, r0.w
mul r0.xyz, r0.wwww, r0.xyzx
dp3 r0.w, v2.xyzx, cb2[0].xyzx
dp3 r0.x, v2.xyzx, r0.xyzx
max r0.xw, r0.xxxw, l(0.000000, 0.000000, 0.000000, 0.000000)
mul r0.y, cb0[69].x, l(128.000000)
log r0.x, r0.x
mul r0.x, r0.x, r0.y
exp r0.x, r0.x
mul r0.x, r1.w, r0.x
mul r4.xyz, r1.xyzx, r2.xzwx
mul r2.xyz, r2.xzwx, cb0[3].xyzx
mul r0.xyz, r0.xxxx, r2.xyzx
mad r0.xyz, r4.xyzx, r0.wwww, r0.xyzx
mad o0.xyz, r1.xyzx, r3.xyzx, r0.xyzx
mov o0.w, l(1.000000)
ret
// Approximately 0 instruction slots used