0

Could someone help me with creating a fragment shader producing a tiled fractal noise. currently I'm using random noise texture and sample it with diferent resolution and sum the result. What I have to add to make it tileable.

uniform float time; 
uniform sampler2D u_texture; 
varying vec2 v_texCoords; 

float noisep(in vec2 p, in float scale) { 
    return texture2D(u_texture, p / scale + vec2(0.0, time * 0.01)) / 4.0; 
} 

void main(void) { 
    vec2 uv = v_texCoords * vec2(0.7, 1.0); 
    float scale = 1.0; 
    float col = 0.0; 
    for(int i = 0; i < 6; i++) { 
        col += noisep(uv, scale); 
        scale += 1.0; 
    } 
    gl_FragColor = vec4(col, col, col, 1); 
}
genpfault
  • 51,148
  • 11
  • 85
  • 139
  • You should add some code and images of your problem for a better understanding. At the moment it's not very clear how we can help you. – Gnietschow Feb 25 '15 at 19:59

1 Answers1

0

I think the main problem why your result isn't tileable is that the x-direction is clipped (or I don't understand the reason for the first line of your main function) and your texturelookup only moves the origin not sample the texture with another resolution.

uniform float time; 
uniform sampler2D u_texture; 
varying vec2 v_texCoords; 

float noisep(in vec2 p, in float scale) { 
    // the shift has to scaled as well 
    return texture2D(u_texture, (p + vec2(0.0, time * 0.01)) / scale) / 4.0; 
} 

void main(void) { 
    vec2 uv = v_texCoords; //why did you shrink the x-direction?
    float scale = 1.0; 
    float col = 0.0; 
    for(int i = 0; i < 6; i++) { 
        col += noisep(uv, scale); 
        scale += 1.0; 
    } 
    gl_FragColor = vec4(col, col, col, 1); 
}
Gnietschow
  • 3,070
  • 1
  • 18
  • 28
  • Yes, it was not even planned to be tillable with this code. My main question is how to make it tillable. I suppose I have to add something more like sin, cos functions when calculate the sampling. I have no idea this is only my assumptions. The first line I put in order to scale a bit more the x direction so it now looks more like ocean surface (this is why I need this noise). Even if I remove it the result will not be tillable. – Ignat Tafradjiiski Mar 04 '15 at 10:16