Getting uncertainty values ​​from noise texture?

I am trying to implement Sketchy Drawings . I am involved in a process that requires the use of a noise texture to obtain uncertainties that will provide an offset in the edges map.

Here is an image of my edge map for a torus:

enter image description here

And here is the noise texture that I got using the Perlin function, as suggested:

enter image description here

I saved them as textures in edgeTextureand noiseTextureaccordingly.

Now I'm stuck in a section where you need to compensate for the texture coordinates of the edge map from the uncertainty values ​​obtained from the noise texture. This is an image from a book:

enter image description here

offs = turbulence(s, t); 
offt = turbulence(1 - s, 1 - t);

I ignore the 2x2 matrix for now. Here is my current fragment shader attempt and result:

#version 330

out vec4 vFragColor;

uniform sampler2D edgeTexture;
uniform sampler2D noiseTexture;

smooth in vec2 vTexCoords;

float turbulence(float s, float t) 
{
    float sum = 0;
    float scale = 1;
    float s1 = 1;
    vec2 coords = vec2(s,t);

    for (int i=0; i < 10; i++)
    {
        vec4 noise = texture(noiseTexture, 0.25 * s1 * coords);
        sum += scale * noise.x;
        scale = scale / 2;
        s1 = s1 * 2;
    }

    return sum;
}

void main( void )
{
    float off_s = turbulence(vTexCoords.s, vTexCoords.t);
    float off_t = turbulence(1 - vTexCoords.s, 1 - vTexCoords.t);

    vFragColor = texture(edgeTexture, vTexCoords + vec2(off_s, off_t));
}

enter image description here

, vTexCoords , , . , , , - . , , , , . , .

+4
1

(0,1). -, , , 0. , . , -, , :

vec4 noise = texture(noiseTexture, 0.25 * s1 * coords);

vec4 noise = texture(noiseTexture, 0.25 * s1 * coords) * 2.0 - 1.0;

, . :

vFragColor = texture(edgeTexture, vTexCoords + vec2(off_s, off_t));

vFragColor = texture(edgeTexture, vTexCoords + vec2(off_s, off_t) * off_scale);

off_scale - (, 0,05), .

+1

Source: https://habr.com/ru/post/1533094/


All Articles