tiling a texture for a glsl shader

edited March 2016 in GLSL / Shaders

I'm trying to port this shader from shadertoy to processing (https://www.shadertoy.com/view/ldlXRS). It works but in shadertoy it uses a noisemap in ichannel0 that is tiled. I can pass it a noisemap in processing but its not tiled. Anyone know how to solve this?

sketch code:

PShader myShader;
PImage  myImage;

void setup() {
  size(640, 360, P2D);
  noStroke();
  myImage = loadImage("noise512.png");
  myShader = loadShader("noise_anim.glsl");
  myShader.set("resolution", float(width), float(height));

}

void draw() {
  background(0);
  myShader.set("time", millis() / 1000.0);

  shader(myShader);
  image( myImage, 0, 0, width, height ); // when using image or text maps

}

noise_anim.glsl code:

#ifdef GL_ES
precision highp float;
#endif

#define PROCESSING_TEXTURE_SHADER

uniform float time;
uniform vec2 resolution;
uniform vec2 mouse;
uniform sampler2D texture;


// Layer between Processing and Shadertoy uniforms
vec3 iResolution = vec3(resolution,0.0);
float iGlobalTime = time;
vec4 iMouse = vec4(mouse,0.0,0.0); // zw would normally be the click status

//Noise animation - Electric
//by nimitz (stormoid.com) (twitter: @stormoid)

//The domain is displaced by two fbm calls one for each axis.
//Turbulent fbm (aka ridged) is used for better effect.

#define time iGlobalTime*0.15
#define tau 6.2831853

mat2 makem2(in float theta){
    float c = cos(theta);
    float s = sin(theta);
    return mat2(c,-s,s,c);
    }
float noise( in vec2 x ){
    return texture2D(texture, x*.01).x;
    }

float fbm(in vec2 p)
{   
    float z=2.;
    float rz = 0.;
    vec2 bp = p;
    for (float i= 1.;i < 6.;i++)
    {
        rz+= abs((noise(p)-0.5)*2.)/z;
        z = z*2.;
        p = p*2.;
    }
    return rz;
}

float dualfbm(in vec2 p)
{
    //get two rotated fbm calls and displace the domain
    vec2 p2 = p*.7;
    vec2 basis = vec2(fbm(p2-time*1.6),fbm(p2+time*1.7));
    basis = (basis-.5)*.2;
    p += basis;

    //coloring
    return fbm(p*makem2(time*0.2));
}

float circ(vec2 p) 
{
    float r = length(p);
    //r = log(sqrt(r));
    r = 0.5*log(r);
    return abs(mod(r*4.,tau)-3.14)*3.+.2;

}

void main()
{
    //setup system
    vec2 p = gl_FragCoord.xy / iResolution.xy-0.5;
    p.x *= iResolution.x/iResolution.y;
    p*=4.;

    float rz = dualfbm(p);

    //rings
    p /= exp(mod(time*10.,3.14159));
    rz *= pow(abs((0.1-circ(p))),.9);

    //final color
    vec3 col = vec3(.2,0.1,0.4)/rz;
    col=pow(abs(col),vec3(.99));
    gl_FragColor = vec4(col,1.);
}

Answers

Sign In or Register to comment.