Skip to content
Snippets Groups Projects
Commit 353a0886 authored by Mathias Paulin's avatar Mathias Paulin :speech_balloon:
Browse files

Other noise proposal for LIC

parent c733ee2f
Branches
No related tags found
No related merge requests found
Pipeline #198 passed
...@@ -6,49 +6,69 @@ in vec2 varTexcoord; ...@@ -6,49 +6,69 @@ in vec2 varTexcoord;
vec2 imgSize = vec2( textureSize( image_sampler, 0 ) ); vec2 imgSize = vec2( textureSize( image_sampler, 0 ) );
const int halfsize = 40; const int halfsize = 40;
const float dirFactor = 1.; const float dirFactor = 0.5;
const float randCeil = 0.3; const float randCeil = 0.3;
#if 1
float rand( vec2 co ) { float rand( vec2 co ) {
return fract( sin( dot( co.xy, vec2( 12.9898, 78.233 ) ) ) * 43758.5453 ); return fract( sin( dot( co.xy, vec2( 12.9898, 78.233 ) ) ) * 43758.5453 );
} }
float whiteNoise( in vec2 at ) { float whiteNoise( in vec2 at ) {
return ( rand( floor( at * randCeil ) / imgSize ) ); return ( rand( floor( at * randCeil ) / imgSize ) );
} }
#else
// noise (hash) functions : taken from https://www.shadertoy.com/view/4djSRW
float hash12(vec2 p)
{
vec3 p3 = fract(vec3(p.xyx) * .1031);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
#define ITERATIONS 1
float whiteNoise( in vec2 at ) {
float a = 0.0;
for (int t = 0; t < ITERATIONS; t++) {
float v = float(t+1)*.152;
vec2 pos = (at * v + 1517.01);
a += hash12(pos);
}
return a/float(ITERATIONS);
}
#undef ITERATIONS
#endif
// desc : texture that contains direction to convolve // desc : texture that contains direction to convolve
// invertdir invert (i.e. perpendicular) direction // invertdir invert (i.e. perpendicular) direction
vec4 lic( in sampler2D desc, in bool invertdir ) { vec4 lic( in sampler2D desc, in bool invertdir ) {
vec2 coord;
vec2 dir = texelFetch( desc, ivec2( gl_FragCoord.xy ), 0 ).xy; vec2 dir = texelFetch( desc, ivec2( gl_FragCoord.xy ), 0 ).xy;
if (length(dir) == 0) {return vec4 (0);}
if ( invertdir ) dir = vec2( dir.y, -dir.x ); if ( invertdir ) dir = vec2( dir.y, -dir.x );
vec4 res = vec4( whiteNoise( gl_FragCoord.xy ) ); vec4 res = vec4( whiteNoise( gl_FragCoord.xy ) );
vec2 currentdir; vec2 currentdir = dir;
vec2 tmpdir; vec2 coord = gl_FragCoord.xy;
coord = gl_FragCoord.xy;
currentdir = dir; for ( int i = 0; i < halfsize; i++ )
for ( int i = 1; i <= halfsize; i++ )
{ {
coord = coord + dirFactor * vec2( currentdir.x, currentdir.y ); coord = coord + dirFactor * currentdir;
res += vec4( whiteNoise( coord ) ); res += vec4( whiteNoise( coord ) );
tmpdir = texelFetch( desc, ivec2( coord ), 0 ).xy; currentdir = texelFetch( desc, ivec2( coord ), 0 ).xy;
if ( invertdir ) tmpdir = vec2( tmpdir.y, -tmpdir.x ); if ( invertdir ) currentdir = vec2( currentdir.y, -currentdir.x );
currentdir = tmpdir;
} }
coord = gl_FragCoord.xy; coord = gl_FragCoord.xy;
currentdir = dir; currentdir = dir;
for ( int i = 1; i <= halfsize; i++ ) for ( int i = 0; i < halfsize; i++ )
{ {
coord = coord - dirFactor * vec2( currentdir.x, currentdir.y ); coord = coord - dirFactor * currentdir;
res += vec4( whiteNoise( coord ) ); res += vec4( whiteNoise( coord ) );
tmpdir = texelFetch( desc, ivec2( coord ), 0 ).xy; currentdir = texelFetch( desc, ivec2( coord ), 0 ).xy;
if ( invertdir ) tmpdir = vec2( tmpdir.y, -tmpdir.x ); if ( invertdir ) currentdir = vec2( currentdir.y, -currentdir.x );
currentdir = tmpdir;
} }
res = res / ( 2.0f * float( halfsize ) + 1.0f ); res = res / ( 2.0f * float( halfsize ) + 1.0f );
return smoothstep( 0.1, 0.9, res ); return smoothstep( 0.1, 0.9, res );
} }
...@@ -70,5 +90,5 @@ void main() { ...@@ -70,5 +90,5 @@ void main() {
out_color = vec4(result / (4 * half_width * half_width), 1); out_color = vec4(result / (4 * half_width * half_width), 1);
*/ */
out_color = lic( image_sampler, true ); out_color = lic( image_sampler, false );
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment