Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Elabajaba committed Feb 12, 2023
1 parent ac17e29 commit 7a44693
Showing 1 changed file with 8 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// From https://github.com/CeeJayDK/SweetFX/blob/master/Shaders/CAS.fx
//
// LICENSE
// =======
// Copyright (c) 2017-2019 Advanced Micro Devices, Inc. All rights reserved.
Expand All @@ -16,40 +14,9 @@
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE

//Initial port to ReShade: SLSNe https://gist.github.com/SLSNe/bbaf2d77db0b2a2a0755df581b3cf00c
//Optimizations by Marty McFly:
// vectorized math, even with scalar gcn hardware this should work
// out the same, order of operations has not changed
// For some reason, it went from 64 to 48 instructions, a lot of MOV gone
// Also modified the way the final window is calculated
//
// reordered min() and max() operations, from 11 down to 9 registers
//
// restructured final weighting, 49 -> 48 instructions
//
// delayed RCP to replace SQRT with RSQRT
//
// removed the saturate() from the control var as it is clamped
// by UI manager already, 48 -> 47 instructions
//
// replaced tex2D with tex2Doffset intrinsic (address offset by immediate integer)
// 47 -> 43 instructions
// 9 -> 8 registers
//Further modified by OopyDoopy and Lord of Lunacy:
// Changed wording in the UI for the existing variable and added a new variable and relevant code to adjust sharpening strength.
//Fix by Lord of Lunacy:
// Made the shader use a linear colorspace rather than sRGB, as recommended by the original AMD documentation from FidelityFX.
//Modified by CeeJay.dk:
// Included a label and tooltip description. I followed AMDs official naming guidelines for FidelityFX.
//
// Used gather trick to reduce the number of texture operations by one (9 -> 8). It's now 42 -> 51 instructions but still faster
// because of the texture operation that was optimized away.
//Fix by CeeJay.dk
// Fixed precision issues with the gather at super high resolutions
// Also tried to refactor the samples so more work can be done while they are being sampled, but it's not so easy and the gains
// I'm seeing are so small they might be statistical noise. So it MIGHT be faster - no promises.
//Ported to Bevy wgsl by Elabajaba
//Ported to Bevy wgsl from https://github.com/CeeJayDK/SweetFX/blob/master/Shaders/CAS.fx by Elabajaba

#import bevy_core_pipeline::fullscreen_vertex_shader

Expand Down Expand Up @@ -85,9 +52,9 @@ fn fragment(in: FullscreenVertexOutput) -> @location(0) vec4<f32> {
let i = textureSample(screenTexture, samp, in.uv, vec2<i32>(1, 1)).rgb;

// Soft min and max.
// a b c b
// d e f * 0.5 + d e f * 0.5
// g h i h
// a b c b
// d e f * 0.5 + d e f * 0.5
// g h i h
// These are 2.0x bigger (factored out the extra multiply).
var mnRGB = min(min(min(d, e.rgb), min(f, b)), h);
let mnRGB2 = min(mnRGB, min(min(a, c), min(g, i)));
Expand All @@ -107,13 +74,13 @@ fn fragment(in: FullscreenVertexOutput) -> @location(0) vec4<f32> {
let wRGB = -1.0 / (ampRGB * peak);
let rcpWeightRGB = 1.0 / (4.0 * wRGB + 1.0);

// 0 w 0
// Filter shape: w 1 w
// 0 w 0
// 0 w 0
// Filter shape: w 1 w
// 0 w 0
let window = (b + d) + (f + h);
let outColor = saturate((window * wRGB + e.rgb) * rcpWeightRGB);

let out = mix(e.rgb, outColor, uniforms.sharpening_intensity);

return vec4<f32>(out, e.w);
}
}

0 comments on commit 7a44693

Please sign in to comment.