Last active
August 7, 2025 03:55
-
-
Save pissang/fc5688ce9a544947e0cea060efec610f to your computer and use it in GitHub Desktop.
Shader Code from Edge-Avoiding À-Trous Wavelet Transform for fast Global Illumination Filtering https://github.com/LWJGL/lwjgl3-demos/blob/master/res/org/lwjgl/demo/opengl/raytracing/tutorial8/atrous.fs.glsl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Copyright LWJGL. All rights reserved. | |
| * License terms: https://www.lwjgl.org/license | |
| */ | |
| /** | |
| * This is a 1:1 implementation/copy of the GLSL algorithm shown at the | |
| * end of the 2010 paper "Edge-Avoiding À-Trous Wavelet Transform for | |
| * fast Global Illumination Filtering" | |
| * | |
| * https://jo.dreggn.org/home/2010_atrous.pdf | |
| */ | |
| #version 330 core | |
| uniform sampler2D colorMap; | |
| uniform sampler2D normalMap; | |
| uniform sampler2D depthMap; | |
| uniform float c_phi; | |
| uniform float n_phi; | |
| uniform float p_phi; | |
| uniform int stepwidth; | |
| #define KERNEL_SIZE 9 | |
| uniform float kernel[KERNEL_SIZE]; | |
| uniform ivec2 offset[KERNEL_SIZE]; | |
| in vec2 texcoord; | |
| out vec4 color; | |
| void main(void) { | |
| vec3 sum = vec3(0.0); | |
| ivec2 tx = ivec2(texcoord); | |
| vec4 cval = texelFetch(colorMap, tx, 0); | |
| float sampleFrame = cval.a; | |
| float sf2 = sampleFrame*sampleFrame; | |
| vec3 nval = texelFetch(normalMap, tx, 0).xyz; | |
| float pval = texelFetch(depthMap, tx, 0).r; | |
| if (isnan(pval)) { | |
| color = cval; | |
| return; | |
| } | |
| float cum_w = 0.0; | |
| for (int i = 0; i < KERNEL_SIZE; i++) { | |
| ivec2 uv = tx + offset[i] * stepwidth; | |
| float ptmp = texelFetch(depthMap, uv, 0).r; | |
| if (isnan(ptmp)) | |
| continue; | |
| vec3 ntmp = texelFetch(normalMap, uv, 0).xyz; | |
| float n_w = dot(nval, ntmp); | |
| if (n_w < 1E-3) | |
| continue; | |
| vec4 ctmp = texelFetch(colorMap, uv, 0); | |
| vec3 t = cval.rgb - ctmp.rgb; | |
| float c_w = max(min(1.0 - dot(t, t) / c_phi * sf2, 1.0), 0.0); | |
| float pt = abs(pval - ptmp); | |
| float p_w = max(min(1.0 - pt/p_phi, 1.0), 0.0); | |
| float weight = c_w * p_w * n_w * kernel[i]; | |
| sum += ctmp.rgb * weight; | |
| cum_w += weight; | |
| } | |
| color = vec4(sum / cum_w, sampleFrame); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/LWJGL/lwjgl3-demos/blob/master/res/org/lwjgl/demo/opengl/raytracing/tutorial8/atrous.fs.glsl 这个链接里说是1:1复制实现原论文。但是感觉这个似乎跟原论文有些差别诶,像底下权重计算部分。另外链接里赋值几个phi的循环中第一次循环里就有出现除0问题了?此外跟原论文里面phi的叠加计算也不同,c_hpi的结果在第N次应该是-2的N次方分之一倍初始c_phi值才对?kernel按照论文应该要遵循B3 spine,但是链接中的看起来也不是?不知道是我理解错了还是有其他原因呢。