Checking within a radius if math.noise returns a certain value

I’m working on making procedural terrain(I finally decided to try and fix it again… ), and to generate certain objects/structures I want to flatten off the area, and to do so, I’m having them seed based(ofc)

Currently I have a way to smooth the terrain out, but it only will smooth in the “chunk” that the object is generating in currently, and I want it to be able to find if within a certain radius(say 200 studs) it would be where an object would generate, since certain times the structure isn’t loaded but terrain around it is

I tried doing the classic double for loops when dealing with 2D maps

for x = 1, 200 do
    for z = 1, 200 do
        if math.noise(CurX + x,  CurZ + z, 1951.2345) > .9 then 
            --do the stuff here ofc
        end
    end
end

Which has the issue of being really slow, or laggy(if I don’t yield every 50 or so iterations on x), since I have to yield now and then or it times out due to it literally just checking a table where I cached the previously found objects

One thing I could do, is not have the objects procedurally placed, and have static locations for them(kinda like how Minecraft Strongholds used to be), but I’d rather not do this, since I feel as though it reduces the immersion of an infinite world, since you can see the pattern to a certain extent.

If there’s a simple way that I’m too dumb to realize, that would be nice, but any input most likely will help, let me know if you need further information :smiley:

1 Like

You need a technique similar to Texture Bombing, which you can adapt to 3D to get that info quickly. This technique is optimized for GPUs so it should be possible to run in parallel.

with that brings up the same general issue of, I would need to have a for loop, and since to check within the radius(which would be the largest side of the object) it could be massive, I again have the issue of it either timing out, OR, it yields now and then(if x % 50 == 0 then task.wait() end), which again takes ages.

I get you’re recommending for it to run in parallel, but I’m still concerned, but I’ll try it out, and see how it works

Also I don’t need to adapt it for 3D, since I only am using it to determine if a X and Z position are valid, I don’t care about the Y