-- values from c --
-- isoLevel
-- gridCount
-- perlin(pos, gridPos)
--
-- radius [0 - 1]
-- wallThickness [0 - 1]
-------------------
toWallStart = radius - wallThickness
--actual value function
function valueFunction(pos, gridPos)
--get normalized position and center
vec = gridPos * (1.0 / gridCount)
center = vector3(0.5, 0.5, 0.5)
--get normalized distance to center
diff = length(vec - center)
--early out of zero when outside of radius
if(diff >= radius)then
return 0.0
end
--gets the fade value
fadeValue = 0.0
if(diff > toWallStart)then
fadeValue = (diff - toWallStart) / wallThickness
end
--early out if the fade value is higher than the isoLevel
if(fadeValue > isoLevel)then
return fadeValue
end
--gets the perlin noise value
perlinValue = fadeValue + perlin(pos)
--returns the final value
return perlinValue
end