Tuesday, November 5, 2024
spot_img

3d – Technology of a Voronoi noise regular map utilizing the analytic by-product methodology


The trickiest bit is making variations of smoothMin and smoothMax that compute analytical derivatives.

I’ve hacked this model collectively primarily based on Inigo Quilez’s article on Clean Minimums for SDFs, although my model might most likely be higher optimized.

It takes the standard parameters a, b, and ok, plus the gradients of a and b, da and db, respectively. These are the vectors of partial derivatives with respect to our x and y sampling coordinates, so da = $ triangledown a = left( frac {partial a} {partial x}, frac {partial a} {partial y} proper)$. We then return the standard clean minimal within the x part of a vector, and its gradient within the xy parts:

vec3 smoothMin(float a, vec2 da, float b, vec2 db, float ok) {
    ok *= 4.0;
    float x = (b - a)/ok;
    float h = (x + 1.0)/2.0;
    float dg = clamp(h, 0.0, 1.0);
    float g = h * dg + step(1, x) * (x - 1.0)/2.0;

    return vec3(combine(db, da, dg), b - ok * g);
}

An analogous technique can be utilized to replace smoothMax:

vec3 smoothMax(float a, vec2 da, float b, vec2 db, float ok) {
    ok *= 4.0;
    float x = (a - b)/ok;
    float h = (x + 1.0)/2.0;
    float dg = clamp(h, 0.0, 1.0);
    float g = h * dg + step(1, x) * (x - 1.0)/2.0;

    return vec3(combine(db, da, dg), b + ok * g);
}

Then we simply must compute these gradient vectors at every step, and carry them by way of all our operations. For every intermediate beneath that is determined by our xy pattern place, I’ve added a d model of the variable that holds its partial derivatives with respect to x and y.

float3 cratersFractal(vec2 st) {
    // Increase peak with gradient vector in xy, and hold peak in z:
    vec3 peak = vec3(0.0, 0.0, 0.5);
    float amplitude = 1.0;

    // The speed that st modifications relative to the unique enter.
    float scaleFactor = 1.0;
    
    for(int i = 0; i 

This returns the unique peak you’d computed within the z part, and the gradient within the xy parts.

You may then compute the conventional like so:

vec3 craters = cratersFractal(st);
float peak = craters.z;

vec3 regular = normalize(vec3(-craters.xy, 1.0)) * 0.5 + 0.5;

You might must scale the craters.xy gradient in that final step to regulate for the relative scale of your texture area to peak displacement.

It is nonetheless early AMs right here, and I’ve solely performed a fast check of the smoothMin / smoothMax code, so I’ve most likely made a math error someplace within the derivation above, however hopefully that provides you a helpful signpost to carry this by way of.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest Articles