cancel
Showing results for 
Search instead for 
Did you mean: 

Medium and memory usage

cybernettr
Superstar
i wanted to create the ground, so I chose a stamp that seemed sort of ground-like and built out my ground, stamping it 50 - 100 times to build up the area. Needless to say, memory started becoming an issue, so I saved and quit. I thought when I restarted the computer later, memory would be freed up. I also thought that all those individual stamps would be merged into a single object, and, since it no longer needed to keep track of its undo history, things would be running smoothly again. But when I relaunched, it was as sluggish as ever.apparently, all those individual stamps are still considered to be separate objects. Is there a way to "simplify" the layer and merge all the stamps into a single object so memory can be freed up again?
5 REPLIES 5

P3nT4gR4m
Consultant
All the stamps on one layer are already merged into a single object. Every time you add a stamp, you add volume to the layer, this uses memory. For example, let's say one stamp took exactly 10Kb of memory. You place it once, it uses 10Kb. If you place another one, next to it (makes no difference if it's on the same layer or a different one, it'll use another 10Kb. Place another 8 and suddenly you'll be up to 100Kb. You'll save a bit on intersections on the same layer. So two 10Kb stamps on the same layer, intersecting in the middle would only use 15Kb. 

Obviously there's more to it than this (I'm not privy to any tricks and optimisations the medium team have in place) but as a rule of thumb it should keep you straight. The more clay you put down, the more memory you'll use up.


kojack
MVP
MVP
The way Medium works is that a layer is a Signed Distance Field. This means the layer is a cube of numbers like a voxel grid. Each grid point stores the distance to the nearest surface. A positive number means the point is outside in open space, a negative number means it is inside of a solid area. Other data like colour is stored on each point too. These numbers can be used to build a triangle mesh (algorithms like Marching Cubes can do this, not sure what medium uses).

When you paste a stamp into the scene, what happens is Medium looks at all the grid points in the area around the stamp and sets their numbers to the distances to the stamp's nearest surface. The stamp itself isn't remembered, it's just a temporary shape used to adjust the numbers in the grid.

The grid itself has a resolution. Let's say the default is 256x256x256. I'm not sure what it really is, but something like that. With a distance and colour it might take 8 bytes per grid point. That means a full layer takes 128MB of ram. You could fill that with 1 huge cube stamp or a million tiny stamps, the result is the same.
Every time you click the increase resolution button, the grid doubles on each axis, which makes it take 8 times the memory. One click and you have a 1GB grid (512x512x512). Another click and it's 8GB of ram. Another and it's 64GB.
(These numbers are just a guess, I don't know how many bytes per point it really used. 8 seems reasonable)

But that's for a full layer. What Medium does to avoid going too crazy in ram is the layer is split into smaller sections. So if you only do modelling in one corner of the layer, only the sections affected are allocated. So a 512x512x512 layer wouldn't all be allocated at the beginning. It adds new sections (taking ram) as needed.
According to one of the devs, Medium doesn't reclaim that memory though. If you do something in a corner then erase it, the memory stays active.


It's similar to Minecraft. a minecraft world is based on regions of 16x256x16 (at least it used to be, might be 16x512x16 now on pc, don't know). Once a region is pulled in, the ram usage doesn't care if it's 99% empty or filled with dirt. Empty space takes the same ram as solid blocks. But regions that are far away don't exist until you get close to them, then they have to be remembered.

Author: Oculus Monitor,  Auto Oculus Touch,  Forum Dark Mode, Phantom Touch Remover,  X-Plane Fixer
Hardware: Threadripper 1950x, MSI Gaming Trio 2080TI, Asrock X399 Taich
Headsets: Wrap 1200VR, DK1, DK2, CV1, Rift-S, GearVR, Go, Quest, Quest 2, Reverb G2

P3nT4gR4m
Consultant

kojack said:


The grid itself has a resolution. Let's say the default is 256x256x256. I'm not sure what it really is, but something like that. With a distance and colour it might take 8 bytes per grid point. That means a full layer takes 128MB of ram. You could fill that with 1 huge cube stamp or a million tiny stamps, the result is the same.
Every time you click the increase resolution button, the grid doubles on each axis, which makes it take 8 times the memory. One click and you have a 1GB grid (512x512x512). Another click and it's 8GB of ram. Another and it's 64GB.
(These numbers are just a guess, I don't know how many bytes per point it really used. 8 seems reasonable)



I was under the impression that the number of spaces in the grid stays constant but the sculpted volume is subdivided. That's why the bounding box shrinks when you hit the res button. Maybe not. Maybe a dev could clarify?

nalex66
MVP
MVP

P3nT4gR4m said:


kojack said:


The grid itself has a resolution. Let's say the default is 256x256x256. I'm not sure what it really is, but something like that. With a distance and colour it might take 8 bytes per grid point. That means a full layer takes 128MB of ram. You could fill that with 1 huge cube stamp or a million tiny stamps, the result is the same.
Every time you click the increase resolution button, the grid doubles on each axis, which makes it take 8 times the memory. One click and you have a 1GB grid (512x512x512). Another click and it's 8GB of ram. Another and it's 64GB.
(These numbers are just a guess, I don't know how many bytes per point it really used. 8 seems reasonable)



I was under the impression that the number of spaces in the grid stays constant but the sculpted volume is subdivided. That's why the bounding box shrinks when you hit the res button. Maybe not. Maybe a dev could clarify?


That's correct, when you up the res, the boundary shrinks and the model gets larger within the boundary to effectively get more voxels per unit of volume.

DK2, CV1, Go, Quest, Quest 2, Quest 3.


Try my game: Cyclops Island Demo

kojack
MVP
MVP
Yep, I was wrong, you're right. I did some tests.
Effectively the increase resolution option doesn't increase resolution of the layer.
Instead the model is centred within the layer and doubled in size, while the layer size in space is halved. This means you have what looks the same, but is now represented by more grid points.
If the model is larger than half the size of the layer, then parts are cut off and you'll get a warning.

Going through the shader code, the iso surface values in the SDF are in the form of 0-1, where 0 is outside, 1 is inside and 0.5 is on the surface. Blocks are 8x8x8.


Author: Oculus Monitor,  Auto Oculus Touch,  Forum Dark Mode, Phantom Touch Remover,  X-Plane Fixer
Hardware: Threadripper 1950x, MSI Gaming Trio 2080TI, Asrock X399 Taich
Headsets: Wrap 1200VR, DK1, DK2, CV1, Rift-S, GearVR, Go, Quest, Quest 2, Reverb G2