// asmtool.py -I ../.. --fix-unity-reflection --only-autofixed db1eaf920c5c3f55-ps.txt
// 3DMigoto: db1eaf920c5c3f55 |    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: 201708220 23 3 0
//   undeciphered1a: 3
//   Keywords { "DIRECTIONAL" "SHADOWS_SCREEN" "LIGHTMAP_ON" "LIGHTMAP_SHADOW_MIXING" }
//   undeciphered2: 1 3 5 3 0 0
//   undeciphered3: 0 0
//   ConstBuffer "$Globals" 96
//   Vector 0 [unity_Lightmap_HDR]
//   Vector 32 [_LightColor0]
//   Vector 64 [_Color]
//   ConstBuffer "UnityPerCamera" 144
//   Vector 64 [_WorldSpaceCameraPos] 3
//   ConstBuffer "UnityLighting" 768
//   Vector 0 [_WorldSpaceLightPos0]
//   ConstBuffer "UnityShadows" 416
//   Vector 384 [_LightShadowData]
//   Vector 400 [unity_ShadowFadeCenterAndType]
//   ConstBuffer "UnityPerFrame" 368
//   Vector 352 [unity_ShadowColor]
//   Matrix 144 [unity_MatrixV]
//   SetTexture 0 [_MainTex] 2D 20
//   SetTexture 1 [_ShadowMapTexture] 2D 10
//   SetTexture 2 [unity_Lightmap] 2D 00
//   BindCB "$Globals" 0
//   BindCB "UnityPerCamera" 1
//   BindCB "UnityLighting" 2
//   BindCB "UnityShadows" 3
//   BindCB "UnityPerFrame" 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.2 on Mon Jan 14 19:36:39 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   xyzw        4     NONE   float   xy
// TEXCOORD                 5   xyzw        5     NONE   float   xy w
//
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target                0   xyzw        0   TARGET   float   xyzw
//
ps_4_0
dcl_constantbuffer cb0[5], immediateIndexed
dcl_constantbuffer cb1[9], immediateIndexed
dcl_constantbuffer cb2[1], immediateIndexed
dcl_constantbuffer cb3[26], immediateIndexed
dcl_constantbuffer cb4[23], 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_texture2d (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.xy
dcl_input_ps linear v5.xyw
dcl_output o0.xyzw
dcl_temps 5
dcl_constantbuffer cb10[4], immediateIndexed

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

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

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

add r0.xyz, v3.xyzx, -cb3[25].xyzx
dp3 r0.x, r0.xyzx, r0.xyzx
sqrt r0.x, r0.x
add r0.yzw, -v3.xxyz, r4.xxyz
mov r1.x, cb4[9].z
mov r1.y, cb4[10].z
mov r1.z, cb4[11].z
dp3 r0.y, r0.yzwy, r1.xyzx
add r0.x, -r0.y, r0.x
mad r0.x, cb3[25].w, r0.x, r0.y
mad_sat r0.x, r0.x, cb3[24].z, cb3[24].w
div r0.yz, v5.xxyx, v5.wwww
sample r1.xyzw, r0.yzyy, t1.xyzw, s1
add_sat r0.x, r0.x, r1.x
add r0.x, -r0.x, l(1.000000)
dp3 r0.y, v2.xyzx, cb2[0].xyzx
max r0.y, r0.y, l(0.000000)
mul r0.x, r0.x, r0.y
sample r1.xyzw, v4.xyxx, t2.xyzw, s0
mul r0.y, r1.w, cb0[0].x
mul r2.xyz, r1.xyzx, r0.yyyy
mad r0.xzw, -r0.xxxx, cb0[2].xxyz, r2.xxyz
max r0.xzw, r0.xxzw, cb4[22].xxyz
mad r1.xyz, r0.yyyy, r1.xyzx, -r0.xzwx
mad r0.xyz, cb3[24].xxxx, r1.xyzx, r0.xzwx
min r0.xyz, r0.xyzx, r2.xyzx
sample r1.xyzw, v1.xyxx, t0.xyzw, s2
mul r1.xyz, r1.xyzx, cb0[4].xyzx
mul o0.xyz, r0.xyzx, r1.xyzx
mov o0.w, l(1.000000)
ret
// Approximately 0 instruction slots used