Lathe shader

Any idea on how to make something like this?
I’m trying to make a lathe using World Position Offset, and what I’ve achieved untill now is an interpolation between a constant and a gradient that simulates going from a cylinder shape to a differnt one.
What I don’t know how to do is store somehow where “the material has been removed” and “how much of it”. Maybe half of the log has been carved while the other has only been carved halfway.
Any idea on how to solve this situation?
Thanks!

Probably the best way best way would be store the data in 1D texture, where coordinate represents distance along the lathe and the value represents height. You can use this texture for World Position Offset. You would need to write values to this texture from your game code.

By 1D you mean something like a 256x1 px texture or something that I’m not aware of?
Also, do you know any example of runtime texture editing? I suppose it has to be done pixel by pixel.
Thanks a lot for your suggestions!

You could do this with material displacement or POM, I wrote a shader for displacement based tree cutting and one of the iterations before it was finished had an unintended side-effect where displacement occurred in a ring like that. You could potentially do the same thing where displacement is applied along the width of the cylinder either with a banding texture that’s masked in based on coordinates or by literally spinning the mesh and applying sphere-mask based displacement by location, scale the displacement in a blueprint on a 0-1 scale where 0 is no displacement and 1 is displacement all the way down to the center, and set up an event tick with a branch check that will apply like a .001 displacement when it’s true and no displacement when it’s false. Then just set up the variable to be something like “iscutting?” and have it set to true when the left mouse button is pressed, and false when the left mouse button is released.

Here’s a link to my blog post discussing the shader stuff, it’s not built for this particular situation but may have some helpful pointers for you.

https://hippowombatsblog.wordpress.com/2015/11/17/ue4-tree-cutting-system-breakdown/

Cheers!

Yep something like 256x1. I think this is the link that covers editing textures dynamically.

However, if you do not want to dive into the code, as of version 4.13 I think there might be an approach of doing the effect you need with less precision using Draw Material To Render target completely on blueprints.
In fact you can avoid intermediate render target at all. Split your axis into cross sections and feed their height into material via Material Parameter Collections. Inside the material interpolate between cross-sections based on location of the vertex.
This will not allow you to make 90 degree sharp edges in the shape, of course, but you could improve it further by sending your material not only cross sections height, but also their in and out tangents and account for them during interpolation.

As a complete alternative to all that, you could take a look at procedural mesh component in blueprints.

Anyway, I might think inefficiently and someone else can suggest you a better approach.

I think I’ll try with procedural meshes by hiding the finished mesh inside an editable cylinder.
I’ll store a depth value for each vertex group along the rotating axis and I’ll build a mesh from that
I tried with the sphere mask way and I couldn’t get a nice result, while I’m really not able to use dynamic textures at low level, I’ve done it in other engines but it was like “SetPixel(x, y, Color)”.
Thanks to everybody for your kind help!

I made a wood material a while ago that should work for the inside. You’ll need need to interpolate between the bark and the wood, but as you displace the vertices of the wood as you carve it should update in real time.

This will come in handy, thanks a lot!