From a6fcd3f4c75651e08c4392dea8a77b7fed1c2fe5 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Mon, 16 Mar 2026 16:03:52 -0400 Subject: Outline of new features Signed-off-by: Andrew Opalach --- .gitignore | 2 + Config.cs | 10 + Plugin.cs | 174 +++ Scripts/generate_diffs.sh | 5 + Scripts/get_dxbc_hash.py | 17 + Shaders/Original/body_skin.dxbc.xz | Bin 0 -> 2916 bytes Shaders/Original/cube_only.dxbc.xz | Bin 0 -> 2072 bytes Shaders/Original/face.dxbc.xz | Bin 0 -> 5740 bytes Shaders/Original/fxaa_out.dxbc.xz | Bin 0 -> 1732 bytes Shaders/Original/sslr.dxbc.xz | Bin 0 -> 3704 bytes Shaders/Original/volume_upsample.dxbc.xz | Bin 0 -> 1700 bytes Shaders/Original/volume_upsample2.dxbc.xz | Bin 0 -> 2160 bytes Shaders/body_skin.diff | 11 + Shaders/cube_only.diff | 15 + Shaders/face.diff | 11 + Shaders/fxaa_max_quality.hlsl | 2116 +++++++++++++++++++++++++++++ Shaders/notes.txt | 11 + Shaders/sslr.diff | 15 + Shaders/volume_upsample.diff | 22 + Shaders/volume_upsample2.diff | 191 +++ WorldTuningTool.csproj | 26 + WorldTuningTool.sln | 22 + 22 files changed, 2648 insertions(+) create mode 100644 .gitignore create mode 100755 Config.cs create mode 100755 Plugin.cs create mode 100755 Scripts/generate_diffs.sh create mode 100755 Scripts/get_dxbc_hash.py create mode 100755 Shaders/Original/body_skin.dxbc.xz create mode 100755 Shaders/Original/cube_only.dxbc.xz create mode 100755 Shaders/Original/face.dxbc.xz create mode 100755 Shaders/Original/fxaa_out.dxbc.xz create mode 100755 Shaders/Original/sslr.dxbc.xz create mode 100755 Shaders/Original/volume_upsample.dxbc.xz create mode 100755 Shaders/Original/volume_upsample2.dxbc.xz create mode 100644 Shaders/body_skin.diff create mode 100644 Shaders/cube_only.diff create mode 100644 Shaders/face.diff create mode 100644 Shaders/fxaa_max_quality.hlsl create mode 100644 Shaders/notes.txt create mode 100644 Shaders/sslr.diff create mode 100644 Shaders/volume_upsample.diff create mode 100644 Shaders/volume_upsample2.diff create mode 100755 WorldTuningTool.csproj create mode 100755 WorldTuningTool.sln diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..da66154 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +Scripts/cmd_Decompiler.exe +Scripts/d3dcompiler_47.dll diff --git a/Config.cs b/Config.cs new file mode 100755 index 0000000..bbb785b --- /dev/null +++ b/Config.cs @@ -0,0 +1,10 @@ +using SharpPluginLoader.Core.Configuration; + +namespace WorldTuningTool +{ + internal class Config : IConfig + { + public String Name => "WorldTuningTool"; + public String Version => "1.0"; + } +} diff --git a/Plugin.cs b/Plugin.cs new file mode 100755 index 0000000..b382df7 --- /dev/null +++ b/Plugin.cs @@ -0,0 +1,174 @@ +using System.Reflection; +using System.Runtime.Loader; +using System.Runtime.InteropServices; + +using ImGuiNET; +using SharpPluginLoader.Core; +using SharpPluginLoader.Core.Memory; + +namespace WorldTuningTool +{ + public unsafe class Plugin : IPlugin + { + public string Name => "World Tuning Tool"; + public string Author => "Akon City Software"; + + // @TODO: + // - Port FXAA object. + // - Port some stuff as is. + // - OnAreaChange. + // - Shadow distance retuning. + // - Work out obvious simplifications. + // - sMhRenderer vs common parameter address. + // - Overrides system. + // - Pass on LODs. + // - Verbose descriptions. + // - Re-implement shadow res override for hoarfrost. + // - Exact float flag for hex input? + + private bool dofDisabled = false; + private Patch jmpOverDof; + + public void SetDofForceOff(bool off) + { + if (off && !dofDisabled) + { + jmpOverDof.Enable(); + } + else if (!off && dofDisabled) + { + jmpOverDof.Disable(); + } + dofDisabled = off; + } + + public bool GetDofDisabled() + { + return dofDisabled; + } + + public PluginData Initialize() + { + PluginData data = new PluginData(); + data.ExportedFunctions.Add(("SetDofForceOff", SetDofForceOff)); + data.ExportedFunctions.Add(("GetDofDisabled", GetDofDisabled)); + return data; + } + + public void OnPreMain() + { + unchecked + { + jmpOverDof = new Patch((nint)0x1424233C6, [0xEB]); // je -> jmp. + } + } + + private static bool replaceShaderFromFile(ShaderInfo *info, string path) + { + if (!System.IO.File.Exists(path)) + { + Log.Warn($"File not found: {path}."); + return false; + } + byte[] shaderData; + try + { + shaderData = System.IO.File.ReadAllBytes(path); + } + catch (Exception) + { + Log.Error($"Failed to read: {path}."); + return false; + } + info->NewSourceLength = shaderData.Length; + info->NewSource = (byte *)Marshal.UnsafeAddrOfPinnedArrayElement(shaderData, 0); + return true; + } + + private string shaderPath = "nativePC/plugins/CSharp/Shaders"; + private bool shadersLoadedOnce = false; + public unsafe void OnCreateShader(ShaderInfo *info) + { + string hash = new string(info->DxbcHash); + if (!shadersLoadedOnce && hash == "2e4e18fd-6ea5eeae-2de3d65c-26ab36dd") + { + if (replaceShaderFromFile(info, $"{shaderPath}/volume_upsample.shdr")) { + info->NewSourceType = ShaderSourceType.BINARY; + Log.Info("Volume upsample shader 1 replaced."); + } + } + else if (!shadersLoadedOnce && hash == "e2c8c13e-45bc99b2-4c3d7699-3d66188e") + { + if (replaceShaderFromFile(info, $"{shaderPath}/volume_upsample2.shdr")) { + info->NewSourceType = ShaderSourceType.BINARY; + Log.Info("Volume upsample shader 2 replaced."); + } + // This allows us to A/B using the volume rendering value 2 switch. + shadersLoadedOnce = true; + } + else if (hash == "8cf2a107-ecde214b-9939b350-7b2af1a7") + { + if (replaceShaderFromFile(info, $"{shaderPath}/cube_only.shdr")) { + info->NewSourceType = ShaderSourceType.BINARY; + Log.Info("Cube Only shader replaced."); + } + } + else if (hash == "b21dd223-98ab56ae-918264e6-eb6e8ee4") + { + info->NewSourceType = ShaderSourceType.BINARY; + if (replaceShaderFromFile(info, $"{shaderPath}/sslr.shdr")) { + Log.Info("SSLR shader replaced."); + } + } + else if (hash == "9ff245fb-4fd555e0-04d0ef15-84609fe1") + { + if (replaceShaderFromFile(info, $"{shaderPath}/fxaa_max_quality.hlsl")) { + info->NewSourceType = ShaderSourceType.HLSL; + Log.Info("FXAA shader replaced."); + } + } + else if (hash == "2eed1f00-e24d1b19-9d521064-17b9a586") + { + if (replaceShaderFromFile(info, $"{shaderPath}/body_skin.shdr")) { + info->NewSourceType = ShaderSourceType.BINARY; + Log.Info("Body skin shader replaced."); + } + } + else if (hash == "8e5e3c09-ebe77ee4-ba1cb659-d25bc7bf") + { + if (replaceShaderFromFile(info, $"{shaderPath}/face.shdr")) { + info->NewSourceType = ShaderSourceType.BINARY; + Log.Info("Face shader replaced."); + } + } + /* + else if (hash == "d7e47ffe-82572c64-795c4698-341e5b91") + { + if (replaceShaderFromFile(info, $"{shaderPath}/sslr_mips.shdr")) { + info->NewSourceType = ShaderSourceType.BINARY; + Log.Info("SSLR mips shader replaced."); + } + } + */ + } + + public void OnLoad() + { + } + + public void OnImGuiRender() + { + if (ImGui.Checkbox("Disable Depth of Field", ref dofDisabled)) + { + if (dofDisabled) + { + jmpOverDof.Enable(); + } + else + { + jmpOverDof.Disable(); + } + } + } + } +} diff --git a/Scripts/generate_diffs.sh b/Scripts/generate_diffs.sh new file mode 100755 index 0000000..b0c5687 --- /dev/null +++ b/Scripts/generate_diffs.sh @@ -0,0 +1,5 @@ +#! /usr/bin/env sh + +#wine cmd_Decompiler.exe -d ../Shaders/Original/*.dxbc +#wine cmd_Decompiler.exe -d ../Shaders/*.shdr +#diff -u orig.asm edit.asm diff --git a/Scripts/get_dxbc_hash.py b/Scripts/get_dxbc_hash.py new file mode 100755 index 0000000..0c53107 --- /dev/null +++ b/Scripts/get_dxbc_hash.py @@ -0,0 +1,17 @@ +#! /usr/bin/env python3 + +import sys +import os.path +import struct + +if not os.path.isfile(sys.argv[1]): + print(f'File not found: {sys.argv[1]}') + sys.exit(1) + +for path in sys.argv[1:]: + print(path + ':') + with open(path, 'rb') as f: + if f.read(4).decode('ASCII') == 'DXBC': + print(' %08x-%08x-%08x-%08x' % (struct.unpack('= edgeVert; + FxaaFloat subpixA = subpixNSWE * 2.0 + subpixNWSWNESE; +/*--------------------------------------------------------------------------*/ + if(!horzSpan) lumaN = lumaW; + if(!horzSpan) lumaS = lumaE; + if(horzSpan) lengthSign = fxaaQualityRcpFrame.y; + FxaaFloat subpixB = (subpixA * (1.0/12.0)) - lumaM; +/*--------------------------------------------------------------------------*/ + FxaaFloat gradientN = lumaN - lumaM; + FxaaFloat gradientS = lumaS - lumaM; + FxaaFloat lumaNN = lumaN + lumaM; + FxaaFloat lumaSS = lumaS + lumaM; + FxaaBool pairN = abs(gradientN) >= abs(gradientS); + FxaaFloat gradient = max(abs(gradientN), abs(gradientS)); + if(pairN) lengthSign = -lengthSign; + FxaaFloat subpixC = FxaaSat(abs(subpixB) * subpixRcpRange); +/*--------------------------------------------------------------------------*/ + FxaaFloat2 posB; + posB.x = posM.x; + posB.y = posM.y; + FxaaFloat2 offNP; + offNP.x = (!horzSpan) ? 0.0 : fxaaQualityRcpFrame.x; + offNP.y = ( horzSpan) ? 0.0 : fxaaQualityRcpFrame.y; + if(!horzSpan) posB.x += lengthSign * 0.5; + if( horzSpan) posB.y += lengthSign * 0.5; +/*--------------------------------------------------------------------------*/ + FxaaFloat2 posN; + posN.x = posB.x - offNP.x * FXAA_QUALITY__P0; + posN.y = posB.y - offNP.y * FXAA_QUALITY__P0; + FxaaFloat2 posP; + posP.x = posB.x + offNP.x * FXAA_QUALITY__P0; + posP.y = posB.y + offNP.y * FXAA_QUALITY__P0; + FxaaFloat subpixD = ((-2.0)*subpixC) + 3.0; + FxaaFloat lumaEndN = FxaaLuma(FxaaTexTop(tex, posN)); + FxaaFloat subpixE = subpixC * subpixC; + FxaaFloat lumaEndP = FxaaLuma(FxaaTexTop(tex, posP)); +/*--------------------------------------------------------------------------*/ + if(!pairN) lumaNN = lumaSS; + FxaaFloat gradientScaled = gradient * 1.0/4.0; + FxaaFloat lumaMM = lumaM - lumaNN * 0.5; + FxaaFloat subpixF = subpixD * subpixE; + FxaaBool lumaMLTZero = lumaMM < 0.0; +/*--------------------------------------------------------------------------*/ + lumaEndN -= lumaNN * 0.5; + lumaEndP -= lumaNN * 0.5; + FxaaBool doneN = abs(lumaEndN) >= gradientScaled; + FxaaBool doneP = abs(lumaEndP) >= gradientScaled; + if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P1; + if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P1; + FxaaBool doneNP = (!doneN) || (!doneP); + if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P1; + if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P1; +/*--------------------------------------------------------------------------*/ + if(doneNP) { + if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); + if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); + if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; + if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; + doneN = abs(lumaEndN) >= gradientScaled; + doneP = abs(lumaEndP) >= gradientScaled; + if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P2; + if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P2; + doneNP = (!doneN) || (!doneP); + if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P2; + if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P2; +/*--------------------------------------------------------------------------*/ + #if (FXAA_QUALITY__PS > 3) + if(doneNP) { + if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); + if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); + if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; + if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; + doneN = abs(lumaEndN) >= gradientScaled; + doneP = abs(lumaEndP) >= gradientScaled; + if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P3; + if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P3; + doneNP = (!doneN) || (!doneP); + if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P3; + if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P3; +/*--------------------------------------------------------------------------*/ + #if (FXAA_QUALITY__PS > 4) + if(doneNP) { + if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); + if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); + if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; + if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; + doneN = abs(lumaEndN) >= gradientScaled; + doneP = abs(lumaEndP) >= gradientScaled; + if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P4; + if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P4; + doneNP = (!doneN) || (!doneP); + if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P4; + if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P4; +/*--------------------------------------------------------------------------*/ + #if (FXAA_QUALITY__PS > 5) + if(doneNP) { + if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); + if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); + if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; + if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; + doneN = abs(lumaEndN) >= gradientScaled; + doneP = abs(lumaEndP) >= gradientScaled; + if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P5; + if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P5; + doneNP = (!doneN) || (!doneP); + if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P5; + if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P5; +/*--------------------------------------------------------------------------*/ + #if (FXAA_QUALITY__PS > 6) + if(doneNP) { + if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); + if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); + if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; + if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; + doneN = abs(lumaEndN) >= gradientScaled; + doneP = abs(lumaEndP) >= gradientScaled; + if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P6; + if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P6; + doneNP = (!doneN) || (!doneP); + if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P6; + if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P6; +/*--------------------------------------------------------------------------*/ + #if (FXAA_QUALITY__PS > 7) + if(doneNP) { + if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); + if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); + if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; + if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; + doneN = abs(lumaEndN) >= gradientScaled; + doneP = abs(lumaEndP) >= gradientScaled; + if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P7; + if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P7; + doneNP = (!doneN) || (!doneP); + if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P7; + if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P7; +/*--------------------------------------------------------------------------*/ + #if (FXAA_QUALITY__PS > 8) + if(doneNP) { + if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); + if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); + if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; + if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; + doneN = abs(lumaEndN) >= gradientScaled; + doneP = abs(lumaEndP) >= gradientScaled; + if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P8; + if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P8; + doneNP = (!doneN) || (!doneP); + if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P8; + if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P8; +/*--------------------------------------------------------------------------*/ + #if (FXAA_QUALITY__PS > 9) + if(doneNP) { + if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); + if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); + if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; + if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; + doneN = abs(lumaEndN) >= gradientScaled; + doneP = abs(lumaEndP) >= gradientScaled; + if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P9; + if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P9; + doneNP = (!doneN) || (!doneP); + if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P9; + if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P9; +/*--------------------------------------------------------------------------*/ + #if (FXAA_QUALITY__PS > 10) + if(doneNP) { + if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); + if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); + if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; + if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; + doneN = abs(lumaEndN) >= gradientScaled; + doneP = abs(lumaEndP) >= gradientScaled; + if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P10; + if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P10; + doneNP = (!doneN) || (!doneP); + if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P10; + if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P10; +/*--------------------------------------------------------------------------*/ + #if (FXAA_QUALITY__PS > 11) + if(doneNP) { + if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); + if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); + if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; + if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; + doneN = abs(lumaEndN) >= gradientScaled; + doneP = abs(lumaEndP) >= gradientScaled; + if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P11; + if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P11; + doneNP = (!doneN) || (!doneP); + if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P11; + if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P11; +/*--------------------------------------------------------------------------*/ + #if (FXAA_QUALITY__PS > 12) + if(doneNP) { + if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy)); + if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy)); + if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5; + if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5; + doneN = abs(lumaEndN) >= gradientScaled; + doneP = abs(lumaEndP) >= gradientScaled; + if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P12; + if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P12; + doneNP = (!doneN) || (!doneP); + if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P12; + if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P12; +/*--------------------------------------------------------------------------*/ + } + #endif +/*--------------------------------------------------------------------------*/ + } + #endif +/*--------------------------------------------------------------------------*/ + } + #endif +/*--------------------------------------------------------------------------*/ + } + #endif +/*--------------------------------------------------------------------------*/ + } + #endif +/*--------------------------------------------------------------------------*/ + } + #endif +/*--------------------------------------------------------------------------*/ + } + #endif +/*--------------------------------------------------------------------------*/ + } + #endif +/*--------------------------------------------------------------------------*/ + } + #endif +/*--------------------------------------------------------------------------*/ + } + #endif +/*--------------------------------------------------------------------------*/ + } +/*--------------------------------------------------------------------------*/ + FxaaFloat dstN = posM.x - posN.x; + FxaaFloat dstP = posP.x - posM.x; + if(!horzSpan) dstN = posM.y - posN.y; + if(!horzSpan) dstP = posP.y - posM.y; +/*--------------------------------------------------------------------------*/ + FxaaBool goodSpanN = (lumaEndN < 0.0) != lumaMLTZero; + FxaaFloat spanLength = (dstP + dstN); + FxaaBool goodSpanP = (lumaEndP < 0.0) != lumaMLTZero; + FxaaFloat spanLengthRcp = 1.0/spanLength; +/*--------------------------------------------------------------------------*/ + FxaaBool directionN = dstN < dstP; + FxaaFloat dst = min(dstN, dstP); + FxaaBool goodSpan = directionN ? goodSpanN : goodSpanP; + FxaaFloat subpixG = subpixF * subpixF; + FxaaFloat pixelOffset = (dst * (-spanLengthRcp)) + 0.5; + FxaaFloat subpixH = subpixG * fxaaQualitySubpix; +/*--------------------------------------------------------------------------*/ + FxaaFloat pixelOffsetGood = goodSpan ? pixelOffset : 0.0; + FxaaFloat pixelOffsetSubpix = max(pixelOffsetGood, subpixH); + if(!horzSpan) posM.x += pixelOffsetSubpix * lengthSign; + if( horzSpan) posM.y += pixelOffsetSubpix * lengthSign; + #if (FXAA_DISCARD == 1) + return FxaaTexTop(tex, posM); + #else + return FxaaFloat4(FxaaTexTop(tex, posM).xyz, lumaM); + #endif +} +/*==========================================================================*/ +#endif + + + + +/*============================================================================ + + FXAA3 CONSOLE - PC VERSION + +------------------------------------------------------------------------------ +Instead of using this on PC, I'd suggest just using FXAA Quality with + #define FXAA_QUALITY__PRESET 10 +Or + #define FXAA_QUALITY__PRESET 20 +Either are higher qualilty and almost as fast as this on modern PC GPUs. +============================================================================*/ +#if (FXAA_PC_CONSOLE == 1) +/*--------------------------------------------------------------------------*/ +FxaaFloat4 FxaaPixelShader( + // See FXAA Quality FxaaPixelShader() source for docs on Inputs! + FxaaFloat2 pos, + FxaaFloat4 fxaaConsolePosPos, + FxaaTex tex, + FxaaTex fxaaConsole360TexExpBiasNegOne, + FxaaTex fxaaConsole360TexExpBiasNegTwo, + FxaaFloat2 fxaaQualityRcpFrame, + FxaaFloat4 fxaaConsoleRcpFrameOpt, + FxaaFloat4 fxaaConsoleRcpFrameOpt2, + FxaaFloat4 fxaaConsole360RcpFrameOpt2, + FxaaFloat fxaaQualitySubpix, + FxaaFloat fxaaQualityEdgeThreshold, + FxaaFloat fxaaQualityEdgeThresholdMin, + FxaaFloat fxaaConsoleEdgeSharpness, + FxaaFloat fxaaConsoleEdgeThreshold, + FxaaFloat fxaaConsoleEdgeThresholdMin, + FxaaFloat4 fxaaConsole360ConstDir +) { +/*--------------------------------------------------------------------------*/ + FxaaFloat lumaNw = FxaaLuma(FxaaTexTop(tex, fxaaConsolePosPos.xy)); + FxaaFloat lumaSw = FxaaLuma(FxaaTexTop(tex, fxaaConsolePosPos.xw)); + FxaaFloat lumaNe = FxaaLuma(FxaaTexTop(tex, fxaaConsolePosPos.zy)); + FxaaFloat lumaSe = FxaaLuma(FxaaTexTop(tex, fxaaConsolePosPos.zw)); +/*--------------------------------------------------------------------------*/ + FxaaFloat4 rgbyM = FxaaTexTop(tex, pos.xy); + #if (FXAA_GREEN_AS_LUMA == 0) + FxaaFloat lumaM = rgbyM.w; + #else + FxaaFloat lumaM = rgbyM.y; + #endif +/*--------------------------------------------------------------------------*/ + FxaaFloat lumaMaxNwSw = max(lumaNw, lumaSw); + lumaNe += 1.0/384.0; + FxaaFloat lumaMinNwSw = min(lumaNw, lumaSw); +/*--------------------------------------------------------------------------*/ + FxaaFloat lumaMaxNeSe = max(lumaNe, lumaSe); + FxaaFloat lumaMinNeSe = min(lumaNe, lumaSe); +/*--------------------------------------------------------------------------*/ + FxaaFloat lumaMax = max(lumaMaxNeSe, lumaMaxNwSw); + FxaaFloat lumaMin = min(lumaMinNeSe, lumaMinNwSw); +/*--------------------------------------------------------------------------*/ + FxaaFloat lumaMaxScaled = lumaMax * fxaaConsoleEdgeThreshold; +/*--------------------------------------------------------------------------*/ + FxaaFloat lumaMinM = min(lumaMin, lumaM); + FxaaFloat lumaMaxScaledClamped = max(fxaaConsoleEdgeThresholdMin, lumaMaxScaled); + FxaaFloat lumaMaxM = max(lumaMax, lumaM); + FxaaFloat dirSwMinusNe = lumaSw - lumaNe; + FxaaFloat lumaMaxSubMinM = lumaMaxM - lumaMinM; + FxaaFloat dirSeMinusNw = lumaSe - lumaNw; + if(lumaMaxSubMinM < lumaMaxScaledClamped) return rgbyM; +/*--------------------------------------------------------------------------*/ + FxaaFloat2 dir; + dir.x = dirSwMinusNe + dirSeMinusNw; + dir.y = dirSwMinusNe - dirSeMinusNw; +/*--------------------------------------------------------------------------*/ + FxaaFloat2 dir1 = normalize(dir.xy); + FxaaFloat4 rgbyN1 = FxaaTexTop(tex, pos.xy - dir1 * fxaaConsoleRcpFrameOpt.zw); + FxaaFloat4 rgbyP1 = FxaaTexTop(tex, pos.xy + dir1 * fxaaConsoleRcpFrameOpt.zw); +/*--------------------------------------------------------------------------*/ + FxaaFloat dirAbsMinTimesC = min(abs(dir1.x), abs(dir1.y)) * fxaaConsoleEdgeSharpness; + FxaaFloat2 dir2 = clamp(dir1.xy / dirAbsMinTimesC, -2.0, 2.0); +/*--------------------------------------------------------------------------*/ + FxaaFloat4 rgbyN2 = FxaaTexTop(tex, pos.xy - dir2 * fxaaConsoleRcpFrameOpt2.zw); + FxaaFloat4 rgbyP2 = FxaaTexTop(tex, pos.xy + dir2 * fxaaConsoleRcpFrameOpt2.zw); +/*--------------------------------------------------------------------------*/ + FxaaFloat4 rgbyA = rgbyN1 + rgbyP1; + FxaaFloat4 rgbyB = ((rgbyN2 + rgbyP2) * 0.25) + (rgbyA * 0.25); +/*--------------------------------------------------------------------------*/ + #if (FXAA_GREEN_AS_LUMA == 0) + FxaaBool twoTap = (rgbyB.w < lumaMin) || (rgbyB.w > lumaMax); + #else + FxaaBool twoTap = (rgbyB.y < lumaMin) || (rgbyB.y > lumaMax); + #endif + if(twoTap) rgbyB.xyz = rgbyA.xyz * 0.5; + return rgbyB; } +/*==========================================================================*/ +#endif + + + +/*============================================================================ + + FXAA3 CONSOLE - 360 PIXEL SHADER + +------------------------------------------------------------------------------ +This optimized version thanks to suggestions from Andy Luedke. +Should be fully tex bound in all cases. +As of the FXAA 3.11 release, I have still not tested this code, +however I fixed a bug which was in both FXAA 3.9 and FXAA 3.10. +And note this is replacing the old unoptimized version. +If it does not work, please let me know so I can fix it. +============================================================================*/ +#if (FXAA_360 == 1) +/*--------------------------------------------------------------------------*/ +[reduceTempRegUsage(4)] +float4 FxaaPixelShader( + // See FXAA Quality FxaaPixelShader() source for docs on Inputs! + FxaaFloat2 pos, + FxaaFloat4 fxaaConsolePosPos, + FxaaTex tex, + FxaaTex fxaaConsole360TexExpBiasNegOne, + FxaaTex fxaaConsole360TexExpBiasNegTwo, + FxaaFloat2 fxaaQualityRcpFrame, + FxaaFloat4 fxaaConsoleRcpFrameOpt, + FxaaFloat4 fxaaConsoleRcpFrameOpt2, + FxaaFloat4 fxaaConsole360RcpFrameOpt2, + FxaaFloat fxaaQualitySubpix, + FxaaFloat fxaaQualityEdgeThreshold, + FxaaFloat fxaaQualityEdgeThresholdMin, + FxaaFloat fxaaConsoleEdgeSharpness, + FxaaFloat fxaaConsoleEdgeThreshold, + FxaaFloat fxaaConsoleEdgeThresholdMin, + FxaaFloat4 fxaaConsole360ConstDir +) { +/*--------------------------------------------------------------------------*/ + float4 lumaNwNeSwSe; + #if (FXAA_GREEN_AS_LUMA == 0) + asm { + tfetch2D lumaNwNeSwSe.w___, tex, pos.xy, OffsetX = -0.5, OffsetY = -0.5, UseComputedLOD=false + tfetch2D lumaNwNeSwSe._w__, tex, pos.xy, OffsetX = 0.5, OffsetY = -0.5, UseComputedLOD=false + tfetch2D lumaNwNeSwSe.__w_, tex, pos.xy, OffsetX = -0.5, OffsetY = 0.5, UseComputedLOD=false + tfetch2D lumaNwNeSwSe.___w, tex, pos.xy, OffsetX = 0.5, OffsetY = 0.5, UseComputedLOD=false + }; + #else + asm { + tfetch2D lumaNwNeSwSe.y___, tex, pos.xy, OffsetX = -0.5, OffsetY = -0.5, UseComputedLOD=false + tfetch2D lumaNwNeSwSe._y__, tex, pos.xy, OffsetX = 0.5, OffsetY = -0.5, UseComputedLOD=false + tfetch2D lumaNwNeSwSe.__y_, tex, pos.xy, OffsetX = -0.5, OffsetY = 0.5, UseComputedLOD=false + tfetch2D lumaNwNeSwSe.___y, tex, pos.xy, OffsetX = 0.5, OffsetY = 0.5, UseComputedLOD=false + }; + #endif +/*--------------------------------------------------------------------------*/ + lumaNwNeSwSe.y += 1.0/384.0; + float2 lumaMinTemp = min(lumaNwNeSwSe.xy, lumaNwNeSwSe.zw); + float2 lumaMaxTemp = max(lumaNwNeSwSe.xy, lumaNwNeSwSe.zw); + float lumaMin = min(lumaMinTemp.x, lumaMinTemp.y); + float lumaMax = max(lumaMaxTemp.x, lumaMaxTemp.y); +/*--------------------------------------------------------------------------*/ + float4 rgbyM = tex2Dlod(tex, float4(pos.xy, 0.0, 0.0)); + #if (FXAA_GREEN_AS_LUMA == 0) + float lumaMinM = min(lumaMin, rgbyM.w); + float lumaMaxM = max(lumaMax, rgbyM.w); + #else + float lumaMinM = min(lumaMin, rgbyM.y); + float lumaMaxM = max(lumaMax, rgbyM.y); + #endif + if((lumaMaxM - lumaMinM) < max(fxaaConsoleEdgeThresholdMin, lumaMax * fxaaConsoleEdgeThreshold)) return rgbyM; +/*--------------------------------------------------------------------------*/ + float2 dir; + dir.x = dot(lumaNwNeSwSe, fxaaConsole360ConstDir.yyxx); + dir.y = dot(lumaNwNeSwSe, fxaaConsole360ConstDir.xyxy); + dir = normalize(dir); +/*--------------------------------------------------------------------------*/ + float4 dir1 = dir.xyxy * fxaaConsoleRcpFrameOpt.xyzw; +/*--------------------------------------------------------------------------*/ + float4 dir2; + float dirAbsMinTimesC = min(abs(dir.x), abs(dir.y)) * fxaaConsoleEdgeSharpness; + dir2 = saturate(fxaaConsole360ConstDir.zzww * dir.xyxy / dirAbsMinTimesC + 0.5); + dir2 = dir2 * fxaaConsole360RcpFrameOpt2.xyxy + fxaaConsole360RcpFrameOpt2.zwzw; +/*--------------------------------------------------------------------------*/ + float4 rgbyN1 = tex2Dlod(fxaaConsole360TexExpBiasNegOne, float4(pos.xy + dir1.xy, 0.0, 0.0)); + float4 rgbyP1 = tex2Dlod(fxaaConsole360TexExpBiasNegOne, float4(pos.xy + dir1.zw, 0.0, 0.0)); + float4 rgbyN2 = tex2Dlod(fxaaConsole360TexExpBiasNegTwo, float4(pos.xy + dir2.xy, 0.0, 0.0)); + float4 rgbyP2 = tex2Dlod(fxaaConsole360TexExpBiasNegTwo, float4(pos.xy + dir2.zw, 0.0, 0.0)); +/*--------------------------------------------------------------------------*/ + float4 rgbyA = rgbyN1 + rgbyP1; + float4 rgbyB = rgbyN2 + rgbyP2 + rgbyA * 0.5; +/*--------------------------------------------------------------------------*/ + float4 rgbyR = ((FxaaLuma(rgbyB) - lumaMax) > 0.0) ? rgbyA : rgbyB; + rgbyR = ((FxaaLuma(rgbyB) - lumaMin) > 0.0) ? rgbyR : rgbyA; + return rgbyR; } +/*==========================================================================*/ +#endif + + + +/*============================================================================ + + FXAA3 CONSOLE - OPTIMIZED PS3 PIXEL SHADER (NO EARLY EXIT) + +============================================================================== +The code below does not exactly match the assembly. +I have a feeling that 12 cycles is possible, but was not able to get there. +Might have to increase register count to get full performance. +Note this shader does not use perspective interpolation. + +Use the following cgc options, + + --fenable-bx2 --fastmath --fastprecision --nofloatbindings + +------------------------------------------------------------------------------ + NVSHADERPERF OUTPUT +------------------------------------------------------------------------------ +For reference and to aid in debug, output of NVShaderPerf should match this, + +Shader to schedule: + 0: texpkb h0.w(TRUE), v5.zyxx, #0 + 2: addh h2.z(TRUE), h0.w, constant(0.001953, 0.000000, 0.000000, 0.000000).x + 4: texpkb h0.w(TRUE), v5.xwxx, #0 + 6: addh h0.z(TRUE), -h2, h0.w + 7: texpkb h1.w(TRUE), v5, #0 + 9: addh h0.x(TRUE), h0.z, -h1.w + 10: addh h3.w(TRUE), h0.z, h1 + 11: texpkb h2.w(TRUE), v5.zwzz, #0 + 13: addh h0.z(TRUE), h3.w, -h2.w + 14: addh h0.x(TRUE), h2.w, h0 + 15: nrmh h1.xz(TRUE), h0_n + 16: minh_m8 h0.x(TRUE), |h1|, |h1.z| + 17: maxh h4.w(TRUE), h0, h1 + 18: divx h2.xy(TRUE), h1_n.xzzw, h0_n + 19: movr r1.zw(TRUE), v4.xxxy + 20: madr r2.xz(TRUE), -h1, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).zzww, r1.zzww + 22: minh h5.w(TRUE), h0, h1 + 23: texpkb h0(TRUE), r2.xzxx, #0 + 25: madr r0.zw(TRUE), h1.xzxz, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w), r1 + 27: maxh h4.x(TRUE), h2.z, h2.w + 28: texpkb h1(TRUE), r0.zwzz, #0 + 30: addh_d2 h1(TRUE), h0, h1 + 31: madr r0.xy(TRUE), -h2, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).xyxx, r1.zwzz + 33: texpkb h0(TRUE), r0, #0 + 35: minh h4.z(TRUE), h2, h2.w + 36: fenct TRUE + 37: madr r1.xy(TRUE), h2, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).xyxx, r1.zwzz + 39: texpkb h2(TRUE), r1, #0 + 41: addh_d2 h0(TRUE), h0, h2 + 42: maxh h2.w(TRUE), h4, h4.x + 43: minh h2.x(TRUE), h5.w, h4.z + 44: addh_d2 h0(TRUE), h0, h1 + 45: slth h2.x(TRUE), h0.w, h2 + 46: sgth h2.w(TRUE), h0, h2 + 47: movh h0(TRUE), h0 + 48: addx.c0 rc(TRUE), h2, h2.w + 49: movh h0(c0.NE.x), h1 + +IPU0 ------ Simplified schedule: -------- +Pass | Unit | uOp | PC: Op +-----+--------+------+------------------------- + 1 | SCT0/1 | mov | 0: TXLr h0.w, g[TEX1].zyxx, const.xxxx, TEX0; + | TEX | txl | 0: TXLr h0.w, g[TEX1].zyxx, const.xxxx, TEX0; + | SCB1 | add | 2: ADDh h2.z, h0.--w-, const.--x-; + | | | + 2 | SCT0/1 | mov | 4: TXLr h0.w, g[TEX1].xwxx, const.xxxx, TEX0; + | TEX | txl | 4: TXLr h0.w, g[TEX1].xwxx, const.xxxx, TEX0; + | SCB1 | add | 6: ADDh h0.z,-h2, h0.--w-; + | | | + 3 | SCT0/1 | mov | 7: TXLr h1.w, g[TEX1], const.xxxx, TEX0; + | TEX | txl | 7: TXLr h1.w, g[TEX1], const.xxxx, TEX0; + | SCB0 | add | 9: ADDh h0.x, h0.z---,-h1.w---; + | SCB1 | add | 10: ADDh h3.w, h0.---z, h1; + | | | + 4 | SCT0/1 | mov | 11: TXLr h2.w, g[TEX1].zwzz, const.xxxx, TEX0; + | TEX | txl | 11: TXLr h2.w, g[TEX1].zwzz, const.xxxx, TEX0; + | SCB0 | add | 14: ADDh h0.x, h2.w---, h0; + | SCB1 | add | 13: ADDh h0.z, h3.--w-,-h2.--w-; + | | | + 5 | SCT1 | mov | 15: NRMh h1.xz, h0; + | SRB | nrm | 15: NRMh h1.xz, h0; + | SCB0 | min | 16: MINh*8 h0.x, |h1|, |h1.z---|; + | SCB1 | max | 17: MAXh h4.w, h0, h1; + | | | + 6 | SCT0 | div | 18: DIVx h2.xy, h1.xz--, h0; + | SCT1 | mov | 19: MOVr r1.zw, g[TEX0].--xy; + | SCB0 | mad | 20: MADr r2.xz,-h1, const.z-w-, r1.z-w-; + | SCB1 | min | 22: MINh h5.w, h0, h1; + | | | + 7 | SCT0/1 | mov | 23: TXLr h0, r2.xzxx, const.xxxx, TEX0; + | TEX | txl | 23: TXLr h0, r2.xzxx, const.xxxx, TEX0; + | SCB0 | max | 27: MAXh h4.x, h2.z---, h2.w---; + | SCB1 | mad | 25: MADr r0.zw, h1.--xz, const, r1; + | | | + 8 | SCT0/1 | mov | 28: TXLr h1, r0.zwzz, const.xxxx, TEX0; + | TEX | txl | 28: TXLr h1, r0.zwzz, const.xxxx, TEX0; + | SCB0/1 | add | 30: ADDh/2 h1, h0, h1; + | | | + 9 | SCT0 | mad | 31: MADr r0.xy,-h2, const.xy--, r1.zw--; + | SCT1 | mov | 33: TXLr h0, r0, const.zzzz, TEX0; + | TEX | txl | 33: TXLr h0, r0, const.zzzz, TEX0; + | SCB1 | min | 35: MINh h4.z, h2, h2.--w-; + | | | + 10 | SCT0 | mad | 37: MADr r1.xy, h2, const.xy--, r1.zw--; + | SCT1 | mov | 39: TXLr h2, r1, const.zzzz, TEX0; + | TEX | txl | 39: TXLr h2, r1, const.zzzz, TEX0; + | SCB0/1 | add | 41: ADDh/2 h0, h0, h2; + | | | + 11 | SCT0 | min | 43: MINh h2.x, h5.w---, h4.z---; + | SCT1 | max | 42: MAXh h2.w, h4, h4.---x; + | SCB0/1 | add | 44: ADDh/2 h0, h0, h1; + | | | + 12 | SCT0 | set | 45: SLTh h2.x, h0.w---, h2; + | SCT1 | set | 46: SGTh h2.w, h0, h2; + | SCB0/1 | mul | 47: MOVh h0, h0; + | | | + 13 | SCT0 | mad | 48: ADDxc0_s rc, h2, h2.w---; + | SCB0/1 | mul | 49: MOVh h0(NE0.xxxx), h1; + +Pass SCT TEX SCB + 1: 0% 100% 25% + 2: 0% 100% 25% + 3: 0% 100% 50% + 4: 0% 100% 50% + 5: 0% 0% 50% + 6: 100% 0% 75% + 7: 0% 100% 75% + 8: 0% 100% 100% + 9: 0% 100% 25% + 10: 0% 100% 100% + 11: 50% 0% 100% + 12: 50% 0% 100% + 13: 25% 0% 100% + +MEAN: 17% 61% 67% + +Pass SCT0 SCT1 TEX SCB0 SCB1 + 1: 0% 0% 100% 0% 100% + 2: 0% 0% 100% 0% 100% + 3: 0% 0% 100% 100% 100% + 4: 0% 0% 100% 100% 100% + 5: 0% 0% 0% 100% 100% + 6: 100% 100% 0% 100% 100% + 7: 0% 0% 100% 100% 100% + 8: 0% 0% 100% 100% 100% + 9: 0% 0% 100% 0% 100% + 10: 0% 0% 100% 100% 100% + 11: 100% 100% 0% 100% 100% + 12: 100% 100% 0% 100% 100% + 13: 100% 0% 0% 100% 100% + +MEAN: 30% 23% 61% 76% 100% +Fragment Performance Setup: Driver RSX Compiler, GPU RSX, Flags 0x5 +Results 13 cycles, 3 r regs, 923,076,923 pixels/s +============================================================================*/ +#if (FXAA_PS3 == 1) && (FXAA_EARLY_EXIT == 0) +/*--------------------------------------------------------------------------*/ +#pragma regcount 7 +#pragma disablepc all +#pragma option O3 +#pragma option OutColorPrec=fp16 +#pragma texformat default RGBA8 +/*==========================================================================*/ +half4 FxaaPixelShader( + // See FXAA Quality FxaaPixelShader() source for docs on Inputs! + FxaaFloat2 pos, + FxaaFloat4 fxaaConsolePosPos, + FxaaTex tex, + FxaaTex fxaaConsole360TexExpBiasNegOne, + FxaaTex fxaaConsole360TexExpBiasNegTwo, + FxaaFloat2 fxaaQualityRcpFrame, + FxaaFloat4 fxaaConsoleRcpFrameOpt, + FxaaFloat4 fxaaConsoleRcpFrameOpt2, + FxaaFloat4 fxaaConsole360RcpFrameOpt2, + FxaaFloat fxaaQualitySubpix, + FxaaFloat fxaaQualityEdgeThreshold, + FxaaFloat fxaaQualityEdgeThresholdMin, + FxaaFloat fxaaConsoleEdgeSharpness, + FxaaFloat fxaaConsoleEdgeThreshold, + FxaaFloat fxaaConsoleEdgeThresholdMin, + FxaaFloat4 fxaaConsole360ConstDir +) { +/*--------------------------------------------------------------------------*/ +// (1) + half4 dir; + half4 lumaNe = h4tex2Dlod(tex, half4(fxaaConsolePosPos.zy, 0, 0)); + #if (FXAA_GREEN_AS_LUMA == 0) + lumaNe.w += half(1.0/512.0); + dir.x = -lumaNe.w; + dir.z = -lumaNe.w; + #else + lumaNe.y += half(1.0/512.0); + dir.x = -lumaNe.y; + dir.z = -lumaNe.y; + #endif +/*--------------------------------------------------------------------------*/ +// (2) + half4 lumaSw = h4tex2Dlod(tex, half4(fxaaConsolePosPos.xw, 0, 0)); + #if (FXAA_GREEN_AS_LUMA == 0) + dir.x += lumaSw.w; + dir.z += lumaSw.w; + #else + dir.x += lumaSw.y; + dir.z += lumaSw.y; + #endif +/*--------------------------------------------------------------------------*/ +// (3) + half4 lumaNw = h4tex2Dlod(tex, half4(fxaaConsolePosPos.xy, 0, 0)); + #if (FXAA_GREEN_AS_LUMA == 0) + dir.x -= lumaNw.w; + dir.z += lumaNw.w; + #else + dir.x -= lumaNw.y; + dir.z += lumaNw.y; + #endif +/*--------------------------------------------------------------------------*/ +// (4) + half4 lumaSe = h4tex2Dlod(tex, half4(fxaaConsolePosPos.zw, 0, 0)); + #if (FXAA_GREEN_AS_LUMA == 0) + dir.x += lumaSe.w; + dir.z -= lumaSe.w; + #else + dir.x += lumaSe.y; + dir.z -= lumaSe.y; + #endif +/*--------------------------------------------------------------------------*/ +// (5) + half4 dir1_pos; + dir1_pos.xy = normalize(dir.xyz).xz; + half dirAbsMinTimesC = min(abs(dir1_pos.x), abs(dir1_pos.y)) * half(FXAA_CONSOLE__PS3_EDGE_SHARPNESS); +/*--------------------------------------------------------------------------*/ +// (6) + half4 dir2_pos; + dir2_pos.xy = clamp(dir1_pos.xy / dirAbsMinTimesC, half(-2.0), half(2.0)); + dir1_pos.zw = pos.xy; + dir2_pos.zw = pos.xy; + half4 temp1N; + temp1N.xy = dir1_pos.zw - dir1_pos.xy * fxaaConsoleRcpFrameOpt.zw; +/*--------------------------------------------------------------------------*/ +// (7) + temp1N = h4tex2Dlod(tex, half4(temp1N.xy, 0.0, 0.0)); + half4 rgby1; + rgby1.xy = dir1_pos.zw + dir1_pos.xy * fxaaConsoleRcpFrameOpt.zw; +/*--------------------------------------------------------------------------*/ +// (8) + rgby1 = h4tex2Dlod(tex, half4(rgby1.xy, 0.0, 0.0)); + rgby1 = (temp1N + rgby1) * 0.5; +/*--------------------------------------------------------------------------*/ +// (9) + half4 temp2N; + temp2N.xy = dir2_pos.zw - dir2_pos.xy * fxaaConsoleRcpFrameOpt2.zw; + temp2N = h4tex2Dlod(tex, half4(temp2N.xy, 0.0, 0.0)); +/*--------------------------------------------------------------------------*/ +// (10) + half4 rgby2; + rgby2.xy = dir2_pos.zw + dir2_pos.xy * fxaaConsoleRcpFrameOpt2.zw; + rgby2 = h4tex2Dlod(tex, half4(rgby2.xy, 0.0, 0.0)); + rgby2 = (temp2N + rgby2) * 0.5; +/*--------------------------------------------------------------------------*/ +// (11) + // compilier moves these scalar ops up to other cycles + #if (FXAA_GREEN_AS_LUMA == 0) + half lumaMin = min(min(lumaNw.w, lumaSw.w), min(lumaNe.w, lumaSe.w)); + half lumaMax = max(max(lumaNw.w, lumaSw.w), max(lumaNe.w, lumaSe.w)); + #else + half lumaMin = min(min(lumaNw.y, lumaSw.y), min(lumaNe.y, lumaSe.y)); + half lumaMax = max(max(lumaNw.y, lumaSw.y), max(lumaNe.y, lumaSe.y)); + #endif + rgby2 = (rgby2 + rgby1) * 0.5; +/*--------------------------------------------------------------------------*/ +// (12) + #if (FXAA_GREEN_AS_LUMA == 0) + bool twoTapLt = rgby2.w < lumaMin; + bool twoTapGt = rgby2.w > lumaMax; + #else + bool twoTapLt = rgby2.y < lumaMin; + bool twoTapGt = rgby2.y > lumaMax; + #endif +/*--------------------------------------------------------------------------*/ +// (13) + if(twoTapLt || twoTapGt) rgby2 = rgby1; +/*--------------------------------------------------------------------------*/ + return rgby2; } +/*==========================================================================*/ +#endif + + + +/*============================================================================ + + FXAA3 CONSOLE - OPTIMIZED PS3 PIXEL SHADER (WITH EARLY EXIT) + +============================================================================== +The code mostly matches the assembly. +I have a feeling that 14 cycles is possible, but was not able to get there. +Might have to increase register count to get full performance. +Note this shader does not use perspective interpolation. + +Use the following cgc options, + + --fenable-bx2 --fastmath --fastprecision --nofloatbindings + +Use of FXAA_GREEN_AS_LUMA currently adds a cycle (16 clks). +Will look at fixing this for FXAA 3.12. +------------------------------------------------------------------------------ + NVSHADERPERF OUTPUT +------------------------------------------------------------------------------ +For reference and to aid in debug, output of NVShaderPerf should match this, + +Shader to schedule: + 0: texpkb h0.w(TRUE), v5.zyxx, #0 + 2: addh h2.y(TRUE), h0.w, constant(0.001953, 0.000000, 0.000000, 0.000000).x + 4: texpkb h1.w(TRUE), v5.xwxx, #0 + 6: addh h0.x(TRUE), h1.w, -h2.y + 7: texpkb h2.w(TRUE), v5.zwzz, #0 + 9: minh h4.w(TRUE), h2.y, h2 + 10: maxh h5.x(TRUE), h2.y, h2.w + 11: texpkb h0.w(TRUE), v5, #0 + 13: addh h3.w(TRUE), -h0, h0.x + 14: addh h0.x(TRUE), h0.w, h0 + 15: addh h0.z(TRUE), -h2.w, h0.x + 16: addh h0.x(TRUE), h2.w, h3.w + 17: minh h5.y(TRUE), h0.w, h1.w + 18: nrmh h2.xz(TRUE), h0_n + 19: minh_m8 h2.w(TRUE), |h2.x|, |h2.z| + 20: divx h4.xy(TRUE), h2_n.xzzw, h2_n.w + 21: movr r1.zw(TRUE), v4.xxxy + 22: maxh h2.w(TRUE), h0, h1 + 23: fenct TRUE + 24: madr r0.xy(TRUE), -h2.xzzw, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).zwzz, r1.zwzz + 26: texpkb h0(TRUE), r0, #0 + 28: maxh h5.x(TRUE), h2.w, h5 + 29: minh h5.w(TRUE), h5.y, h4 + 30: madr r1.xy(TRUE), h2.xzzw, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).zwzz, r1.zwzz + 32: texpkb h2(TRUE), r1, #0 + 34: addh_d2 h2(TRUE), h0, h2 + 35: texpkb h1(TRUE), v4, #0 + 37: maxh h5.y(TRUE), h5.x, h1.w + 38: minh h4.w(TRUE), h1, h5 + 39: madr r0.xy(TRUE), -h4, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).xyxx, r1.zwzz + 41: texpkb h0(TRUE), r0, #0 + 43: addh_m8 h5.z(TRUE), h5.y, -h4.w + 44: madr r2.xy(TRUE), h4, constant(cConst5.x, cConst5.y, cConst5.z, cConst5.w).xyxx, r1.zwzz + 46: texpkb h3(TRUE), r2, #0 + 48: addh_d2 h0(TRUE), h0, h3 + 49: addh_d2 h3(TRUE), h0, h2 + 50: movh h0(TRUE), h3 + 51: slth h3.x(TRUE), h3.w, h5.w + 52: sgth h3.w(TRUE), h3, h5.x + 53: addx.c0 rc(TRUE), h3.x, h3 + 54: slth.c0 rc(TRUE), h5.z, h5 + 55: movh h0(c0.NE.w), h2 + 56: movh h0(c0.NE.x), h1 + +IPU0 ------ Simplified schedule: -------- +Pass | Unit | uOp | PC: Op +-----+--------+------+------------------------- + 1 | SCT0/1 | mov | 0: TXLr h0.w, g[TEX1].zyxx, const.xxxx, TEX0; + | TEX | txl | 0: TXLr h0.w, g[TEX1].zyxx, const.xxxx, TEX0; + | SCB0 | add | 2: ADDh h2.y, h0.-w--, const.-x--; + | | | + 2 | SCT0/1 | mov | 4: TXLr h1.w, g[TEX1].xwxx, const.xxxx, TEX0; + | TEX | txl | 4: TXLr h1.w, g[TEX1].xwxx, const.xxxx, TEX0; + | SCB0 | add | 6: ADDh h0.x, h1.w---,-h2.y---; + | | | + 3 | SCT0/1 | mov | 7: TXLr h2.w, g[TEX1].zwzz, const.xxxx, TEX0; + | TEX | txl | 7: TXLr h2.w, g[TEX1].zwzz, const.xxxx, TEX0; + | SCB0 | max | 10: MAXh h5.x, h2.y---, h2.w---; + | SCB1 | min | 9: MINh h4.w, h2.---y, h2; + | | | + 4 | SCT0/1 | mov | 11: TXLr h0.w, g[TEX1], const.xxxx, TEX0; + | TEX | txl | 11: TXLr h0.w, g[TEX1], const.xxxx, TEX0; + | SCB0 | add | 14: ADDh h0.x, h0.w---, h0; + | SCB1 | add | 13: ADDh h3.w,-h0, h0.---x; + | | | + 5 | SCT0 | mad | 16: ADDh h0.x, h2.w---, h3.w---; + | SCT1 | mad | 15: ADDh h0.z,-h2.--w-, h0.--x-; + | SCB0 | min | 17: MINh h5.y, h0.-w--, h1.-w--; + | | | + 6 | SCT1 | mov | 18: NRMh h2.xz, h0; + | SRB | nrm | 18: NRMh h2.xz, h0; + | SCB1 | min | 19: MINh*8 h2.w, |h2.---x|, |h2.---z|; + | | | + 7 | SCT0 | div | 20: DIVx h4.xy, h2.xz--, h2.ww--; + | SCT1 | mov | 21: MOVr r1.zw, g[TEX0].--xy; + | SCB1 | max | 22: MAXh h2.w, h0, h1; + | | | + 8 | SCT0 | mad | 24: MADr r0.xy,-h2.xz--, const.zw--, r1.zw--; + | SCT1 | mov | 26: TXLr h0, r0, const.xxxx, TEX0; + | TEX | txl | 26: TXLr h0, r0, const.xxxx, TEX0; + | SCB0 | max | 28: MAXh h5.x, h2.w---, h5; + | SCB1 | min | 29: MINh h5.w, h5.---y, h4; + | | | + 9 | SCT0 | mad | 30: MADr r1.xy, h2.xz--, const.zw--, r1.zw--; + | SCT1 | mov | 32: TXLr h2, r1, const.xxxx, TEX0; + | TEX | txl | 32: TXLr h2, r1, const.xxxx, TEX0; + | SCB0/1 | add | 34: ADDh/2 h2, h0, h2; + | | | + 10 | SCT0/1 | mov | 35: TXLr h1, g[TEX0], const.xxxx, TEX0; + | TEX | txl | 35: TXLr h1, g[TEX0], const.xxxx, TEX0; + | SCB0 | max | 37: MAXh h5.y, h5.-x--, h1.-w--; + | SCB1 | min | 38: MINh h4.w, h1, h5; + | | | + 11 | SCT0 | mad | 39: MADr r0.xy,-h4, const.xy--, r1.zw--; + | SCT1 | mov | 41: TXLr h0, r0, const.zzzz, TEX0; + | TEX | txl | 41: TXLr h0, r0, const.zzzz, TEX0; + | SCB0 | mad | 44: MADr r2.xy, h4, const.xy--, r1.zw--; + | SCB1 | add | 43: ADDh*8 h5.z, h5.--y-,-h4.--w-; + | | | + 12 | SCT0/1 | mov | 46: TXLr h3, r2, const.xxxx, TEX0; + | TEX | txl | 46: TXLr h3, r2, const.xxxx, TEX0; + | SCB0/1 | add | 48: ADDh/2 h0, h0, h3; + | | | + 13 | SCT0/1 | mad | 49: ADDh/2 h3, h0, h2; + | SCB0/1 | mul | 50: MOVh h0, h3; + | | | + 14 | SCT0 | set | 51: SLTh h3.x, h3.w---, h5.w---; + | SCT1 | set | 52: SGTh h3.w, h3, h5.---x; + | SCB0 | set | 54: SLThc0 rc, h5.z---, h5; + | SCB1 | add | 53: ADDxc0_s rc, h3.---x, h3; + | | | + 15 | SCT0/1 | mul | 55: MOVh h0(NE0.wwww), h2; + | SCB0/1 | mul | 56: MOVh h0(NE0.xxxx), h1; + +Pass SCT TEX SCB + 1: 0% 100% 25% + 2: 0% 100% 25% + 3: 0% 100% 50% + 4: 0% 100% 50% + 5: 50% 0% 25% + 6: 0% 0% 25% + 7: 100% 0% 25% + 8: 0% 100% 50% + 9: 0% 100% 100% + 10: 0% 100% 50% + 11: 0% 100% 75% + 12: 0% 100% 100% + 13: 100% 0% 100% + 14: 50% 0% 50% + 15: 100% 0% 100% + +MEAN: 26% 60% 56% + +Pass SCT0 SCT1 TEX SCB0 SCB1 + 1: 0% 0% 100% 100% 0% + 2: 0% 0% 100% 100% 0% + 3: 0% 0% 100% 100% 100% + 4: 0% 0% 100% 100% 100% + 5: 100% 100% 0% 100% 0% + 6: 0% 0% 0% 0% 100% + 7: 100% 100% 0% 0% 100% + 8: 0% 0% 100% 100% 100% + 9: 0% 0% 100% 100% 100% + 10: 0% 0% 100% 100% 100% + 11: 0% 0% 100% 100% 100% + 12: 0% 0% 100% 100% 100% + 13: 100% 100% 0% 100% 100% + 14: 100% 100% 0% 100% 100% + 15: 100% 100% 0% 100% 100% + +MEAN: 33% 33% 60% 86% 80% +Fragment Performance Setup: Driver RSX Compiler, GPU RSX, Flags 0x5 +Results 15 cycles, 3 r regs, 800,000,000 pixels/s +============================================================================*/ +#if (FXAA_PS3 == 1) && (FXAA_EARLY_EXIT == 1) +/*--------------------------------------------------------------------------*/ +#pragma regcount 7 +#pragma disablepc all +#pragma option O2 +#pragma option OutColorPrec=fp16 +#pragma texformat default RGBA8 +/*==========================================================================*/ +half4 FxaaPixelShader( + // See FXAA Quality FxaaPixelShader() source for docs on Inputs! + FxaaFloat2 pos, + FxaaFloat4 fxaaConsolePosPos, + FxaaTex tex, + FxaaTex fxaaConsole360TexExpBiasNegOne, + FxaaTex fxaaConsole360TexExpBiasNegTwo, + FxaaFloat2 fxaaQualityRcpFrame, + FxaaFloat4 fxaaConsoleRcpFrameOpt, + FxaaFloat4 fxaaConsoleRcpFrameOpt2, + FxaaFloat4 fxaaConsole360RcpFrameOpt2, + FxaaFloat fxaaQualitySubpix, + FxaaFloat fxaaQualityEdgeThreshold, + FxaaFloat fxaaQualityEdgeThresholdMin, + FxaaFloat fxaaConsoleEdgeSharpness, + FxaaFloat fxaaConsoleEdgeThreshold, + FxaaFloat fxaaConsoleEdgeThresholdMin, + FxaaFloat4 fxaaConsole360ConstDir +) { +/*--------------------------------------------------------------------------*/ +// (1) + half4 rgbyNe = h4tex2Dlod(tex, half4(fxaaConsolePosPos.zy, 0, 0)); + #if (FXAA_GREEN_AS_LUMA == 0) + half lumaNe = rgbyNe.w + half(1.0/512.0); + #else + half lumaNe = rgbyNe.y + half(1.0/512.0); + #endif +/*--------------------------------------------------------------------------*/ +// (2) + half4 lumaSw = h4tex2Dlod(tex, half4(fxaaConsolePosPos.xw, 0, 0)); + #if (FXAA_GREEN_AS_LUMA == 0) + half lumaSwNegNe = lumaSw.w - lumaNe; + #else + half lumaSwNegNe = lumaSw.y - lumaNe; + #endif +/*--------------------------------------------------------------------------*/ +// (3) + half4 lumaNw = h4tex2Dlod(tex, half4(fxaaConsolePosPos.xy, 0, 0)); + #if (FXAA_GREEN_AS_LUMA == 0) + half lumaMaxNwSw = max(lumaNw.w, lumaSw.w); + half lumaMinNwSw = min(lumaNw.w, lumaSw.w); + #else + half lumaMaxNwSw = max(lumaNw.y, lumaSw.y); + half lumaMinNwSw = min(lumaNw.y, lumaSw.y); + #endif +/*--------------------------------------------------------------------------*/ +// (4) + half4 lumaSe = h4tex2Dlod(tex, half4(fxaaConsolePosPos.zw, 0, 0)); + #if (FXAA_GREEN_AS_LUMA == 0) + half dirZ = lumaNw.w + lumaSwNegNe; + half dirX = -lumaNw.w + lumaSwNegNe; + #else + half dirZ = lumaNw.y + lumaSwNegNe; + half dirX = -lumaNw.y + lumaSwNegNe; + #endif +/*--------------------------------------------------------------------------*/ +// (5) + half3 dir; + dir.y = 0.0; + #if (FXAA_GREEN_AS_LUMA == 0) + dir.x = lumaSe.w + dirX; + dir.z = -lumaSe.w + dirZ; + half lumaMinNeSe = min(lumaNe, lumaSe.w); + #else + dir.x = lumaSe.y + dirX; + dir.z = -lumaSe.y + dirZ; + half lumaMinNeSe = min(lumaNe, lumaSe.y); + #endif +/*--------------------------------------------------------------------------*/ +// (6) + half4 dir1_pos; + dir1_pos.xy = normalize(dir).xz; + half dirAbsMinTimes8 = min(abs(dir1_pos.x), abs(dir1_pos.y)) * half(FXAA_CONSOLE__PS3_EDGE_SHARPNESS); +/*--------------------------------------------------------------------------*/ +// (7) + half4 dir2_pos; + dir2_pos.xy = clamp(dir1_pos.xy / dirAbsMinTimes8, half(-2.0), half(2.0)); + dir1_pos.zw = pos.xy; + dir2_pos.zw = pos.xy; + #if (FXAA_GREEN_AS_LUMA == 0) + half lumaMaxNeSe = max(lumaNe, lumaSe.w); + #else + half lumaMaxNeSe = max(lumaNe, lumaSe.y); + #endif +/*--------------------------------------------------------------------------*/ +// (8) + half4 temp1N; + temp1N.xy = dir1_pos.zw - dir1_pos.xy * fxaaConsoleRcpFrameOpt.zw; + temp1N = h4tex2Dlod(tex, half4(temp1N.xy, 0.0, 0.0)); + half lumaMax = max(lumaMaxNwSw, lumaMaxNeSe); + half lumaMin = min(lumaMinNwSw, lumaMinNeSe); +/*--------------------------------------------------------------------------*/ +// (9) + half4 rgby1; + rgby1.xy = dir1_pos.zw + dir1_pos.xy * fxaaConsoleRcpFrameOpt.zw; + rgby1 = h4tex2Dlod(tex, half4(rgby1.xy, 0.0, 0.0)); + rgby1 = (temp1N + rgby1) * 0.5; +/*--------------------------------------------------------------------------*/ +// (10) + half4 rgbyM = h4tex2Dlod(tex, half4(pos.xy, 0.0, 0.0)); + #if (FXAA_GREEN_AS_LUMA == 0) + half lumaMaxM = max(lumaMax, rgbyM.w); + half lumaMinM = min(lumaMin, rgbyM.w); + #else + half lumaMaxM = max(lumaMax, rgbyM.y); + half lumaMinM = min(lumaMin, rgbyM.y); + #endif +/*--------------------------------------------------------------------------*/ +// (11) + half4 temp2N; + temp2N.xy = dir2_pos.zw - dir2_pos.xy * fxaaConsoleRcpFrameOpt2.zw; + temp2N = h4tex2Dlod(tex, half4(temp2N.xy, 0.0, 0.0)); + half4 rgby2; + rgby2.xy = dir2_pos.zw + dir2_pos.xy * fxaaConsoleRcpFrameOpt2.zw; + half lumaRangeM = (lumaMaxM - lumaMinM) / FXAA_CONSOLE__PS3_EDGE_THRESHOLD; +/*--------------------------------------------------------------------------*/ +// (12) + rgby2 = h4tex2Dlod(tex, half4(rgby2.xy, 0.0, 0.0)); + rgby2 = (temp2N + rgby2) * 0.5; +/*--------------------------------------------------------------------------*/ +// (13) + rgby2 = (rgby2 + rgby1) * 0.5; +/*--------------------------------------------------------------------------*/ +// (14) + #if (FXAA_GREEN_AS_LUMA == 0) + bool twoTapLt = rgby2.w < lumaMin; + bool twoTapGt = rgby2.w > lumaMax; + #else + bool twoTapLt = rgby2.y < lumaMin; + bool twoTapGt = rgby2.y > lumaMax; + #endif + bool earlyExit = lumaRangeM < lumaMax; + bool twoTap = twoTapLt || twoTapGt; +/*--------------------------------------------------------------------------*/ +// (15) + if(twoTap) rgby2 = rgby1; + if(earlyExit) rgby2 = rgbyM; +/*--------------------------------------------------------------------------*/ + return rgby2; } +/*==========================================================================*/ +#endif + +// ---- Created with 3Dmigoto v1.4.9 on Wed Feb 25 15:30:06 2026 + +cbuffer CBScreen : register(b1) +{ + float2 fScreenOffset : packoffset(c0) = {1,-1}; + float2 fScreenScale : packoffset(c0.z) = {0.5,-0.5}; + float2 fScreenSize : packoffset(c1) = {1280,720}; + float2 fScreenInverseSize : packoffset(c1.z) = {0.000781250012,0.00138888892}; + uint2 iViewOffset : packoffset(c2); + uint2 iViewSize : packoffset(c2.z); + float2 fViewOffset : packoffset(c3); + float2 fViewSize : packoffset(c3.z); + float2 fViewInverseSize : packoffset(c4); + float fContentScale : packoffset(c4.z); + float fContentScalePF : packoffset(c4.w); + float fContentScaleBase : packoffset(c5); + float fContentScaleActual : packoffset(c5.y); + float fContentScaleInverse : packoffset(c5.z); + float fContentScaleBaseInverse : packoffset(c5.w); + float fContentScaleActualInverse : packoffset(c6); + float fContentScalePassScreen : packoffset(c6.y); + bool bCheckerboard : packoffset(c6.z); +} + +cbuffer CBFXAAParam : register(b3) +{ + float fFXAAQualitySubpix : packoffset(c0); + float fFXAAQualityEdgeThreshold : packoffset(c0.y); + float fFXAAQualityEdgeThresholdMin : packoffset(c0.z); + float2 fFXAATexOnePitch : packoffset(c1); +} + +SamplerState SSFilter : register(s0); +Texture2D tBaseMap : register(t0); + +void main( + float4 v0 : SV_POSITION0, + float2 v1 : TexCoord0, + float2 w1 : TexCoord1, + float4 v2 : Color0, + out float4 o0 : SV_Target0) +{ + FxaaTex tex; + tex.smpl = SSFilter; + tex.tex = tBaseMap; + o0 = FxaaPixelShader( + v1, + float4(0, 0, 0, 0), + tex, + tex, + tex, + fScreenInverseSize, + float4(0, 0, 0, 0), + float4(0, 0, 0, 0), + float4(0, 0, 0, 0), + fFXAAQualitySubpix, + fFXAAQualityEdgeThreshold, + fFXAAQualityEdgeThresholdMin, + 0.0, + 0.0, + 0.0, + float4(0, 0, 0, 0) + ); +} diff --git a/Shaders/notes.txt b/Shaders/notes.txt new file mode 100644 index 0000000..a2e172b --- /dev/null +++ b/Shaders/notes.txt @@ -0,0 +1,11 @@ +# FXAA Source +https://web.archive.org/web/20120121124756/https://docs.google.com/leaf?id=0B2manFVVrzQAOWUwODM1YmQtNmEwOC00ZDBlLThlYzMtYzE4ZDM1ZjRlMzMx&hl=en_US +https://gist.githubusercontent.com/kosua20/0c506b81b3812ac900048059d2383126/raw/9c1f4b97ea5a2ac4bf632fff509f64d7dff0e96a/gistfile1.txt +# Both sources identical and contain this final patch. +https://web.archive.org/web/20120121124756/http://timothylottes.blogspot.com/2011/08/fxaa-311-bug-fixes-for-360.html + +# Links +https://github.com/bo3b/3Dmigoto +https://stackoverflow.com/questions/74722423/i-need-a-source-of-information-about-directxs-assembler +https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/registers---cs-5-0 +https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-to-load diff --git a/Shaders/sslr.diff b/Shaders/sslr.diff new file mode 100644 index 0000000..041d01c --- /dev/null +++ b/Shaders/sslr.diff @@ -0,0 +1,15 @@ +--- a/sslr.asm 2026-03-16 15:19:48.982185265 -0400 ++++ b/sslr.asm 2026-03-16 15:19:28.862978198 -0400 +@@ -246,6 +90,12 @@ + mov [precise(zw)] r0.zw, l(0,0,0,0) + ld_indexable [precise(yw)](texture2d)(float,float,float,float) r1.xyzw, r0.xyww, t4.xyzw + ld_indexable [precise(xyw)](texture2d)(float,float,float,float) r2.xyzw, r0.xyww, t5.xyzw ++ ieq r4.x, r2.w, l(0x3d60e0e1) ++ and r4.x, r4.x, l(0x00404040) ++ xor r2.w, r2.w, r4.x ++ ieq r4.x, r2.w, l(0x3cc0c0c1) ++ and r4.x, r4.x, l(0x00c04040) ++ xor r2.w, r2.w, r4.x + ld_indexable [precise(xyz)](texture2d)(float,float,float,float) r3.xyz, r0.xyww, t6.xyzw + ld_indexable [precise(w)](texture2d)(uint,uint,uint,uint) r3.w, r0.xyww, t7.yzwx + mul [precise(w)] r1.w, r1.w, l(255.000000) diff --git a/Shaders/volume_upsample.diff b/Shaders/volume_upsample.diff new file mode 100644 index 0000000..13c9633 --- /dev/null +++ b/Shaders/volume_upsample.diff @@ -0,0 +1,22 @@ +--- a/volume_upsample.asm 2026-03-16 15:19:54.032009332 -0400 ++++ b/volume_upsample.asm 2026-03-16 15:19:36.341817879 -0400 +@@ -235,16 +155,9 @@ + ld_indexable(texture2d)(float,float,float,float) r1.yzw, r2.xyzz, t3.wxyz + ld_indexable(texture2d)(float,float,float,float) r3.xyz, r2.xyzz, t4.xyzw + else +- if_nz r1.x +- mul r0.xy, r0.xyxx, cb3[2].xyxx +- mul r0.xy, r0.xyxx, cb1[4].zzzz +- sample_l_indexable(texture2d)(float,float,float,float) r1.yzw, r0.xyxx, t0.wxyz, s0, l(0.000000) +- sample_l_indexable(texture2d)(float,float,float,float) r3.xyz, r0.xyxx, t1.xyzw, s0, l(0.000000) +- else +- mov r2.w, l(0) +- ld_indexable(texture2d)(float,float,float,float) r1.yzw, r2.xyww, t0.wxyz +- ld_indexable(texture2d)(float,float,float,float) r3.xyz, r2.xyww, t1.xyzw +- endif ++ mov r2.w, l(0) ++ ld_indexable(texture2d)(float,float,float,float) r1.yzw, r2.xyww, t0.wxyz ++ ld_indexable(texture2d)(float,float,float,float) r3.xyz, r2.xyww, t1.xyzw + endif + store_uav_typed u0.xyzw, vThreadID.xyyy, r0.wwww + store_uav_typed u1.xyzw, vThreadID.xyyy, r1.yzwy diff --git a/Shaders/volume_upsample2.diff b/Shaders/volume_upsample2.diff new file mode 100644 index 0000000..0887f10 --- /dev/null +++ b/Shaders/volume_upsample2.diff @@ -0,0 +1,191 @@ +--- a/volume_upsample2.asm 2026-03-16 15:19:50.820204181 -0400 ++++ b/volume_upsample2.asm 2026-03-16 15:19:31.707007465 -0400 +@@ -254,103 +182,92 @@ + else + mov r0.w, l(0) + endif +-if_nz r0.w +- utof r1.xy, r2.xyxx +- mul r1.xy, r1.xyxx, cb3[2].zwzz +- mul r1.xy, r1.xyxx, cb1[4].zzzz +- mad r1.zw, -cb1[1].zzzw, l(0.000000, 0.000000, 0.500000, 0.500000), cb1[4].zzzz +- max r1.xy, r1.xyxx, l(0.000000, 0.000000, 0.000000, 0.000000) +- min r1.xy, r1.zwzz, r1.xyxx +- sample_l_indexable(texture2d)(float,float,float,float) r3.xyz, r1.xyxx, t1.xyzw, s0, l(0.000000) +- sample_l_indexable(texture2d)(float,float,float,float) r1.xyz, r1.xyxx, t2.xyzw, s0, l(0.000000) ++if_nz r0.z ++ iadd r0.xy, -r0.xyxx, r2.yxyy ++ mov r4.xy, vThreadID.xyxx ++ mov r4.zw, l(0,0,0,0) ++ ld_indexable(texture2d)(float,float,float,float) r0.z, r4.xyzw, t0.yzxw ++ not r4.xy, r0.xyxx ++ imad r0.y, r4.x, l(-9), r0.y ++ imad r0.w, r4.x, l(-9), -r4.y ++ ishl r0.w, r0.w, l(8) ++ or r0.w, r0.w, r0.y ++ imad r0.x, r0.x, l(9), -r4.y ++ ishl r0.xy, r0.xyxx, l(16, 24, 0, 0) ++ or r0.x, r0.x, r0.w ++ or r0.x, r0.y, r0.x ++ bfi r0.y, l(1), l(1), vThreadIDInGroup.y, l(0) ++ bfi r0.y, l(1), l(0), vThreadIDInGroup.x, r0.y ++ and r0.w, r0.x, l(255) ++ ld_structured r1.w, r0.w, l(0), g0.xxxx ++ add r1.w, r0.z, -r1.w ++ add r1.w, |r1.w|, l(1.192092896E-07) ++ iadd r3.w, -r1.w, l(0x7ef312ac) ++ mad r4.x, -r3.w, r1.w, l(2.000000) ++ mul r3.w, r3.w, r4.x ++ mad r1.w, -r3.w, r1.w, l(2.000000) ++ mul r1.w, r1.w, r3.w ++ mul r3.w, r1.w, icb[r0.y + 0].x ++ ld_structured r4.xyz, r0.w, l(0), g1.xyzx ++ ld_structured r5.xyz, r0.w, l(0), g2.xyzx ++ mad r0.w, r1.w, icb[r0.y + 0].x, l(1.192092896E-07) ++ ubfe r6.xy, l(8, 8, 0, 0), l(8, 16, 0, 0), r0.xxxx ++ ld_structured r1.w, r6.x, l(0), g0.xxxx ++ add r1.w, r0.z, -r1.w ++ add r1.w, |r1.w|, l(1.192092896E-07) ++ iadd r4.w, -r1.w, l(0x7ef312ac) ++ mad r5.w, -r4.w, r1.w, l(2.000000) ++ mul r4.w, r4.w, r5.w ++ mad r1.w, -r4.w, r1.w, l(2.000000) ++ mul r1.w, r1.w, r4.w ++ mul r4.w, r1.w, icb[r0.y + 0].y ++ ld_structured r7.xyz, r6.x, l(0), g1.xyzx ++ mul r7.xyz, r4.wwww, r7.xyzx ++ mad r4.xyz, r4.xyzx, r3.wwww, r7.xyzx ++ ld_structured r6.xzw, r6.x, l(0), g2.xxyz ++ mul r6.xzw, r4.wwww, r6.xxzw ++ mad r5.xyz, r5.xyzx, r3.wwww, r6.xzwx ++ mad r0.w, r1.w, icb[r0.y + 0].y, r0.w ++ ld_structured r1.w, r6.y, l(0), g0.xxxx ++ add r1.w, r0.z, -r1.w ++ add r1.w, |r1.w|, l(1.192092896E-07) ++ iadd r3.w, -r1.w, l(0x7ef312ac) ++ mad r4.w, -r3.w, r1.w, l(2.000000) ++ mul r3.w, r3.w, r4.w ++ mad r1.w, -r3.w, r1.w, l(2.000000) ++ mul r1.w, r1.w, r3.w ++ mul r3.w, r1.w, icb[r0.y + 0].z ++ ld_structured r6.xzw, r6.y, l(0), g1.xxyz ++ mad r4.xyz, r6.xzwx, r3.wwww, r4.xyzx ++ ld_structured r6.xyz, r6.y, l(0), g2.xyzx ++ mad r5.xyz, r6.xyzx, r3.wwww, r5.xyzx ++ mad r0.w, r1.w, icb[r0.y + 0].z, r0.w ++ ushr r0.x, r0.x, l(24) ++ ld_structured r1.w, r0.x, l(0), g0.xxxx ++ add r0.z, r0.z, -r1.w ++ add r0.z, |r0.z|, l(1.192092896E-07) ++ iadd r1.w, -r0.z, l(0x7ef312ac) ++ mad r3.w, -r1.w, r0.z, l(2.000000) ++ mul r1.w, r1.w, r3.w ++ mad r0.z, -r1.w, r0.z, l(2.000000) ++ mul r0.z, r0.z, r1.w ++ mul r1.w, r0.z, icb[r0.y + 0].w ++ ld_structured r6.xyz, r0.x, l(0), g1.xyzx ++ mad r4.xyz, r6.xyzx, r1.wwww, r4.xyzx ++ ld_structured r6.xyz, r0.x, l(0), g2.xyzx ++ mad r5.xyz, r6.xyzx, r1.wwww, r5.xyzx ++ mad r0.x, r0.z, icb[r0.y + 0].w, r0.w ++ iadd r0.y, -r0.x, l(0x7ef312ac) ++ mad r0.z, -r0.y, r0.x, l(2.000000) ++ mul r0.y, r0.z, r0.y ++ mad r0.x, -r0.y, r0.x, l(2.000000) ++ mul r0.x, r0.x, r0.y ++ mul r3.xyz, r0.xxxx, r4.xyzx ++ mul r1.xyz, r0.xxxx, r5.xyzx + else +- if_nz r0.z +- iadd r0.xy, -r0.xyxx, r2.yxyy +- mov r4.xy, vThreadID.xyxx +- mov r4.zw, l(0,0,0,0) +- ld_indexable(texture2d)(float,float,float,float) r0.z, r4.xyzw, t0.yzxw +- not r4.xy, r0.xyxx +- imad r0.y, r4.x, l(-9), r0.y +- imad r0.w, r4.x, l(-9), -r4.y +- ishl r0.w, r0.w, l(8) +- or r0.w, r0.w, r0.y +- imad r0.x, r0.x, l(9), -r4.y +- ishl r0.xy, r0.xyxx, l(16, 24, 0, 0) +- or r0.x, r0.x, r0.w +- or r0.x, r0.y, r0.x +- bfi r0.y, l(1), l(1), vThreadIDInGroup.y, l(0) +- bfi r0.y, l(1), l(0), vThreadIDInGroup.x, r0.y +- and r0.w, r0.x, l(255) +- ld_structured r1.w, r0.w, l(0), g0.xxxx +- add r1.w, r0.z, -r1.w +- add r1.w, |r1.w|, l(1.192092896E-07) +- iadd r3.w, -r1.w, l(0x7ef312ac) +- mad r4.x, -r3.w, r1.w, l(2.000000) +- mul r3.w, r3.w, r4.x +- mad r1.w, -r3.w, r1.w, l(2.000000) +- mul r1.w, r1.w, r3.w +- mul r3.w, r1.w, icb[r0.y + 0].x +- ld_structured r4.xyz, r0.w, l(0), g1.xyzx +- ld_structured r5.xyz, r0.w, l(0), g2.xyzx +- mad r0.w, r1.w, icb[r0.y + 0].x, l(1.192092896E-07) +- ubfe r6.xy, l(8, 8, 0, 0), l(8, 16, 0, 0), r0.xxxx +- ld_structured r1.w, r6.x, l(0), g0.xxxx +- add r1.w, r0.z, -r1.w +- add r1.w, |r1.w|, l(1.192092896E-07) +- iadd r4.w, -r1.w, l(0x7ef312ac) +- mad r5.w, -r4.w, r1.w, l(2.000000) +- mul r4.w, r4.w, r5.w +- mad r1.w, -r4.w, r1.w, l(2.000000) +- mul r1.w, r1.w, r4.w +- mul r4.w, r1.w, icb[r0.y + 0].y +- ld_structured r7.xyz, r6.x, l(0), g1.xyzx +- mul r7.xyz, r4.wwww, r7.xyzx +- mad r4.xyz, r4.xyzx, r3.wwww, r7.xyzx +- ld_structured r6.xzw, r6.x, l(0), g2.xxyz +- mul r6.xzw, r4.wwww, r6.xxzw +- mad r5.xyz, r5.xyzx, r3.wwww, r6.xzwx +- mad r0.w, r1.w, icb[r0.y + 0].y, r0.w +- ld_structured r1.w, r6.y, l(0), g0.xxxx +- add r1.w, r0.z, -r1.w +- add r1.w, |r1.w|, l(1.192092896E-07) +- iadd r3.w, -r1.w, l(0x7ef312ac) +- mad r4.w, -r3.w, r1.w, l(2.000000) +- mul r3.w, r3.w, r4.w +- mad r1.w, -r3.w, r1.w, l(2.000000) +- mul r1.w, r1.w, r3.w +- mul r3.w, r1.w, icb[r0.y + 0].z +- ld_structured r6.xzw, r6.y, l(0), g1.xxyz +- mad r4.xyz, r6.xzwx, r3.wwww, r4.xyzx +- ld_structured r6.xyz, r6.y, l(0), g2.xyzx +- mad r5.xyz, r6.xyzx, r3.wwww, r5.xyzx +- mad r0.w, r1.w, icb[r0.y + 0].z, r0.w +- ushr r0.x, r0.x, l(24) +- ld_structured r1.w, r0.x, l(0), g0.xxxx +- add r0.z, r0.z, -r1.w +- add r0.z, |r0.z|, l(1.192092896E-07) +- iadd r1.w, -r0.z, l(0x7ef312ac) +- mad r3.w, -r1.w, r0.z, l(2.000000) +- mul r1.w, r1.w, r3.w +- mad r0.z, -r1.w, r0.z, l(2.000000) +- mul r0.z, r0.z, r1.w +- mul r1.w, r0.z, icb[r0.y + 0].w +- ld_structured r6.xyz, r0.x, l(0), g1.xyzx +- mad r4.xyz, r6.xyzx, r1.wwww, r4.xyzx +- ld_structured r6.xyz, r0.x, l(0), g2.xyzx +- mad r5.xyz, r6.xyzx, r1.wwww, r5.xyzx +- mad r0.x, r0.z, icb[r0.y + 0].w, r0.w +- iadd r0.y, -r0.x, l(0x7ef312ac) +- mad r0.z, -r0.y, r0.x, l(2.000000) +- mul r0.y, r0.z, r0.y +- mad r0.x, -r0.y, r0.x, l(2.000000) +- mul r0.x, r0.x, r0.y +- mul r3.xyz, r0.xxxx, r4.xyzx +- mul r1.xyz, r0.xxxx, r5.xyzx +- else +- mov r2.zw, l(0,0,0,0) +- ld_indexable(texture2d)(float,float,float,float) r3.xyz, r2.xyww, t1.xyzw +- ld_indexable(texture2d)(float,float,float,float) r1.xyz, r2.xyzw, t2.xyzw +- endif ++ mov r2.zw, l(0,0,0,0) ++ ld_indexable(texture2d)(float,float,float,float) r3.xyz, r2.xyww, t1.xyzw ++ ld_indexable(texture2d)(float,float,float,float) r1.xyz, r2.xyzw, t2.xyzw + endif + store_uav_typed u1.xyzw, vThreadID.xyyy, r1.xyzz + store_uav_typed u0.xyzw, vThreadID.xyyy, r3.xyzz diff --git a/WorldTuningTool.csproj b/WorldTuningTool.csproj new file mode 100755 index 0000000..bde04c5 --- /dev/null +++ b/WorldTuningTool.csproj @@ -0,0 +1,26 @@ + + + + net8.0 + enable + enable + True + + + + + + + + + ..\SharpPluginLoader-fork\SharpPluginLoader.Bootstrapper\bin\Release\net8.0\SharpPluginLoader.Bootstrapper.dll + + + ..\SharpPluginLoader-fork\SharpPluginLoader.Core\bin\Release\net8.0\SharpPluginLoader.Core.dll + + + ..\SharpPluginLoader-fork\SharpPluginLoader.InternalCallGenerator\bin\Release\netstandard2.0\SharpPluginLoader.InternalCallGenerator.dll + + + + diff --git a/WorldTuningTool.sln b/WorldTuningTool.sln new file mode 100755 index 0000000..052a1c4 --- /dev/null +++ b/WorldTuningTool.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35514.174 d17.12 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("F2C49107-DDB9-415B-9A7F-DE6B9BA1E104") = "WorldTuningTool", "WorldTuningTool.csproj", "{E9DE1105-BC7A-4753-9181-E7DA03727E54}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E9DE1105-BC7A-4753-9181-E7DA03727E54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E9DE1105-BC7A-4753-9181-E7DA03727E54}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E9DE1105-BC7A-4753-9181-E7DA03727E54}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E9DE1105-BC7A-4753-9181-E7DA03727E54}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal -- cgit v1.2.3-101-g0448