Skip to content
Snippets Groups Projects
Commit c733ee2f authored by dlyr's avatar dlyr
Browse files

update lic image processing shader

parent 332a0f4e
Branches
No related tags found
No related merge requests found
layout (location = 0) out vec4 out_color; layout( location = 0 ) out vec4 out_color;
uniform sampler2D depth_sampler; uniform sampler2D depth_sampler;
uniform sampler2D image_sampler; uniform sampler2D image_sampler;
in vec2 varTexcoord; in vec2 varTexcoord;
vec2 imgSize = vec2( textureSize( image_sampler, 0 ) );
const int halfsize = 40;
const float dirFactor = 1.;
const float randCeil = 0.3;
// replace the nois texture : TODO verify the properties of the generated noise float rand( vec2 co ) {
float whiteNoise(in vec2 at, in vec2 scale) { return fract( sin( dot( co.xy, vec2( 12.9898, 78.233 ) ) ) * 43758.5453 );
return (noise1 (at * scale) + 0.5) * 0.5;
} }
float whiteNoise( in vec2 at ) {
return ( rand( floor( at * randCeil ) / imgSize ) );
}
// desc : texture that contains direction to convolve
// invertdir invert (i.e. perpendicular) direction
vec4 lic( in sampler2D desc, in bool invertdir ) {
/*
// LIC function to be adapted ...
//desc : texture de direction (vecteurs)
// invertdir pour faire "perpendiculaire" a desc,
// noise une texture de bruit "poivre et sel"
// sw, sh : screensize
vec4 lic(in sampler2D desc,in bool invertdir) {
const int halfsize = 10;
vec2 coord; vec2 coord;
vec2 dir = texture2D(desc,gl_TexCoord[0].st).xy;
//vec2 dir = texelFetch(desc,ivec2(gl_TexCoord[0].st*1.0/vec2(sw,sh)),0).xy; vec2 dir = texelFetch( desc, ivec2( gl_FragCoord.xy ), 0 ).xy;
if(invertdir) if ( invertdir ) dir = vec2( dir.y, -dir.x );
dir = vec2(dir.y,-dir.x);
vec4 res = texture2D(noise,gl_TexCoord[0].st); vec4 res = vec4( whiteNoise( gl_FragCoord.xy ) );
vec2 currentdir; vec2 currentdir;
vec2 tmpdir; vec2 tmpdir;
coord = gl_TexCoord[0].st; coord = gl_FragCoord.xy;
currentdir = dir; currentdir = dir;
for(int i=1;i<=halfsize;i++) { for ( int i = 1; i <= halfsize; i++ )
coord = coord+vec2(currentdir.x*sw,currentdir.y*sh); {
res += texture2D(noise,coord); coord = coord + dirFactor * vec2( currentdir.x, currentdir.y );
tmpdir = texture2D(desc,coord).xy; res += vec4( whiteNoise( coord ) );
//tmpdir = texelFetch(desc,ivec2(coord*1.0/vec2(sw,sh)),0).xy; tmpdir = texelFetch( desc, ivec2( coord ), 0 ).xy;
if(invertdir) if ( invertdir ) tmpdir = vec2( tmpdir.y, -tmpdir.x );
tmpdir = vec2(tmpdir.y,-tmpdir.x);
currentdir = tmpdir;
}
coord = gl_TexCoord[0].st;
currentdir = dir;
for(int i=1;i<=halfsize;i++) {
coord = coord-vec2(currentdir.x*sw,currentdir.y*sh);
res += texture2D(noise,coord);
tmpdir = texture2D(desc,coord).xy;
//tmpdir = texelFetch(desc,ivec2(coord*1.0/vec2(sw,sh)),0).xy;
if(invertdir)
tmpdir = vec2(tmpdir.y,-tmpdir.x);
currentdir = tmpdir; currentdir = tmpdir;
} }
res = res/(2.0f*float(halfsize)+1.0f);
return vec4(res.x);
}
*/
vec4 lic(in sampler2D desc,in bool invertdir, in vec2 imgSize) {
const int halfsize = 10;
vec2 coord = varTexcoord;
vec2 dir = texture(desc,coord).xy;
if ( length(dir) <0.0001 )
return vec4(0);
if(invertdir)
dir = vec2(dir.y,-dir.x);
float res = whiteNoise( dir, imgSize);
vec2 currentdir = dir; coord = gl_FragCoord.xy;
for(int i=1;i<=halfsize;i++) {
coord = coord + currentdir;//*halfsize;
currentdir = texture(desc,coord).xy;
res += whiteNoise( currentdir, imgSize);
if(invertdir)
currentdir = vec2(currentdir.y,-currentdir.x);
}
coord = varTexcoord;
currentdir = dir; currentdir = dir;
for(int i=1;i<=halfsize;i++) { for ( int i = 1; i <= halfsize; i++ )
coord = coord - currentdir;//*halfsize; {
currentdir = texture(desc,coord).xy; coord = coord - dirFactor * vec2( currentdir.x, currentdir.y );
res += whiteNoise( currentdir, imgSize); res += vec4( whiteNoise( coord ) );
if(invertdir) tmpdir = texelFetch( desc, ivec2( coord ), 0 ).xy;
currentdir = vec2(currentdir.y,-currentdir.x); if ( invertdir ) tmpdir = vec2( tmpdir.y, -tmpdir.x );
currentdir = tmpdir;
} }
res = res/(2.0f*float(halfsize)+1.0f); res = res / ( 2.0f * float( halfsize ) + 1.0f );
return vec4(vec3(res), 0); return smoothstep( 0.1, 0.9, res );
} }
void main() { void main() {
vec2 imgSize = vec2(textureSize(image_sampler, 0));
/* /*
// 4x4 filtering for test // 4x4 filtering for test
const int half_width = 2; const int half_width = 2;
vec2 texelSize = 1.0 / vec2(imgSize); vec2 texelSize = 1.0 / vec2(textureSize(image_sampler, 0));
vec3 result = vec3(0.0); vec3 result = vec3(0.0);
for (int x = -half_width; x < half_width; ++x) for (int x = -half_width; x < half_width; ++x)
{ {
...@@ -106,10 +69,6 @@ void main() { ...@@ -106,10 +69,6 @@ void main() {
} }
out_color = vec4(result / (4 * half_width * half_width), 1); out_color = vec4(result / (4 * half_width * half_width), 1);
*/ */
/*
out_color = vec4( vec3( whiteNoise( varTexcoord, imgSize) ), 1);
*/
out_color = lic(image_sampler, false, imgSize);
out_color = lic( image_sampler, true );
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment