im trying to generate rocks for my semi-realistic survival evolution type game, but the rocks are generating kinda weirdly…
theres some sort of thing that i can only describe as like, a seam or something on the rock. i think its a result of how i apply the normal? im not sure, heres some images:
ive searched everywhere for like 2 hours and cant find a solution for this… please help
heres the code for further analyis:
local rc = self.rockConfig -- table containing all the config values
local rng = self.rng -- Random
local model = self.model -- editable mesh
local ns = rc.noiseScale -- equals 5
for i, vertex in model:GetVertices() do
local vPos = model:GetPosition(vertex)
local availableNorms = model:GetVertexNormals(vertex)
local sum = Vector3.zero
for i, norm in availableNorms do
local normVec = model:GetNormal(norm)
sum += normVec
end
local vNorm = sum / #availableNorms
local noise = Simplex.Noise3D(vPos.X/ns, vPos.Y/ns, vPos.Z/ns)
local newPos = vPos - vNorm * (noise * rc.noiseMult) -- noiseMult equals 2
model:SetPosition(vertex, newPos)
end
The seam you’re seeing is almost certainly caused by incomplete normal averaging at your vertex boundaries. Looking at your code snippet, you’re summing the normals but never normalizing the result—that Vector3 needs to be .Unit before you apply it.Here’s the fix:lualocal sum = Vector3.zerofor i, norm in availableNorms do local normVec = model:GetNormal(norm) sum += normVecendlocal vNorm = sum.Unit -- Normalize the averaged normalmodel:SetNormal(vertex, vNorm)Why this matters: When you add vectors without normalizing, the magnitude changes based on how many normals you averaged. This creates inconsistent lighting across adjacent vertices, which manifests as visible seams or hard edges on curved surfaces.A few additional things to check:- Vertex ordering: Ensure your mesh generation maintains consistent winding order. Flipped faces will produce inverted normals that contradict their neighbors.- Noise function output: If your noise is creating sharp discontinuities (rather than smooth gradients), that’ll show through regardless of normal handling. Make sure noiseScale is creating gradual height variations.- Double-check your mesh construction: Are you accidentally duplicating vertices instead of reusing them? Shared vertices should share normals; duplicated vertices won’t.If normalizing the averaged normal doesn’t solve it completely, the issue might be in how you’re generating the mesh topology itself. Post a screenshot of your mesh wireframe if the problem persists—that’ll tell us if it’s a topology issue rather than a normal calculation one.