What is a low memory way to store user generated heightmap animations

82 Views Asked by At

I have a heightmap that is a 2D array

const uint32_t dwResolution = 20000;
float fTerrain[dwResolution][dwResolution];

And the user can apply brushes to the terrain like the following:

void ApplyGaussianBrush( float *fTerrain, const uint32_t dwResolution, const float fBrushCenterX, const float fBrushCenterY, const float fDiameter, const float fStrength, const float fTimeDelta )
{
    uint32_t dwYStart = (uint32_t )(fBrushCenterY - (fDiameter/2.0f)) + dwResolution;
    uint32_t dwYEnd = (uint32_t )(fBrushCenterY + (fDiameter/2.0f)) + dwResolution;
    uint32_t dwXStart = //math
    uint32_t dwXEnd = //math
    for( uint32_t dwY = dwYStart; dwY < dwYEnd; ++dwY )
    {
        for( uint32_t dwX = dwXStart; dwX < dwXEnd; ++dwX )
        {
            //Apply Clamped Operation here, still working on it :)
            //(every frame this is called while clicking and gets extrudes up or down if 
            // strength is positive or negative and it is multipled by the time delta), 
            // so while editing changes are accumulated over frames
        }
    }
}

However now I need the user to be able to play back these operations in an animation timeline. Which random access in the animation (meaning they can skip to any part in the animation).

So my first intial thought for the nodes of the animation is to just store solely the positions of the entire terrain into each node and then lerp between the nodes as you scrub through the animation. But this approach seems extremely memory intensive. If my users are going to only have flatten brush and gaussian brushes (that can go up or down), is there a simpler way to store this animation data. Maybe there is an equivalent to some sort of brush skeleton that combines all the applied brushes (from start of animation to current keyframe) into a keyframe then you lerp that brush skeleton and applied the result to the effected vertices. But I can't think of really how to do this and what would be an efficent way to apply these transformations.

So how would I go about doing a cheap performant heightmap animation? Any help would be much appreciated!

0

There are 0 best solutions below