平铺的分形噪音

时间:2015-02-21 08:29:27

标签: opengl 3d directx glsl hlsl

有人可以帮我创建一个产生平铺分形噪声的片段着色器。目前我正在使用随机噪声纹理并以不同的分辨率对其进行采样并对结果求和。我必须添加什么才能使它成为可以制作的。

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); 
}

1 个答案:

答案 0 :(得分:0)

我认为你的结果不能平铺的主要问题是x方向被修剪(或者我不理解你的主函数的第一行的原因)你的texturelookup只移动原点而不是样本纹理与另一种分辨率。

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); 
}