Monday, January 12, 2026
spot_img

What’s the error in my model of OpenSimplex2S?


I used to make use of a Perlin perform to create 3D noise. I am making an attempt to modify to OpenSimplex2S to be a bit extra environment friendly (higher efficiency and noise high quality in 3D house), however I did not simply copy and paste. I attempted to review how the algorithm labored and create my very own model.

It has been 5 days and I have never gotten wherever, and I’ve a ton of code variations that I am not likely positive what to do with…

That is the OpenSimplex code I wrote:

    float OpenSimplex(vec3 p){
        // Transformation to Tetrahedral House
        float s = (p.x + p.y + p.z)/3.0;
        vec3 t = p + vec3(s);
        vec3 i = ground(t);
        float fx = t.x - i.x;
        float fy = t.y - i.y;
        float fz = t.z - i.z;
        
        ivec3 cell = ivec3(i);
        
        ivec3 p1 = cell+ivec3(0);
        ivec3 i2;
        ivec3 i3;
        if(fx >= fy){
            if(fy >= fz){
                i2 = ivec3(1,0,0);
                i3 = ivec3(1,1,0);
            }else if(fx >= fz){
                i2 = ivec3(1,0,0);
                i3 = ivec3(1,0,1);
            }else{
                i2 = ivec3(0,0,1);
                i3 = ivec3(1,0,1);
            }
        }else{
            if(fy < fz){
                i2 = ivec3(0,0,1);
                i3 = ivec3(0,1,1);
            }else if(fx < fz){
                i2 = ivec3(0,1,0);
                i3 = ivec3(0,1,1);
            }else{
                i2 = ivec3(0,1,0);
                i3 = ivec3(1,1,0);
            }
        }
        ivec3 p2 = cell + i2;
        ivec3 p3 = cell + i3;
        ivec3 p4 = cell+ivec3(1);
        
        // Vectors of every Level (LUT already normalized).
        vec3 d1 = pontos[idx(p1)];
        vec3 d2 = pontos[idx(p2)];
        vec3 d3 = pontos[idx(p3)];
        vec3 d4 = pontos[idx(p4)];
        
        // Vectors of the Level in Tetrahedral House to the factors.
        vec3 v1 = t - p1;
        vec3 v2 = t - p2;
        vec3 v3 = t - p3;
        vec3 v4 = t - p4;
        
        // Attenuation calculation for every level.
        float limite = 0.6;
        float f1 = dot(v1,v1);
        f1 = f1 >= limite ? 0.0 : pow(limite - f1,4);
        float f2 = dot(v2,v2);
        f2 = f2 >= limite ? 0.0 : pow(limite - f2,4);
        float f3 = dot(v3,v3);
        f3 = f3 >= limite ? 0.0 : pow(limite - f3,4);
        float f4 = dot(v4,v4);
        f4 = f4 >= limite ? 0.0 : pow(limite - f4,4);
        
        // Ultimate Calculation
        float last = 0.0;
        last += f1*dot(v1,d1);
        last += f2*dot(v2,d2);
        last += f3*dot(v3,d3);
        last += f4*dot(v4,d4);
        
        return last;
    }

These are the features I used to arrange the LUT:

    int wrap(int x, int max){
        return ((xpercentmax)+max)%max;
    }

    int idx(ivec3 c){
        const int gs = 27;
        ivec3 cq = ivec3(wrap(c.x,gs),wrap(c.y,gs),wrap(c.z,gs));
        return cq.x+gs*cq.y+gs*gs*cq.z;
    }

The issue is that after I run it utilizing a easy Ray Marcher to check the noise, I bounce on to a sure distance and that is the outcome (there are a number of photos however it’s the identical outcome):

What’s the error in my model of OpenSimplex2S?

enter image description here

enter image description here

You may see the tetrahedrons; this was the perfect model I might obtain to verify if the algorithm was operating, however the result’s so unusual that I am simply questioning what’s taking place… Can anybody with expertise in creating 3D noise inform me what’s improper with my code? I assumed the error may be within the calculation that selects the vectors connecting the purpose in 3D house with the tetrahedrons, however I’ve messed with that a lot that now I don’t know what I am doing.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest Articles