Material - Modifiying Object's Scale Using ObjectScale

86224-objectscale.png

I’m trying to write a vertex shader that will scale an object down programmatically. Can this be done using the ObjectScale function? I tried this basic shader, but it doesn’t affect the object’s scale.

1 Like

I havent used object scale before, bit im pretty sure what your doing will scale a texture (which you dont have) with the scale of the object. I dont think you can do that in the material editor, do it in the blueprint of the object

Take the objects world position, subtract the Absolute world position and multiply the result by a value.

I use the sine of time to make it pulse back and forth.

Wire all that into World Position Offset.

5 Likes

Object scale gives you the scale that the object already have in your level editor.
If your object scale is 1,1,1, it will be white, 1,1,0 will be yellow etc… Values over 1 will become emmisive if you plug it to the emissive node. (10,10,0): emissive yellow. It does not make sense to scale an object in the shader using this data because you have to modify the real transform of the object to modify that parameter.

To scale an object uniformly in X,Y,Z, you can just multiply a scalar value by the vertex normal node and plug it into the world position offset.

1 Like

If anyone is looking to have an actor scale up or down based on the distance to the camera (or player) you can use a camera depth fade and a lerp to drive the multiply value instead of time and sine:

3 Likes

Wit this method I seem to be getting some self-shadowing on the normals based on the original scale of the object. If the object grows in size, it’s not visible, but as it contracts, the normals become dark in the areas where it contracts past the origin point of the vertex.

1 Like

Probably mesh distance field shelf shadowing, you could disable them on the mesh or change the bias settings for it.

Hmm, not sure how to turn them off, but changing the bias didn’t seem to affect the objects. I’ve currently got just an HDRI lighting the scene, which doesn’t seem to have any Distance Field Shadow properties either, as other lights seem to.

You can set Distance Field Resolution Scale to 0 to turn it off on a static mesh.

Ah, I see it. Did not seem to fix it though.


To illustrate, I am squashing this sphere on the x-axis. In the areas where it shrinks past the vertex origin point, it will shadow it. Doing something like turning off the shadows fixes the issue, but naturally that’s not what I’m looking for. Your suggestion seemed like a good one, but not sure why it had no effect.

Switching off raytracing fixed the issue, though I’m not sure why. For some reason, Raytracing is causing this.