Created
December 8, 2018 23:36
-
-
Save edom18/b0276cbcc2a0e77f8f9d857d36285622 to your computer and use it in GitHub Desktop.
[WebGL] レイマーチングでアンチエイリアス(FXAA)してみる ref: https://qiita.com/edo_m18/items/c211fea23b4747a8da3c
This file contains 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
maxLuma = max(nw,ne,sw,se) | |
contrast = max(nw,ne,sw,se,m) - min(nw,ne,sw,se,m) | |
if(contrast >= max(minThreshold, maxLuma * threshold)) |
This file contains 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
dir.x = -((NW+NE)-(SW+SE)) | |
dir.y = ((NW+SW)-(NE+SE)) | |
dir.xy = normalize(dir.xy) * scale |
This file contains 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
#if __VERSION_ >= 130 | |
#define OffsetVec(a, b) ivec2(a, b) | |
#define FxaaTexOff(t, p, o, r) textureOffset(t, p, o) | |
#elif defined(GL_EXT_gpu_shader4) | |
#define OffsetVec(a, b) ivec2(a, b) | |
#define FxaaTexOff(t, p, o, r) texture2DLodOffset(t, p, 0.0, o) | |
#else | |
#define OffsetVec(a, b) vec2(a, b) | |
#define FxaaTexOff(t, p, o, r) texture2D(t, p + o * r) | |
#endif |
This file contains 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
#define FxaaTexOff(t, p, o, r) texture2D(t, p + o * r) |
This file contains 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
vec3 luma = vec3(0.299, 0.587, 0.114); | |
float lumaNW = dot(rgbNW, luma); |
This file contains 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
vec3 rgbA = (1.0/2.0) * ( | |
FxaaTexLod0(tex, posPos.xy + dir * (1.0/3.0 - 0.5)).xyz + | |
FxaaTexLod0(tex, posPos.xy + dir * (2.0/3.0 - 0.5)).xyz); | |
vec3 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * ( | |
FxaaTexLod0(tex, posPos.xy + dir * (0.0/3.0 - 0.5)).xyz + | |
FxaaTexLod0(tex, posPos.xy + dir * (3.0/3.0 - 0.5)).xyz); | |
float lumaB = dot(rgbB, luma); | |
if((lumaB < lumaMin) || (lumaB > lumaMax)) | |
{ | |
return rgbA; | |
} | |
else | |
{ | |
return rgbB; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment