How to use "shader"/"Material" to "rescale" a Mesh it attached to?

context: Since I want to let GPU process the “Rescale” action for all the meshes
How to use “shader”/“Material” to “rescale” a Mesh it is attached to?
let’s say there is a cube mesh with a scale like (X:1.0, Y:1.0, Z:1.0), now i want to create a shader/material which will rescale it to (1.0, 1.0, 0.5) then how do I implement it?

where it can just planish the mesh by a certain height just like the following picture shows

You scale the vertices by doing math into the WorldPositionOffset.

Here’s an example of how you can manipulate it: Materials: Rotating meshes using Vertex Shaders - Tom Looman

thx I’ll read it

Essentially, you want to adjust the WPO or XYZ of the vertex by something to move it. But you also need a vector/direction along which you project that vector/magnitude. If you simply multiplied the Zcoordinate by .5 for the entire mesh, you would likely get something very odd, vs the flat-topping you seem to be asking for.

Otherwise for just raw-scaling of the mesh bigger vs larger, you can do something like this:

vs:

So, the short version is WPO is where it’s at, but depending on WHAT you want to do, you gotta figure out the maths for yourself. If you want to only scale parts of the mesh you will need to calculate the alpha for yourself.

In my example, I use the vertexnormal in worldspace so it’s always pointing ‘out’ from the face of the mesh, generally ‘out’ from the center, but complicated shapes being what they are, you might need to make something more elegant to calc an alpha-mask.

NOTE: adjusting the WPO this way does NOT carry over to collision, it’s visual only.

thx for the explanation there is a friend of mine suggested those nodes that are pretty close to what I want. as the following image shows:


1 Like

If that is what you want, great! Otherwise, you’re on the right track.

If you are new to materials (?), try these:

And glad I could help.

Hey im looking to pay someone to explain exactlly what you guys are talking about .

If you want tutor/lessons, sure, lol, otherwise I can explain here.

WPO is World Position Offset. You put a 3vector, XYZ/RGB value into the WPO node and it will cause the shader to move the vertices of the mesh XYZ units in that direction.

The direction, mask, etc is all something you have to math out. If you want only the left-side, the top-half, etc. You then, essentially, multiply that by the mask/alpha so you can control where the adjustments are made.

In my example above I use the vertex-normal, in worldspace, so it generally always points ‘out’ from the surface of the mesh. Since I multiply my adjustment/movement-factor by that vector, I project that amount of movement along that line/vector in worldspace. So the WPO is always X units along the outward-vector from the surface, hence it makes the sphere bigger.

In anyone else’s specific case, it’s hard to predict what you would need.

In the OPs case, you’d want to find the middle of the mesh and scale any Z-values above that point down to that z-value, leave the X and Y values alone.

Feel free to ping me with questions. I learned all this stuff at the behest of other ppl bothering to document stuff. We all stand on the shoulders of giants here.

1 Like