Last active
September 23, 2020 10:04
-
-
Save VirtuosoChris/eff3963696019bea7c58708340aad0ab to your computer and use it in GitHub Desktop.
asdasdvbafasdasd
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
#version 440 core | |
precision highp float; | |
#define LOCAL_BLOCKSIZE 32 | |
layout(local_size_x=LOCAL_BLOCKSIZE, local_size_y=LOCAL_BLOCKSIZE, local_size_z=1) in; | |
layout (binding = 0, rgba32f) uniform image2D imgIn; | |
layout (binding = 1, rgba32f) uniform image2D imgOut; | |
uniform int iterations; | |
#define FILTER_CONE7 {0.1508,0.3015,0.4523,0.6030,0.4523,0.3015,0.1508} | |
const float[] filterarr=FILTER_CONE7; | |
//this could be vec4x2 or something if you need more than 4 values | |
#define interp_value_t vec4 | |
shared interp_value_t blockcache[2][LOCAL_BLOCKSIZE][LOCAL_BLOCKSIZE]; | |
interp_value_t hole_fill(interp_value_t value,bool is_hole,int iterations) | |
{ | |
//interp_value_t cachedval=value; | |
uvec2 lid = gl_LocalInvocationID.xy; | |
if(is_hole) | |
{ | |
// cachedval= | |
value = interp_value_t(0.5); | |
} | |
blockcache[0][lid.x][lid.y]=value; | |
blockcache[1][lid.x][lid.y]=value; | |
if(!is_hole) return value; | |
//#if 0 | |
for(int iter=0; iter < iterations;iter++) | |
{ | |
//unknown if seperable implementation with 2 barriers is faster than 2d implementation with 1 barrier. | |
//TODO test this. | |
interp_value_t val= interp_value_t(0.0); | |
for(int u=0;u<filterarr.length();u++) | |
{ | |
uint loc=lid.x+u-filterarr.length()/2; | |
if(!(loc < 0 || loc >= LOCAL_BLOCKSIZE)) | |
{ | |
val+=filterarr[u]*blockcache[0][loc][lid.y]; | |
} | |
} | |
blockcache[1][lid.x][lid.y]=val; | |
barrier(); //docs say this does a shared memory barrier. But this might need to be groupMemoryBarrier() or memoryBarrierShared() | |
val=interp_value_t(0.0); | |
for(int v=0;v<filterarr.length();v++) | |
{ | |
uint loc=lid.y+v-filterarr.length()/2; | |
if(!(loc < 0 || loc >= LOCAL_BLOCKSIZE)) | |
{ | |
val+=filterarr[v]*blockcache[1][lid.x][loc]; | |
} | |
} | |
blockcache[0][lid.x][lid.y] = val; | |
barrier(); | |
} | |
//#endif | |
return blockcache[0][lid.x][lid.y]; | |
} | |
void main() | |
{ | |
#if 0 | |
vec4 texel; | |
ivec2 p = ivec2(gl_GlobalInvocationID.xy); | |
texel = imageLoad(imgIn, p); | |
texel = vec4(1.0) - texel; | |
imageStore(imgOut, p, texel); | |
#else | |
vec4 texel; | |
ivec2 p = ivec2(gl_GlobalInvocationID.xy); | |
texel = imageLoad(imgIn, p); | |
bool isHole = (texel.xyz == vec3(1.0,1.0,0.0)); | |
#if 0 | |
if (isHole) | |
{ | |
imageStore(imgOut, p, vec4(1.0, 0.0, 0.0, 1.0)); | |
} | |
else | |
{ | |
imageStore(imgOut, p, vec4(0.0)); | |
} | |
#endif | |
// invert the output pixel colors for debug reasons for now | |
imageStore(imgOut, p, hole_fill(texel, isHole, iterations)); | |
#endif | |
} | |
)STRING"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment