From 7a44693d9e3a584ea8ef9452f7de53e4b1fb7df9 Mon Sep 17 00:00:00 2001 From: Elabajaba Date: Sun, 12 Feb 2023 16:16:08 -0500 Subject: [PATCH] fix comments --- .../contrast_adaptive_sharpening.wgsl | 49 +++---------------- 1 file changed, 8 insertions(+), 41 deletions(-) diff --git a/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/contrast_adaptive_sharpening.wgsl b/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/contrast_adaptive_sharpening.wgsl index 15425c49e122d6..449c4e686f7afb 100644 --- a/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/contrast_adaptive_sharpening.wgsl +++ b/crates/bevy_core_pipeline/src/contrast_adaptive_sharpening/contrast_adaptive_sharpening.wgsl @@ -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. @@ -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 @@ -85,9 +52,9 @@ fn fragment(in: FullscreenVertexOutput) -> @location(0) vec4 { let i = textureSample(screenTexture, samp, in.uv, vec2(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))); @@ -107,13 +74,13 @@ fn fragment(in: FullscreenVertexOutput) -> @location(0) vec4 { 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(out, e.w); -} \ No newline at end of file +}