summaryrefslogtreecommitdiff
path: root/src/libs/din/din.c
AgeCommit message (Collapse)Author
2023-12-31libs/din: constify coordinate to din()Vito Caputo
This doesn't seem to make any impact on performance, but it's awkward to be modifying the supplied coordinate as if it's a result... the coordinate input should be left alone, and should be able to get reused across din calls so only the varying members need to get updated across calls.
2023-12-31libs/din: remove unnecessary floorf() from din()Vito Caputo
These are being assigned to ints to index the grid and will become rounded down through truncation anyways. This little change brings a ~20% FPS boost in modules/swab on an i7 x230.
2023-12-31libs/din: constify din_t for din()Vito Caputo
din() just samples the din_t which will always just be a read-only operation, so constify this. It might even help the compiler generate faster code for din-heavy inner loops like modules/swab uses.
2023-12-31libs/din: trivial optimizationsVito Caputo
din() is a hot path for modules/swab in particular. Barring any substantial changes to swab, which would probably make sense in the long-term, there's some low-hanging fruit in libs/din. Here smootherstep() has been made less general for a little perf boost. The way din uses smootherstep() doesn't need these bounds checks, nor does it need the caller-supplied edge values. Also the asserts() have been disabled in the hot path as they were mostly there for catching programmer errors and swab is already done. On my i7 x230 this takes swab from 44fps->54fps, so worthwhile, but swab is still painfully slow here. It's largely just a libs/din abuse module that was made to test libs/din, but turned out to look interesting enough to keep.
2023-06-13*: smattering of random small fixes to silence -WallVito Caputo
I thought the build was already using -Wall but that seems to not be the case, maybe got lost somewhere along the line or messed up in configure.ac After forcing a build with -Wall -Werror, these showed up. Fixed up in the obvious way, nothing too scary.
2022-07-20libs/din: pass seed to din_new()Vito Caputo
also update call sites in modules/{meta2d,swab} accordingly
2022-04-28libs/din: lose the asserts in dotgradient()Vito Caputo
This just slows things down, and now that the code is mature enough to never trigger these asserts just get rid of them.
2022-04-28libs/din: minor optimization in clamp()Vito Caputo
short-circuit by directly returning bound when exceeded
2022-04-28libs/din: premultiply din->width * din->heightVito Caputo
dotgradient() is very hot and needs this result when indexing din->grid[]. Since it doesn't change for a given din instance, just cache the result @ din_new().
2019-12-18libs/din: fix scaling overflow, add assertsVito Caputo
Phil reported a crash in swab, illuminating an overflow in how the unit cube was being scaled to the noise field dimensions. Added some asserts enforcing critical assumptions as well, though it will probably cost some FPS in din-heavy modules like swab.
2019-11-25din: scale resultVito Caputo
I'd like the output to fill the range -1..+1, but it's not doing that and I'm uncertain on what exactly the scaling factor should be here. In one reference a factor of 1/sqrt(.75) is specified, but in my tests that doesn't seem to quite fill the range but it doesn't seem to blow it out so it seems safe for now.
2019-11-25din: drop .f from integer additions in din()Vito Caputo
2019-11-25din: don't include v3f.h in din.hVito Caputo
This requires a forward declaration of v3f_t and changing din() to take a v3f_t *. The swab module needed updating to supply a pointer type and a v3f_t definition. This is being done so din.h users can have their own v3f implementations. I might consolidate all the duplicated vector code scattered throughout the libs and modules, but for now I'm carrying on with the original intention of having modules be largely self-contained. Though the introduction of libs like ray and din has certainly violated that a bit already.
2019-11-18libs/din: add a perlin noise implementationVito Caputo
This is a 3D noise field addressed as a unit cube. The caller supplies the resolution of the noise field in three dimensions. I've just pulled in my v3f.h here, but it probably makes sense to later on move vector headers into libs/ and share them. Later. It's called din as in noise, because it's shorter than perlin and noise.
© All Rights Reserved