// asmtool.py -I ../.. --fix-unity-reflection --only-autofixed 0fa361d1779853bf-ps.txt
// 3DMigoto: 0fa361d1779853bf |    Unity headers extracted from Nature_Terrain_Specular
//    Shader "Nature/Terrain/Specular" {
//      Fallback "Nature/Terrain/Diffuse"
//      SubShader 1/1 {
//        Tags { "QUEUE"="Geometry-100" "RenderType"="Opaque" }
//        Pass 1/6 {
//          Name "FORWARD"
//          Tags { "LIGHTMODE"="FORWARDBASE" "QUEUE"="Geometry-100" "RenderType"="Opaque" "SHADOWSUPPORT"="true" }
//          Program "fp" {
//            SubProgram "d3d11" {
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from Nature_Terrain_Specular:
//   API d3d11
//   Shader model ps_4_0
//   undeciphered1: 201609010 75 13 4
//   undeciphered1a: 8
//   Keywords { "DIRECTIONAL" "_TERRAIN_NORMAL_MAP" }
//   undeciphered2: 1 10 4 10 0 0
//   undeciphered3: 0 0
//   ConstBuffer "$Globals" 1184
//   Vector 32 [_LightColor0]
//   Vector 48 [_SpecColor]
//   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 "UnityProbeVolume" 112
//   Vector 0 [unity_ProbeVolumeParams]
//   Vector 80 [unity_ProbeVolumeSizeInv] 3
//   Vector 96 [unity_ProbeVolumeMin] 3
//   Matrix 16 [unity_ProbeVolumeWorldToObject]
//   SetTexture 0 [_Control] 2D 1
//   SetTexture 1 [_Splat0] 2D 2
//   SetTexture 2 [_Splat1] 2D 3
//   SetTexture 3 [_Splat2] 2D 4
//   SetTexture 4 [_Splat3] 2D 5
//   SetTexture 5 [_Normal0] 2D 6
//   SetTexture 6 [_Normal1] 2D 7
//   SetTexture 7 [_Normal2] 2D 8
//   SetTexture 8 [_Normal3] 2D 9
//   SetTexture 9 [unity_ProbeVolumeSH] 3D 0
//   BindCB "$Globals" 0
//   BindCB "UnityPerCamera" 1
//   BindCB "UnityLighting" 2
//   BindCB "UnityProbeVolume" 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:51:57 2019
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_POSITION              0   xyzw        0      POS   float
// TEXCOORD                 0   xyzw        1     NONE   float   xyzw
// TEXCOORD                 1   xyzw        2     NONE   float   xyzw
// TEXCOORD                 2   xyzw        3     NONE   float   xyzw
// TEXCOORD                 3   xyzw        4     NONE   float   xyzw
// TEXCOORD                 4   xyzw        5     NONE   float   xyzw
// TEXCOORD                 5   xy          6     NONE   float   xy
// TEXCOORD                 7     zw        6     NONE   float
// TEXCOORD                 6   xyz         7     NONE   float   xyz
// TEXCOORD                 8   xyzw        8     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[7], 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_sampler s6, mode_default
dcl_sampler s7, mode_default
dcl_sampler s8, mode_default
dcl_sampler s9, 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_resource_texture2d (float,float,float,float) t6
dcl_resource_texture2d (float,float,float,float) t7
dcl_resource_texture2d (float,float,float,float) t8
dcl_resource_texture3d (float,float,float,float) t9
dcl_input_ps linear v1.xyzw
dcl_input_ps linear v2.xyzw
dcl_input_ps linear v3.xyzw
dcl_input_ps linear v4.xyzw
dcl_input_ps linear v5.xyzw
dcl_input_ps linear v6.xy
dcl_input_ps linear v7.xyz
dcl_output o0.xyzw
dcl_temps 10
dcl_constantbuffer cb10[4], immediateIndexed

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

ld_indexable(texture2d)(float,float,float,float) r8.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 0fa361d1779853bf-ps.txt

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

mov r0.y, v3.w
mov r0.z, v4.w
mov r0.w, v5.w
add r1.xyz, -r0.yzwy, r9.xyzx
dp3 r0.x, r1.xyzx, r1.xyzx
rsq r0.x, r0.x
sample r2.xyzw, v6.xyxx, t0.xyzw, s1
dp4 r1.w, r2.xyzw, l(1.000000, 1.000000, 1.000000, 1.000000)
add r3.x, r1.w, l(0.001000)
div r2.xyzw, r2.xyzw, r3.xxxx
sample r3.xyzw, v1.xyxx, t1.xyzw, s2
sample r4.xyzw, v1.zwzz, t2.xyzw, s3
mul r4.xyzw, r2.yyyy, r4.xyzw
mad r3.xyzw, r2.xxxx, r3.xyzw, r4.xyzw
sample r4.xyzw, v2.xyxx, t3.xyzw, s4
mad r3.xyzw, r2.zzzz, r4.xyzw, r3.xyzw
sample r4.xyzw, v2.zwzz, t4.xyzw, s5
mad r3.xyzw, r2.wwww, r4.xyzw, r3.xyzw
sample r4.xyzw, v1.xyxx, t5.xyzw, s6
sample r5.xyzw, v1.zwzz, t6.xyzw, s7
mul r4.xz, r2.yyyy, r5.wwyw
mad r2.xy, r2.xxxx, r4.wyww, r4.xzxx
sample r4.xyzw, v2.xyxx, t7.xyzw, s8
mad r2.xy, r2.zzzz, r4.wyww, r2.xyxx
sample r4.xyzw, v2.zwzz, t8.xyzw, s9
mad r2.xy, r2.wwww, r4.wyww, r2.xyxx
mad r2.xy, r2.xyxx, l(2.000000, 2.000000, 0.000000, 0.000000), l(-1.000000, -1.000000, 0.000000, 0.000000)
dp2 r2.w, r2.xyxx, r2.xyxx
min r2.w, r2.w, l(1.000000)
add r2.w, -r2.w, l(1.000000)
sqrt r2.z, r2.w
eq r2.w, cb3[0].x, l(1.000000)
if_nz r2.w
  eq r4.x, cb3[0].y, l(1.000000)
  mul r4.yzw, v4.wwww, cb3[2].xxyz
  mad r4.yzw, cb3[1].xxyz, v3.wwww, r4.yyzw
  mad r4.yzw, cb3[3].xxyz, v5.wwww, r4.yyzw
  add r4.yzw, r4.yyzw, cb3[4].xxyz
  movc r4.xyz, r4.xxxx, r4.yzwy, r0.yzwy
  add r4.xyz, r4.xyzx, -cb3[6].xyzx
  mul r4.yzw, r4.xxyz, cb3[5].xxyz
  mad r4.y, r4.y, l(0.250000), l(0.750000)
  mad r5.x, cb3[0].z, l(0.500000), l(0.750000)
  max r4.x, r4.y, r5.x
  sample r4.xyzw, r4.xzwx, t9.xyzw, s0
else
  mov r4.xyzw, l(1.000000,1.000000,1.000000,1.000000)
endif
dp4_sat r4.x, r4.xyzw, cb2[45].xyzw
dp3 r5.x, v3.xyzx, r2.xyzx
dp3 r5.y, v4.xyzx, r2.xyzx
dp3 r5.z, v5.xyzx, r2.xyzx
mul r2.xyz, r4.xxxx, cb0[2].xyzx
if_nz r2.w
  eq r2.w, cb3[0].y, l(1.000000)
  mul r4.xyz, v4.wwww, cb3[2].xyzx
  mad r4.xyz, cb3[1].xyzx, v3.wwww, r4.xyzx
  mad r4.xyz, cb3[3].xyzx, v5.wwww, r4.xyzx
  add r4.xyz, r4.xyzx, cb3[4].xyzx
  movc r0.yzw, r2.wwww, r4.xxyz, r0.yyzw
  add r0.yzw, r0.yyzw, -cb3[6].xxyz
  mul r4.yzw, r0.yyzw, cb3[5].xxyz
  mul r0.y, r4.y, l(0.250000)
  mul r0.z, cb3[0].z, l(0.500000)
  mad r0.w, -cb3[0].z, l(0.500000), l(0.250000)
  max r0.y, r0.z, r0.y
  min r4.x, r0.w, r0.y
  sample r6.xyzw, r4.xzwx, t9.xyzw, s0
  add r0.yzw, r4.xxzw, l(0.000000, 0.250000, 0.000000, 0.000000)
  sample r7.xyzw, r0.yzwy, t9.xyzw, s0
  add r0.yzw, r4.xxzw, l(0.000000, 0.500000, 0.000000, 0.000000)
  sample r4.xyzw, r0.yzwy, t9.xyzw, s0
  mov r5.w, l(1.000000)
  dp4 r6.x, r6.xyzw, r5.xyzw
  dp4 r6.y, r7.xyzw, r5.xyzw
  dp4 r6.z, r4.xyzw, r5.xyzw
else
  mov r5.w, l(1.000000)
  dp4 r6.x, cb2[38].xyzw, r5.xyzw
  dp4 r6.y, cb2[39].xyzw, r5.xyzw
  dp4 r6.z, cb2[40].xyzw, r5.xyzw
endif
add r0.yzw, r6.xxyz, v7.xxyz
mad r1.xyz, r1.xyzx, r0.xxxx, cb2[0].xyzx
dp3 r0.x, r1.xyzx, r1.xyzx
rsq r0.x, r0.x
mul r1.xyz, r0.xxxx, r1.xyzx
dp3 r0.x, r5.xyzx, cb2[0].xyzx
max r0.xyzw, r0.xyzw, l(0.000000, 0.000000, 0.000000, 0.000000)
dp3 r1.x, r5.xyzx, r1.xyzx
max r1.x, r1.x, l(0.000000)
mul r1.y, cb0[69].x, l(128.000000)
log r1.x, r1.x
mul r1.x, r1.x, r1.y
exp r1.x, r1.x
mul r1.x, r3.w, r1.x
mul r4.xyz, r2.xyzx, r3.xyzx
mul r2.xyz, r2.xyzx, cb0[3].xyzx
mul r1.xyz, r1.xxxx, r2.xyzx
mad r1.xyz, r4.xyzx, r0.xxxx, r1.xyzx
mad r0.xyz, r3.xyzx, r0.yzwy, r1.xyzx
mul o0.xyz, r1.wwww, r0.xyzx
mov o0.w, l(1.000000)
ret
// Approximately 0 instruction slots used