// asmtool.py -I ../.. --fix-unity-reflection --only-autofixed e77fcc5e5a8410dd-ps.txt
// 3DMigoto: e77fcc5e5a8410dd |    Unity headers extracted from Nature_Terrain_Standard
//    Shader "Nature/Terrain/Standard" {
//      Fallback "Nature/Terrain/Diffuse"
//      SubShader 1/1 {
//        Tags { "QUEUE"="Geometry-100" "RenderType"="Opaque" }
//        Pass 1/4 {
//          Name "FORWARD"
//          Tags { "LIGHTMODE"="FORWARDBASE" "QUEUE"="Geometry-100" "RenderType"="Opaque" "SHADOWSUPPORT"="true" }
//          Program "fp" {
//            SubProgram "d3d11" {
//            }
//          }
//        }
//      }
//    }
//
// Unity 5.3 headers extracted from Nature_Terrain_Standard:
//   API d3d11
//   Shader model ps_4_0
//   undeciphered1: 201609010 176 12 6
//   undeciphered1a: 14
//   Keywords { "DIRECTIONAL" "DIRLIGHTMAP_COMBINED" "DYNAMICLIGHTMAP_ON" "_TERRAIN_NORMAL_MAP" }
//   undeciphered2: 1 14 5 12 0 0
//   undeciphered3: 0 0
//   ConstBuffer "$Globals" 1200
//   Vector 16 [unity_DynamicLightmap_HDR]
//   Vector 32 [_LightColor0]
//   Float 1104 [_Metallic0]
//   Float 1108 [_Metallic1]
//   Float 1112 [_Metallic2]
//   Float 1116 [_Metallic3]
//   Float 1120 [_Smoothness0]
//   Float 1124 [_Smoothness1]
//   Float 1128 [_Smoothness2]
//   Float 1132 [_Smoothness3]
//   ConstBuffer "UnityPerCamera" 144
//   Vector 64 [_WorldSpaceCameraPos] 3
//   ConstBuffer "UnityLighting" 752
//   Vector 0 [_WorldSpaceLightPos0]
//   Vector 720 [unity_OcclusionMaskSelector]
//   ConstBuffer "UnityReflectionProbes" 128
//   Vector 0 [unity_SpecCube0_BoxMax]
//   Vector 16 [unity_SpecCube0_BoxMin]
//   Vector 32 [unity_SpecCube0_ProbePosition]
//   Vector 48 [unity_SpecCube0_HDR]
//   Vector 64 [unity_SpecCube1_BoxMax]
//   Vector 80 [unity_SpecCube1_BoxMin]
//   Vector 96 [unity_SpecCube1_ProbePosition]
//   Vector 112 [unity_SpecCube1_HDR]
//   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 3
//   SetTexture 1 [_Splat0] 2D 4
//   SetTexture 2 [_Splat1] 2D 5
//   SetTexture 3 [_Splat2] 2D 6
//   SetTexture 4 [_Splat3] 2D 7
//   SetTexture 5 [_Normal0] 2D 8
//   SetTexture 6 [_Normal1] 2D 9
//   SetTexture 7 [_Normal2] 2D 10
//   SetTexture 8 [_Normal3] 2D 11
//   SetTexture 9 [unity_DynamicLightmap] 2D 0
//   SetTexture 10 [unity_DynamicDirectionality] 2D -1
//   SetTexture 11 [unity_SpecCube0] CUBE 1
//   SetTexture 12 [unity_SpecCube1] CUBE -1
//   SetTexture 13 [unity_ProbeVolumeSH] 3D 2
//   BindCB "$Globals" 0
//   BindCB "UnityPerCamera" 1
//   BindCB "UnityLighting" 2
//   BindCB "UnityReflectionProbes" 3
//   BindCB "UnityProbeVolume" 4
//
// 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:03:36 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                 8   xyzw        7     NONE   float     zw
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target                0   xyzw        0   TARGET   float   xyzw
//
ps_4_0
dcl_constantbuffer cb0[71], immediateIndexed
dcl_constantbuffer cb1[9], immediateIndexed
dcl_constantbuffer cb2[46], immediateIndexed
dcl_constantbuffer cb3[8], immediateIndexed
dcl_constantbuffer cb4[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_sampler s10, mode_default
dcl_sampler s11, 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_texture2d (float,float,float,float) t9
dcl_resource_texture2d (float,float,float,float) t10
dcl_resource_texturecube (float,float,float,float) t11
dcl_resource_texturecube (float,float,float,float) t12
dcl_resource_texture3d (float,float,float,float) t13
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.zw
dcl_output o0.xyzw
dcl_temps 16
dcl_constantbuffer cb10[4], immediateIndexed

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

ld_indexable(texture2d)(float,float,float,float) r14.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 e77fcc5e5a8410dd-ps.txt

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

mov r0.x, v3.w
mov r0.y, v4.w
mov r0.z, v5.w
add r1.xyz, -r0.xyzx, r15.xyzx
dp3 r0.w, r1.xyzx, r1.xyzx
rsq r0.w, r0.w
mul r2.xyz, r0.wwww, r1.xyzx
sample r3.xyzw, v6.xyxx, t0.xyzw, s3
dp4 r1.w, r3.xyzw, l(1.000000, 1.000000, 1.000000, 1.000000)
add r2.w, r1.w, l(0.001000)
div r3.xyzw, r3.xyzw, r2.wwww
sample r4.xyzw, v1.xyxx, t1.xyzw, s4
mul r4.xyzw, r3.xxxx, r4.xyzw
mul r4.w, r4.w, cb0[70].x
sample r5.xyzw, v1.zwzz, t2.xyzw, s5
mul r5.xyzw, r3.yyyy, r5.xyzw
mul r5.w, r5.w, cb0[70].y
add r4.xyzw, r4.xyzw, r5.xyzw
sample r5.xyzw, v2.xyxx, t3.xyzw, s6
mul r5.xyzw, r3.zzzz, r5.xyzw
mul r5.w, r5.w, cb0[70].z
add r4.xyzw, r4.xyzw, r5.xyzw
sample r5.xyzw, v2.zwzz, t4.xyzw, s7
mul r5.xyzw, r3.wwww, r5.xyzw
mul r5.w, r5.w, cb0[70].w
add r4.xyzw, r4.xyzw, r5.xyzw
sample r5.xyzw, v1.xyxx, t5.xyzw, s8
sample r6.xyzw, v1.zwzz, t6.xyzw, s9
mul r5.xz, r3.yyyy, r6.wwyw
mad r5.xy, r3.xxxx, r5.wyww, r5.xzxx
sample r6.xyzw, v2.xyxx, t7.xyzw, s10
mad r5.xy, r3.zzzz, r6.wyww, r5.xyxx
sample r6.xyzw, v2.zwzz, t8.xyzw, s11
mad r5.xy, r3.wwww, r6.wyww, r5.xyxx
mad r5.xy, r5.xyxx, l(2.000000, 2.000000, 0.000000, 0.000000), l(-1.000000, -1.000000, 0.000000, 0.000000)
dp2 r2.w, r5.xyxx, r5.xyxx
min r2.w, r2.w, l(1.000000)
add r2.w, -r2.w, l(1.000000)
sqrt r5.z, r2.w
dp4 r2.w, r3.xyzw, cb0[69].xyzw
eq r3.x, cb4[0].x, l(1.000000)
if_nz r3.x
  eq r3.x, cb4[0].y, l(1.000000)
  mul r3.yzw, v4.wwww, cb4[2].xxyz
  mad r3.yzw, cb4[1].xxyz, v3.wwww, r3.yyzw
  mad r3.yzw, cb4[3].xxyz, v5.wwww, r3.yyzw
  add r3.yzw, r3.yyzw, cb4[4].xxyz
  movc r3.xyz, r3.xxxx, r3.yzwy, r0.xyzx
  add r3.xyz, r3.xyzx, -cb4[6].xyzx
  mul r3.yzw, r3.xxyz, cb4[5].xxyz
  mad r3.y, r3.y, l(0.250000), l(0.750000)
  mad r5.w, cb4[0].z, l(0.500000), l(0.750000)
  max r3.x, r3.y, r5.w
  sample r3.xyzw, r3.xzwx, t13.xyzw, s2
else
  mov r3.xyzw, l(1.000000,1.000000,1.000000,1.000000)
endif
dp4_sat r3.x, r3.xyzw, cb2[45].xyzw
dp3 r6.x, v3.xyzx, r5.xyzx
dp3 r6.y, v4.xyzx, r5.xyzx
dp3 r6.z, v5.xyzx, r5.xyzx
add r3.y, -r4.w, l(1.000000)
dp3 r3.z, -r2.xyzx, r6.xyzx
add r3.z, r3.z, r3.z
mad r5.xyz, r6.xyzx, -r3.zzzz, -r2.xyzx
mul r3.xzw, r3.xxxx, cb0[2].xxyz
sample r7.xyzw, v7.zwzz, t9.xyzw, s0
mul r5.w, r7.w, cb0[1].x
mul r7.xyz, r7.xyzx, r5.wwww
log r7.xyz, r7.xyzx
mul r7.xyz, r7.xyzx, cb0[1].yyyy
exp r7.xyz, r7.xyzx
sample r8.xyzw, v7.zwzz, t10.xyzw, s0
add r8.xyz, r8.xyzx, l(-0.500000, -0.500000, -0.500000, 0.000000)
dp3 r5.w, r6.xyzx, r8.xyzx
add r5.w, r5.w, l(0.500000)
mul r7.xyz, r5.wwww, r7.xyzx
max r5.w, r8.w, l(0.000100)
div r7.xyz, r7.xyzx, r5.wwww
lt r5.w, l(0.000000), cb3[2].w
if_nz r5.w
  dp3 r5.w, r5.xyzx, r5.xyzx
  rsq r5.w, r5.w
  mul r8.xyz, r5.wwww, r5.xyzx
  add r9.xyz, -r0.xyzx, cb3[0].xyzx
  div r9.xyz, r9.xyzx, r8.xyzx
  add r10.xyz, -r0.xyzx, cb3[1].xyzx
  div r10.xyz, r10.xyzx, r8.xyzx
  lt r11.xyz, l(0.000000, 0.000000, 0.000000, 0.000000), r8.xyzx
  movc r9.xyz, r11.xyzx, r9.xyzx, r10.xyzx
  min r5.w, r9.y, r9.x
  min r5.w, r9.z, r5.w
  add r9.xyz, r0.xyzx, -cb3[2].xyzx
  mad r8.xyz, r8.xyzx, r5.wwww, r9.xyzx
else
  mov r8.xyz, r5.xyzx
endif
mad r5.w, -r3.y, l(0.700000), l(1.700000)
mul r5.w, r3.y, r5.w
mul r5.w, r5.w, l(6.000000)
sample_l r8.xyzw, r8.xyzx, t11.xyzw, s1, r5.w
add r6.w, r8.w, l(-1.000000)
mad r6.w, cb3[3].w, r6.w, l(1.000000)
log r6.w, r6.w
mul r6.w, r6.w, cb3[3].y
exp r6.w, r6.w
mul r6.w, r6.w, cb3[3].x
mul r9.xyz, r8.xyzx, r6.wwww
lt r7.w, cb3[1].w, l(0.999990)
if_nz r7.w
  lt r7.w, l(0.000000), cb3[6].w
  if_nz r7.w
    dp3 r7.w, r5.xyzx, r5.xyzx
    rsq r7.w, r7.w
    mul r10.xyz, r5.xyzx, r7.wwww
    add r11.xyz, -r0.xyzx, cb3[4].xyzx
    div r11.xyz, r11.xyzx, r10.xyzx
    add r12.xyz, -r0.xyzx, cb3[5].xyzx
    div r12.xyz, r12.xyzx, r10.xyzx
    lt r13.xyz, l(0.000000, 0.000000, 0.000000, 0.000000), r10.xyzx
    movc r11.xyz, r13.xyzx, r11.xyzx, r12.xyzx
    min r7.w, r11.y, r11.x
    min r7.w, r11.z, r7.w
    add r0.xyz, r0.xyzx, -cb3[6].xyzx
    mad r5.xyz, r10.xyzx, r7.wwww, r0.xyzx
  endif
  sample_l r5.xyzw, r5.xyzx, t12.xyzw, s1, r5.w
  add r0.x, r5.w, l(-1.000000)
  mad r0.x, cb3[7].w, r0.x, l(1.000000)
  log r0.x, r0.x
  mul r0.x, r0.x, cb3[7].y
  exp r0.x, r0.x
  mul r0.x, r0.x, cb3[7].x
  mul r0.xyz, r5.xyzx, r0.xxxx
  mad r5.xyz, r6.wwww, r8.xyzx, -r0.xyzx
  mad r9.xyz, cb3[1].wwww, r5.xyzx, r0.xyzx
endif
dp3 r0.x, r6.xyzx, r6.xyzx
rsq r0.x, r0.x
mul r0.xyz, r0.xxxx, r6.xyzx
add r5.xyz, r4.xyzx, l(-0.040000, -0.040000, -0.040000, 0.000000)
mad r5.xyz, r2.wwww, r5.xyzx, l(0.040000, 0.040000, 0.040000, 0.000000)
mad r2.w, -r2.w, l(0.960000), l(0.960000)
mul r4.xyz, r2.wwww, r4.xyzx
mad r1.xyz, r1.xyzx, r0.wwww, cb2[0].xyzx
dp3 r0.w, r1.xyzx, r1.xyzx
max r0.w, r0.w, l(0.001000)
rsq r0.w, r0.w
mul r1.xyz, r0.wwww, r1.xyzx
dp3 r0.w, r0.xyzx, r2.xyzx
dp3_sat r2.x, r0.xyzx, cb2[0].xyzx
dp3_sat r0.x, r0.xyzx, r1.xyzx
dp3_sat r0.y, cb2[0].xyzx, r1.xyzx
mul r0.z, r0.y, r0.y
dp2 r0.z, r0.zzzz, r3.yyyy
add r0.z, r0.z, l(-0.500000)
add r1.x, -r2.x, l(1.000000)
mul r1.y, r1.x, r1.x
mul r1.y, r1.y, r1.y
mul r1.x, r1.x, r1.y
mad r1.x, r0.z, r1.x, l(1.000000)
add r1.y, -|r0.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.z, r0.z, r1.y, l(1.000000)
mul r0.z, r0.z, r1.x
mul r1.x, r3.y, r3.y
mad r1.z, -r3.y, r3.y, l(1.000000)
mad r2.y, |r0.w|, r1.z, r1.x
mad r1.z, r2.x, r1.z, r1.x
mul r0.w, |r0.w|, r1.z
mad r0.w, r2.x, r2.y, r0.w
add r0.w, r0.w, l(0.000010)
div r0.w, l(0.500000), r0.w
mul r1.z, r1.x, r1.x
mad r2.y, r0.x, r1.z, -r0.x
mad r0.x, r2.y, r0.x, l(1.000000)
mul r1.z, r1.z, l(0.318309873)
mad r0.x, r0.x, r0.x, l(1.000000012E-007)
div r0.x, r1.z, r0.x
mul r0.x, r0.x, r0.w
mul r0.x, r0.x, l(3.14159274)
mul r0.xz, r2.xxxx, r0.xxzx
max r0.x, r0.x, l(0.000000)
mad r0.w, r1.x, r1.x, l(1.000000)
div r0.w, l(1.000000, 1.000000, 1.000000, 1.000000), r0.w
dp3 r1.x, r5.xyzx, r5.xyzx
ne r1.x, r1.x, l(0.000000)
and r1.x, r1.x, l(0x3f800000)
mul r0.x, r0.x, r1.x
add r1.x, -r2.w, r4.w
add_sat r1.x, r1.x, l(1.000000)
mad r2.xyz, r3.xzwx, r0.zzzz, r7.xyzx
mul r3.xyz, r3.xzwx, r0.xxxx
add r0.x, -r0.y, l(1.000000)
mul r0.y, r0.x, r0.x
mul r0.y, r0.y, r0.y
mul r0.x, r0.x, r0.y
add r6.xyz, -r5.xyzx, l(1.000000, 1.000000, 1.000000, 0.000000)
mad r0.xyz, r6.xyzx, r0.xxxx, r5.xyzx
mul r0.xyz, r0.xyzx, r3.xyzx
mad r0.xyz, r4.xyzx, r2.xyzx, r0.xyzx
mul r2.xyz, r9.xyzx, r0.wwww
add r3.xyz, -r5.xyzx, r1.xxxx
mad r1.xyz, r1.yyyy, r3.xyzx, r5.xyzx
mad r0.xyz, r2.xyzx, r1.xyzx, r0.xyzx
mul o0.xyz, r1.wwww, r0.xyzx
mov o0.w, l(1.000000)
ret
// Approximately 0 instruction slots used