Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef GL_ES
- precision highp float;
- #endif
- uniform float time;
- uniform vec2 resolution;
- float function( float x ) {
- return sin(x*x*x)*sin(x);
- // return sin(x*x*x)*sin(x) + 0.1*sin(x*x);
- // return sin(x);
- }
- float superEval( vec2 uv ) {
- const int samples = 255; //note: amd-bug: doesn't work below 255 iterations (probably because it doesn't unroll?)
- float max_jit = 0.05;
- float stepsize = max_jit / float(samples);
- vec2 jitter = vec2(stepsize) * vec2( resolution.x / resolution.y, 1.0 );
- float count = 0.0;
- vec2 initial_offset = -vec2(samples)*0.5*jitter.xy;
- uv = uv + initial_offset;
- for ( int ii = 0; ii<samples; ii++ ) {
- float i = float(ii);
- float fx = function( uv.x + i*jitter.x );
- for ( int jj = 0; jj<samples; jj++ ) {
- float j = float(jj);
- float diff = fx - float(uv.y + j*jitter.y);
- count = count + step(0.0, diff) * 2.0 - 1.0;
- }
- }
- return 1.0 - abs( count ) / float(samples*samples);
- }
- float discreteEval( vec2 uv ) {
- const float threshold = 0.015;
- float x = uv.x;
- float fx = function( x );
- float dist = abs( uv.y - fx );
- float hit = step( dist, threshold );
- return hit;
- }
- float stochDistEval( vec2 uv ) {
- const int samples = 255;
- const float fsamples = float(samples);
- vec2 maxdist = vec2( 0.075, 0.075 );
- vec2 halfmaxdist = 0.5 * maxdist;
- float stepsize = maxdist.x / fsamples;
- float initial_offset_x = -0.5*fsamples * stepsize;
- uv.x += initial_offset_x;
- float hit = 0.0;
- for( int i=0; i<samples; ++i ) {
- float x = uv.x + stepsize * float(i);
- float y = uv.y;
- float fx = function( x );
- float dist = ( y - fx );
- float vt = clamp( dist / halfmaxdist.y -1.0, -1.0, 1.0 );
- hit += vt;
- }
- return 1.0 - abs(hit) / fsamples;
- }
- void main(void)
- {
- vec2 uv_norm = gl_FragCoord.xy / resolution.xy;
- vec4 dim = vec4( -2.0, 12.0, -3.0, 3.0 );
- uv_norm = (uv_norm ) * ( dim.yw - dim.xz ) + dim.xz;
- float hitDiscr = discreteEval( uv_norm + vec2(0,2) );
- float hitStoch = superEval( uv_norm - vec2(0,2) );
- float hitDistStoch = stochDistEval( uv_norm - vec2(0,0) );
- gl_FragColor = vec4( hitDistStoch, hitStoch, hitDiscr, 1.0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement