Results 1 to 8 of 8

Thread: Curses! Artifacts!

  1. #1
    eye kan kode gud jrandom's Avatar
    Join Date
    Dec 2009
    Location
    Seattle, WA
    Posts
    1,143

    Curses! Artifacts!

    I've verified this isn't a result of my coordinate transforms, so the simplex noise generator itself must be messed up. I'll be darned if I know how.

    *grumble* *grumble*

    Click image for larger version. 

Name:	Simplex Artifacts.jpg 
Views:	230 
Size:	116.6 KB 
ID:	113967

    Click image for larger version. 

Name:	Simplex Artifacts 2.jpg 
Views:	199 
Size:	226.2 KB 
ID:	113968
    Last edited by jrandom; 04-27-2013 at 07:29 PM.

  2. #2
    eye kan kode gud jrandom's Avatar
    Join Date
    Dec 2009
    Location
    Seattle, WA
    Posts
    1,143
    Just crawled over every single line of code in the noise generator. Looks solid. Argh.

  3. #3
    eye kan kode gud jrandom's Avatar
    Join Date
    Dec 2009
    Location
    Seattle, WA
    Posts
    1,143
    If anyone is curious: the code for the noise generator (updated to include the complete fix I finally stumbled across -- see a few posts down).

    I've only been working with the 3D noise generator. While 1D and 2D have been coded, neither have been tested.
    Last edited by jrandom; 04-28-2013 at 12:12 AM.

  4. #4
    eye kan kode gud jrandom's Avatar
    Join Date
    Dec 2009
    Location
    Seattle, WA
    Posts
    1,143
    Interesting... I think the artifacts are limited to areas where at least one of the texture coordinates is negative...

    (don't mind me, I'm pretty much just talking to myself at this point)

  5. #5
    eye kan kode gud jrandom's Avatar
    Join Date
    Dec 2009
    Location
    Seattle, WA
    Posts
    1,143
    SOLVED! And it's a bug in the reference implementation. Not my fault! Whee!

    Once I knew that negative coordinates were involved in the problem, a google search turned up the answer -- There's a section of code that gets array indexes:

    Code:
                const int ii = i % 256;
                const int jj = j % 256;
                const int kk = k % 256;
    But modulus preserves sign! This results in negative numbers being used to access the arrays, grabbing whatever memory happens to be there. Using a simple inline abs() function (so the compiler can optimize away branching) fixes the problem:

    Code:
    static inline int Fast_Abs( int value )
    {
        return ( value < 0 ) ? -value : value;
    }
    Code:
                const int ii = Fast_Abs(i) % 256;
                const int jj = Fast_Abs(j) % 256;
                const int kk = Fast_Abs(k) % 256;
    Well that was a waste of a day. Grr. At least I took a break and got some good solid hours put into Fallout: New Vegas. Shooting mutant radioactive wasteland monsters can be cathartic.

  6. #6
    eye kan kode gud jrandom's Avatar
    Join Date
    Dec 2009
    Location
    Seattle, WA
    Posts
    1,143
    ... which brings up a whole new artifact problem. ARGH. Yeargh. Gagh. Mrgh.

    Click image for larger version. 

Name:	Simplex Artifacts 3.jpg 
Views:	181 
Size:	211.9 KB 
ID:	113971

  7. #7
    eye kan kode gud jrandom's Avatar
    Join Date
    Dec 2009
    Location
    Seattle, WA
    Posts
    1,143
    FINALLY!

    Simply using the absolute value gets you all sorts of discontinuities as seen above. You have to invert if the integer value is less than zero, but you still get discontinuities at -1 -- a fun sort of off-by-one error. This finally did it:

    Code:
                auto int_process = [](int v) -> int
                {
                    return (v >= 0) ? v % 256
                                    : 255 - ((-(v+1)) % 256);
                };
                
                const int ii = int_process(i);
                const int jj = int_process(j);
                const int kk = int_process(k);

  8. #8
    eye kan kode gud jrandom's Avatar
    Join Date
    Dec 2009
    Location
    Seattle, WA
    Posts
    1,143
    ... or simply use the obvious solution:

    Code:
    const int ii = i & 0xFF;

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •