Skip to content

Commit

Permalink
FCPrimal: Apply scripted volumetric fog fix
Browse files Browse the repository at this point in the history
This changes all VFLightVolumeTexture and combining fog volume shaders
to use the one pattern that seems to be pretty universal.

Need to check if point lights still work ok with this change, or if they
will need more work.
  • Loading branch information
DarkStarSword committed Mar 12, 2016
1 parent 95bb73e commit 53458ac
Show file tree
Hide file tree
Showing 16 changed files with 301 additions and 458 deletions.
80 changes: 18 additions & 62 deletions Far Cry Primal/ShaderFixes/008f4b4539a0cab7-cs.txt
@@ -1,17 +1,4 @@
// Volumetric fog - Populates VFLightVolumeTexture (point lights)
// Related shaders:
// CS 008f4b4539a0cab7 - VFLightVolumeTexture (point lights)
// CS ad7a6a5c9182e26e - VFLightVolumeTexture (point lights in cutscenes)
// CS 79d2dd1629dd2fd3 - VFLightVolumeTexture (point lights in enemy camp)
// CS 63156ad276e52990 - VFLightVolumeTexture (light shafts in cave)
// CS 8b431e0726c6115e - VFShadowVolumeTexture (light shafts outside)
// CS 6bdcbf1223c89177 - VFShadowVolumeTexture (as above, but for cutscenes)
// CS 5b5e5a3ac5bc8145 - VFDensityVolumeTexture (bad density near mountains)
// CS ac73802804100e3f - combines this & other fog buffers together
// CS b353330000eff5ed - intermediate stage
// CS 30f0ac937c0b3451 - intermediate stage x 2
// PS 2b6cfbaa250d7a51 - output to screen

// asmtool.py -i --fix-fcprimal-volumetric-fog --only-autofixed -f 008f4b4539a0cab7-cs.txt
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
Expand Down Expand Up @@ -181,6 +168,7 @@ dcl_input vThreadIDInGroup.xyz
dcl_temps 14
dcl_thread_group 2, 2, 64

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

ld_indexable(texture2d)(float,float,float,float) r11.xyzw, l(0, 0, 0, 0), t125.xyzw
Expand Down Expand Up @@ -230,6 +218,22 @@ if_nz r1.x
add r1.x, r1.y, r1.x
mul r1.x, r1.x, l(0.500000)
mad r1.yzw, r2.xxyz, r1.xxxx, cb0[42].xxyz

// Volumetric Fog fix inserted with DarkStarSword's asmtool.py:
// asmtool.py -i --fix-fcprimal-volumetric-fog --only-autofixed -f 008f4b4539a0cab7-cs.txt

mov r12.xyz, r1.yzwx
mov r12.w, l(1.0)
dp4 r13.w, r12.xyzw, cb0[19].xyzw
add r13.x, r13.w, -r11.y
mul r13.x, r13.x, -r11.x
mul r13.x, r13.x, cb0[0].x
mov r13.yzw, l(0.0)
dp4 r12.x, r13.xyzw, cb0[4].xyzw
dp4 r12.y, r13.xyzw, cb0[5].xyzw
dp4 r12.z, r13.xyzw, cb0[6].xyzw
add r1.yzw, r1.xyzw, r12.xxyz

imad r2.xyzw, r0.xyxy, cb1[22].wwww, l(4, 4, 12, 4)
ushr r2.xyzw, r2.xyzw, l(3, 3, 3, 3)
imad r2.xy, r2.ywyy, cb2[13].xxxx, r2.xzxx
Expand Down Expand Up @@ -273,34 +277,10 @@ if_nz r1.x
ishl r5.w, l(1), r4.w
not r5.w, r5.w
and r5.w, r3.w, r5.w

// LightsLightingData
ld_structured_indexable(structured_buffer, stride=128)(mixed,mixed,mixed,mixed) r6.xyz, r4.w, l(0), t1.xyzx
ld_structured_indexable(structured_buffer, stride=128)(mixed,mixed,mixed,mixed) r7.xyzw, r4.w, l(16), t1.xyzw
ld_structured_indexable(structured_buffer, stride=128)(mixed,mixed,mixed,mixed) r8.xyz, r4.w, l(32), t1.xyzx
ld_structured_indexable(structured_buffer, stride=128)(mixed,mixed,mixed,mixed) r9.xyzw, r4.w, l(48), t1.xyzw

// Correct volumetric fog around point lights:
mov r12.xyz, r6.xyz
mov r12.w, l(1.0)
// ViewProjectionMatrix:
dp4 r13.w, r12.xyzw, cb0[19].xyzw
// Adjustment amount:
add r11.w, r13.w, -r11.y
mul r13.x, r11.w, r11.x
mov r13.yzw, l(0.0)
// InvProjectionMatrix:
dp4 r12.x, r13.xyzw, cb0[0].xyzw
dp4 r12.y, r13.xyzw, cb0[1].xyzw
dp4 r12.z, r13.xyzw, cb0[2].xyzw
dp4 r12.w, r13.xyzw, cb0[3].xyzw
// InvViewMatrix:
dp4 r13.x, r12.xyzw, cb0[4].xyzw
dp4 r13.y, r12.xyzw, cb0[5].xyzw
dp4 r13.z, r12.xyzw, cb0[6].xyzw
// Add adjustment:
add r6.xyz, r6.xyz, r13.xyz

and r4.w, r9.w, l(1)
ult r4.w, l(0), r4.w
add r6.xyz, -r1.yzwy, r6.xyzx
Expand Down Expand Up @@ -349,34 +329,10 @@ add r6.xyz, r6.xyz, r13.xyz
not r6.x, r6.x
and r6.x, r2.x, r6.x
iadd r5.w, l(32), r5.w

// LightsLightingData
ld_structured_indexable(structured_buffer, stride=128)(mixed,mixed,mixed,mixed) r6.yzw, r5.w, l(0), t1.xxyz
ld_structured_indexable(structured_buffer, stride=128)(mixed,mixed,mixed,mixed) r7.xyzw, r5.w, l(16), t1.xyzw
ld_structured_indexable(structured_buffer, stride=128)(mixed,mixed,mixed,mixed) r8.xyz, r5.w, l(32), t1.xyzx
ld_structured_indexable(structured_buffer, stride=128)(mixed,mixed,mixed,mixed) r9.xyzw, r5.w, l(48), t1.xyzw

// Untested:
mov r12.xyz, r6.yzwx
mov r12.w, l(1.0)
// ViewProjectionMatrix:
dp4 r13.w, r12.xyzw, cb0[19].xyzw
// Adjustment amount:
add r11.w, r13.w, -r11.y
mul r13.x, r11.w, r11.x
mov r13.yzw, l(0.0)
// InvProjectionMatrix:
dp4 r12.x, r13.xyzw, cb0[0].xyzw
dp4 r12.y, r13.xyzw, cb0[1].xyzw
dp4 r12.z, r13.xyzw, cb0[2].xyzw
dp4 r12.w, r13.xyzw, cb0[3].xyzw
// InvViewMatrix:
dp4 r13.x, r12.xyzw, cb0[4].xyzw
dp4 r13.y, r12.xyzw, cb0[5].xyzw
dp4 r13.z, r12.xyzw, cb0[6].xyzw
// Add adjustment:
add r6.yzw, r6.xyzw, r13.xxyz

and r5.w, r9.w, l(1)
ult r5.w, l(0), r5.w
add r6.yzw, -r1.yyzw, r6.yyzw
Expand Down
42 changes: 10 additions & 32 deletions Far Cry Primal/ShaderFixes/08e56ca875f16eb4-cs.txt
@@ -1,23 +1,4 @@
// Volumetric fog - combines all fog buffers together. Fix fog near cliffs & in sky.
// t7 - VFDensityVolumeTexture (general fog aruond landscape)
// t8 - VFShadowVolumeTexture (tree shadows / outdoor light shafts)
// Related shaders:
// CS 008f4b4539a0cab7 - VFLightVolumeTexture (point lights)
// CS ad7a6a5c9182e26e - VFLightVolumeTexture (point lights in cutscenes)
// CS 79d2dd1629dd2fd3 - VFLightVolumeTexture (point lights in enemy camp)
// CS 63156ad276e52990 - VFLightVolumeTexture (light shafts in cave)
// CS 8b431e0726c6115e - VFShadowVolumeTexture (light shafts outside)
// CS 6bdcbf1223c89177 - VFShadowVolumeTexture (as above, but for cutscenes)
// CS 5b5e5a3ac5bc8145 - VFDensityVolumeTexture (bad density near mountains)
// CS ac73802804100e3f - combines fog buffers together (Fix fog near cliffs & in sky)
// CS 08e56ca875f16eb4 - combines fog buffers together (No light volumes)
// CS 724b836f4ef69b66 - combines fog buffers together (No light or shadow volumes)
// CS b0dadd43e54744d2 - combines fog buffers together (No shadow volumes)
// CS ddc904400656fe8c - combines fog buffers together (No shadow volumes or sun shadows)
// CS ff698d5796811b2c - combines fog buffers together (No light or shadow volumes, or sun shadows)
// CS b353330000eff5ed - intermediate stage
// CS 30f0ac937c0b3451 - intermediate stage x 2
// PS 2b6cfbaa250d7a51 - output to screen
// asmtool.py -i --fix-fcprimal-volumetric-fog --only-autofixed -f 08e56ca875f16eb4-cs.txt
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
Expand Down Expand Up @@ -226,6 +207,7 @@ dcl_input vThreadIDInGroup.xy
dcl_temps 10
dcl_thread_group 16, 16, 1

// 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
Expand Down Expand Up @@ -263,24 +245,20 @@ if_nz r1.x
mul r2.yw, r3.xxxy, l(0.000000, 0.500000, 0.000000, 0.500000)
mad r3.xyz, r3.xyzx, l(0.500000, 0.500000, 0.500000, 0.000000), cb0[42].xyzx

mov r6.xyz, r3.xyz
mov r6.w, l(1.0)
// Volumetric Fog fix inserted with DarkStarSword's asmtool.py:
// asmtool.py -i --fix-fcprimal-volumetric-fog --only-autofixed -f 08e56ca875f16eb4-cs.txt

// ViewProjectionMatrix:
dp4 r9.w, r6.xyzw, cb0[19].xyzw
// Adjustment amount:
add r7.w, r9.w, -r7.y
mul r9.x, -r7.w, r7.x
mov r8.xyz, r3.xyzx
mov r8.w, l(1.0)
dp4 r9.w, r8.xyzw, cb0[19].xyzw
add r9.x, r9.w, -r7.y
mul r9.x, r9.x, -r7.x
mul r9.x, r9.x, cb0[0].x
mov r9.yzw, l(0.0)
// InvViewMatrix:
dp4 r8.x, r9.xyzw, cb0[4].xyzw
dp4 r8.y, r9.xyzw, cb0[5].xyzw
dp4 r8.z, r9.xyzw, cb0[6].xyzw
// Add adjustment:
add r6.xyz, r6.xyz, r8.xyz

mov r3.xyz, r6.xyz
add r3.xyz, r3.xyzw, r8.xyzx

iadd r4.xy, cb1[22].xyxx, l(-1, -1, 0, 0)
umin r4.xy, r0.xyxx, r4.xyxx
Expand Down
25 changes: 24 additions & 1 deletion Far Cry Primal/ShaderFixes/14bd4d43412bdc12-cs.txt
@@ -1,3 +1,4 @@
// asmtool.py -i --fix-fcprimal-volumetric-fog --only-autofixed -f 14bd4d43412bdc12-cs.txt
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
Expand Down Expand Up @@ -195,8 +196,14 @@ dcl_resource_structured t5, 4
dcl_uav_typed_texture3d (float,float,float,float) u0
dcl_input vThreadGroupID.xyz
dcl_input vThreadIDInGroup.xyz
dcl_temps 18
dcl_temps 21
dcl_thread_group 2, 2, 64

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

ld_indexable(texture2d)(float,float,float,float) r18.xyzw, l(0, 0, 0, 0), t125.xyzw

imad r0.xy, vThreadGroupID.xyxx, l(2, 2, 0, 0), vThreadIDInGroup.xyxx
ult r1.xy, r0.xyxx, cb1[22].xyxx
and r1.x, r1.y, r1.x
Expand Down Expand Up @@ -242,6 +249,22 @@ if_nz r1.x
add r1.x, r1.y, r1.x
mul r1.x, r1.x, l(0.500000)
mad r2.xyz, r2.xyzx, r1.xxxx, cb0[42].xyzx

// Volumetric Fog fix inserted with DarkStarSword's asmtool.py:
// asmtool.py -i --fix-fcprimal-volumetric-fog --only-autofixed -f 14bd4d43412bdc12-cs.txt

mov r19.xyz, r2.xyzx
mov r19.w, l(1.0)
dp4 r20.w, r19.xyzw, cb0[19].xyzw
add r20.x, r20.w, -r18.y
mul r20.x, r20.x, -r18.x
mul r20.x, r20.x, cb0[0].x
mov r20.yzw, l(0.0)
dp4 r19.x, r20.xyzw, cb0[4].xyzw
dp4 r19.y, r20.xyzw, cb0[5].xyzw
dp4 r19.z, r20.xyzw, cb0[6].xyzw
add r2.xyz, r2.xyzw, r19.xyzx

imad r4.xyzw, r0.xyxy, cb1[22].wwww, l(4, 4, 12, 4)
ushr r4.xyzw, r4.xyzw, l(3, 3, 3, 3)
imad r1.yz, r4.yywy, cb2[13].xxxx, r4.xxzx
Expand Down
25 changes: 24 additions & 1 deletion Far Cry Primal/ShaderFixes/441ebb36cc8f98fa-cs.txt
@@ -1,3 +1,4 @@
// asmtool.py -i --fix-fcprimal-volumetric-fog --only-autofixed -f 441ebb36cc8f98fa-cs.txt
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
Expand Down Expand Up @@ -235,8 +236,14 @@ dcl_resource_structured t5, 4
dcl_uav_typed_texture3d (float,float,float,float) u0
dcl_input vThreadGroupID.xyz
dcl_input vThreadIDInGroup.xyz
dcl_temps 17
dcl_temps 20
dcl_thread_group 2, 2, 64

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

ld_indexable(texture2d)(float,float,float,float) r17.xyzw, l(0, 0, 0, 0), t125.xyzw

imad r0.xy, vThreadGroupID.xyxx, l(2, 2, 0, 0), vThreadIDInGroup.xyxx
ult r1.xy, r0.xyxx, cb2[22].xyxx
and r1.x, r1.y, r1.x
Expand Down Expand Up @@ -282,6 +289,22 @@ if_nz r1.x
add r1.x, r1.y, r1.x
mul r1.x, r1.x, l(0.500000)
mad r1.yzw, r2.xxyz, r1.xxxx, cb0[42].xxyz

// Volumetric Fog fix inserted with DarkStarSword's asmtool.py:
// asmtool.py -i --fix-fcprimal-volumetric-fog --only-autofixed -f 441ebb36cc8f98fa-cs.txt

mov r18.xyz, r1.yzwx
mov r18.w, l(1.0)
dp4 r19.w, r18.xyzw, cb0[19].xyzw
add r19.x, r19.w, -r17.y
mul r19.x, r19.x, -r17.x
mul r19.x, r19.x, cb0[0].x
mov r19.yzw, l(0.0)
dp4 r18.x, r19.xyzw, cb0[4].xyzw
dp4 r18.y, r19.xyzw, cb0[5].xyzw
dp4 r18.z, r19.xyzw, cb0[6].xyzw
add r1.yzw, r1.xyzw, r18.xxyz

imad r2.xyzw, r0.xyxy, cb2[22].wwww, l(4, 4, 12, 4)
ushr r2.xyzw, r2.xyzw, l(3, 3, 3, 3)
imad r2.xy, r2.ywyy, cb3[13].xxxx, r2.xzxx
Expand Down
25 changes: 24 additions & 1 deletion Far Cry Primal/ShaderFixes/51cb4c1f75e34427-cs.txt
@@ -1,3 +1,4 @@
// asmtool.py -i --fix-fcprimal-volumetric-fog --only-autofixed -f 51cb4c1f75e34427-cs.txt
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
Expand Down Expand Up @@ -235,8 +236,14 @@ dcl_resource_structured t5, 4
dcl_uav_typed_texture3d (float,float,float,float) u0
dcl_input vThreadGroupID.xyz
dcl_input vThreadIDInGroup.xyz
dcl_temps 18
dcl_temps 21
dcl_thread_group 2, 2, 64

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

ld_indexable(texture2d)(float,float,float,float) r18.xyzw, l(0, 0, 0, 0), t125.xyzw

imad r0.xy, vThreadGroupID.xyxx, l(2, 2, 0, 0), vThreadIDInGroup.xyxx
ult r1.xy, r0.xyxx, cb2[22].xyxx
and r1.x, r1.y, r1.x
Expand Down Expand Up @@ -282,6 +289,22 @@ if_nz r1.x
add r1.x, r1.y, r1.x
mul r1.x, r1.x, l(0.500000)
mad r1.yzw, r2.xxyz, r1.xxxx, cb0[42].xxyz

// Volumetric Fog fix inserted with DarkStarSword's asmtool.py:
// asmtool.py -i --fix-fcprimal-volumetric-fog --only-autofixed -f 51cb4c1f75e34427-cs.txt

mov r19.xyz, r1.yzwx
mov r19.w, l(1.0)
dp4 r20.w, r19.xyzw, cb0[19].xyzw
add r20.x, r20.w, -r18.y
mul r20.x, r20.x, -r18.x
mul r20.x, r20.x, cb0[0].x
mov r20.yzw, l(0.0)
dp4 r19.x, r20.xyzw, cb0[4].xyzw
dp4 r19.y, r20.xyzw, cb0[5].xyzw
dp4 r19.z, r20.xyzw, cb0[6].xyzw
add r1.yzw, r1.xyzw, r19.xxyz

imad r2.xyzw, r0.xyxy, cb2[22].wwww, l(4, 4, 12, 4)
ushr r2.xyzw, r2.xyzw, l(3, 3, 3, 3)
imad r2.xy, r2.ywyy, cb3[13].xxxx, r2.xzxx
Expand Down
51 changes: 15 additions & 36 deletions Far Cry Primal/ShaderFixes/63156ad276e52990-cs.txt
@@ -1,17 +1,4 @@
// Volumetric fog - populates VFLightVolumeTexture (light shafts in cave)
// Related shaders:
// CS 008f4b4539a0cab7 - VFLightVolumeTexture (point lights)
// CS ad7a6a5c9182e26e - VFLightVolumeTexture (point lights in cutscenes)
// CS 79d2dd1629dd2fd3 - VFLightVolumeTexture (point lights in enemy camp)
// CS 63156ad276e52990 - VFLightVolumeTexture (light shafts in cave)
// CS 8b431e0726c6115e - VFShadowVolumeTexture (light shafts outside)
// CS 6bdcbf1223c89177 - VFShadowVolumeTexture (as above, but for cutscenes)
// CS 5b5e5a3ac5bc8145 - VFDensityVolumeTexture (bad density near mountains)
// CS ac73802804100e3f - combines this & other fog buffers together
// CS b353330000eff5ed - intermediate stage
// CS 30f0ac937c0b3451 - intermediate stage x 2
// PS 2b6cfbaa250d7a51 - output to screen

// asmtool.py -i --fix-fcprimal-volumetric-fog --only-autofixed -f 63156ad276e52990-cs.txt
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
Expand Down Expand Up @@ -209,9 +196,10 @@ dcl_resource_structured t5, 4
dcl_uav_typed_texture3d (float,float,float,float) u0
dcl_input vThreadGroupID.xyz
dcl_input vThreadIDInGroup.xyz
dcl_temps 22
dcl_temps 21
dcl_thread_group 2, 2, 64

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

ld_indexable(texture2d)(float,float,float,float) r18.xyzw, l(0, 0, 0, 0), t125.xyzw
Expand Down Expand Up @@ -260,31 +248,22 @@ if_nz r1.x
mad r1.y, r1.y, cb1[12].z, cb1[12].w
add r1.x, r1.y, r1.x
mul r1.x, r1.x, l(0.500000)

mad r2.xyz, r2.xyzx, r1.xxxx, cb0[42].xyzx

mov r21.xyz, r2.xyz
mov r21.w, l(1.0)
// Volumetric Fog fix inserted with DarkStarSword's asmtool.py:
// asmtool.py -i --fix-fcprimal-volumetric-fog --only-autofixed -f 63156ad276e52990-cs.txt

// ViewProjectionMatrix:
dp4 r20.w, r21.xyzw, cb0[19].xyzw
// Adjustment amount:
add r18.w, r20.w, -r18.y
mul r20.x, -r18.w, r18.x
mov r19.xyz, r2.xyzx
mov r19.w, l(1.0)
dp4 r20.w, r19.xyzw, cb0[19].xyzw
add r20.x, r20.w, -r18.y
mul r20.x, r20.x, -r18.x
mul r20.x, r20.x, cb0[0].x
mov r20.yzw, l(0.0)
// InvProjectionMatrix:
dp4 r19.x, r20.xyzw, cb0[0].xyzw
dp4 r19.y, r20.xyzw, cb0[1].xyzw
dp4 r19.z, r20.xyzw, cb0[2].xyzw
dp4 r19.w, r20.xyzw, cb0[3].xyzw
// InvViewMatrix:
dp4 r20.x, r19.xyzw, cb0[4].xyzw
dp4 r20.y, r19.xyzw, cb0[5].xyzw
dp4 r20.z, r19.xyzw, cb0[6].xyzw
// Add adjustment:
add r21.xyz, r21.xyz, r20.xyz

mov r2.xyz, r21.xyz
dp4 r19.x, r20.xyzw, cb0[4].xyzw
dp4 r19.y, r20.xyzw, cb0[5].xyzw
dp4 r19.z, r20.xyzw, cb0[6].xyzw
add r2.xyz, r2.xyzw, r19.xyzx

imad r4.xyzw, r0.xyxy, cb1[22].wwww, l(4, 4, 12, 4)
ushr r4.xyzw, r4.xyzw, l(3, 3, 3, 3)
Expand Down

0 comments on commit 53458ac

Please sign in to comment.