// asmtool.py -I ../.. --fix-unity-reflection --only-autofixed 9dd3fbda67327ea3-ps.txt
// 3DMigoto: 9dd3fbda67327ea3 |    Unity headers extracted from Legacy Shaders_Diffuse
//    Shader "Legacy Shaders/Diffuse" {
//      Fallback "Legacy Shaders/VertexLit"
//      SubShader 1/1 {
//        LOD 200
//        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_Diffuse:
//   API d3d11
//   Shader model ps_4_0
//   undeciphered1: 201609010 41 5 2
//   undeciphered1a: 4
//   Keywords { "DIRECTIONAL" "SHADOWS_SCREEN" "DIRLIGHTMAP_COMBINED" "DYNAMICLIGHTMAP_ON" "INSTANCING_ON" }
//   undeciphered2: 1 5 6 4 0 0
//   undeciphered3: 0 0
//   ConstBuffer "$Globals" 1120
//   Vector 16 [unity_DynamicLightmap_HDR]
//   Vector 32 [_LightColor0]
//   Vector 1088 [_Color]
//   ConstBuffer "UnityPerCamera" 144
//   Vector 64 [_WorldSpaceCameraPos] 3
//   ConstBuffer "UnityLighting" 752
//   Vector 0 [_WorldSpaceLightPos0]
//   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 3
//   SetTexture 1 [_ShadowMapTexture] 2D 2
//   SetTexture 2 [unity_DynamicLightmap] 2D 0
//   SetTexture 3 [unity_DynamicDirectionality] 2D -1
//   SetTexture 4 [unity_ProbeVolumeSH] 3D 1
//   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 17:59:38 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                 4   xyzw        4     NONE   float   xy w
// TEXCOORD                 6   xyzw        5     NONE   float     zw
// SV_InstanceID            0   x           6     NONE    uint
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target                0   xyzw        0   TARGET   float   xyzw
//
ps_4_0
dcl_constantbuffer cb0[69], 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_sampler s3, 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_texture3d (float,float,float,float) t4
dcl_input_ps linear v1.xy
dcl_input_ps linear v2.xyz
dcl_input_ps linear v3.xyz
dcl_input_ps linear v4.xyw
dcl_input_ps linear v5.zw
dcl_output o0.xyzw
dcl_temps 6
dcl_constantbuffer cb10[4], immediateIndexed

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

ld_indexable(texture2d)(float,float,float,float) r4.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 9dd3fbda67327ea3-ps.txt

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

sample r0.xyzw, v1.xyxx, t0.xyzw, s3
mul r0.xyz, r0.xyzx, cb0[68].xyzx
add r1.xyz, -v3.xyzx, r5.xyzx
mov r2.x, cb4[9].z
mov r2.y, cb4[10].z
mov r2.z, cb4[11].z
dp3 r0.w, r1.xyzx, r2.xyzx
add r1.xyz, v3.xyzx, -cb3[25].xyzx
dp3 r1.x, r1.xyzx, r1.xyzx
sqrt r1.x, r1.x
add r1.x, -r0.w, r1.x
mad r0.w, cb3[25].w, r1.x, r0.w
mad_sat r0.w, r0.w, cb3[24].z, cb3[24].w
eq r1.x, cb5[0].x, l(1.000000)
if_nz r1.x
  eq r1.x, cb5[0].y, l(1.000000)
  mul r1.yzw, v3.yyyy, cb5[2].xxyz
  mad r1.yzw, cb5[1].xxyz, v3.xxxx, r1.yyzw
  mad r1.yzw, cb5[3].xxyz, v3.zzzz, r1.yyzw
  add r1.yzw, r1.yyzw, cb5[4].xxyz
  movc r1.xyz, r1.xxxx, r1.yzwy, v3.xyzx
  add r1.xyz, r1.xyzx, -cb5[6].xyzx
  mul r1.yzw, r1.xxyz, cb5[5].xxyz
  mad r1.y, r1.y, l(0.250000), l(0.750000)
  mad r2.x, cb5[0].z, l(0.500000), l(0.750000)
  max r1.x, r1.y, r2.x
  sample r1.xyzw, r1.xzwx, t4.xyzw, s1
else
  mov r1.xyzw, l(1.000000,1.000000,1.000000,1.000000)
endif
dp4_sat r1.x, r1.xyzw, cb2[45].xyzw
div r1.yz, v4.xxyx, v4.wwww
sample r2.xyzw, r1.yzyy, t1.xyzw, s2
add r1.x, r1.x, -r2.x
mad r0.w, r0.w, r1.x, r2.x
mul r1.xyz, r0.wwww, cb0[2].xyzx
sample r2.xyzw, v5.zwzz, t2.xyzw, s0
mul r0.w, r2.w, cb0[1].x
mul r2.xyz, r2.xyzx, r0.wwww
log r2.xyz, r2.xyzx
mul r2.xyz, r2.xyzx, cb0[1].yyyy
exp r2.xyz, r2.xyzx
sample r3.xyzw, v5.zwzz, t3.xyzw, s0
add r3.xyz, r3.xyzx, l(-0.500000, -0.500000, -0.500000, 0.000000)
dp3 r0.w, v2.xyzx, r3.xyzx
add r0.w, r0.w, l(0.500000)
mul r2.xyz, r0.wwww, r2.xyzx
max r0.w, r3.w, l(0.000100)
div r2.xyz, r2.xyzx, r0.wwww
dp3 r0.w, v2.xyzx, cb2[0].xyzx
max r0.w, r0.w, l(0.000000)
mul r1.xyz, r0.xyzx, r1.xyzx
mul r0.xyz, r0.xyzx, r2.xyzx
mad o0.xyz, r1.xyzx, r0.wwww, r0.xyzx
mov o0.w, l(1.000000)
ret
// Approximately 0 instruction slots used