# Scale instances based on distance from camera - geonodes

Hello.

Does anyone know how to scale instances based on the distance from the camera? I just want to make them smaller the further away they are, so I can fake extreme distance.

I have varied solutions for similar problems but I can’t get this to work - it’s just a basic distribute points on faces, then instance from a collection of objects.

I tried this approach too, but I’m not sure how to get this to work with instance scaling - yet again I’m at a loss as to where exactly this goes in a node tree, if it even works. Image for convenience:

I just got it.

This makes them bigger as they get further away, but I can hopefully figure out how to invert this.

A Vector Math node set to Scale, -1 after the multiply should invert it

2 Likes

That’s what I thought, but it doesn’t…it seems to be rotating them 180 around the Z axis.

Try changing the multiply node to a regular math node since you’re inputting two floats anyway. Add a subtract node after it, putting a constant value of 1.0 in the first input, and the result of the multiply node in the second input.

2 Likes

It seems to be doing the same - it’s flipping the meshes upside down depending on whether it’s 1 or -1, and if the scale or subtract is 1,-1 etc.

Hmmn…

Try putting the subtract node before the multiply node.

1 Like

Still having the same effect I’m afraid. (I suppose the flipping is them getting negative scale?)

What I find strange is that it’s almost like there is a “wave” of scaling - the ones in the middle dip in scale compared to the ones closest and furthest from the camera. I’ve checked all the meshes - everything is scaled to 1, rotation set, etc.

I think I’ll need to come back to this fresh tomorrow. It’s a shame there isn’t just a “camera data” node with distance like there is for shading!

Does the Geometry Proximity node work with cameras?

1 Like

I don’t believe so. You’ll have to use a distance vector math node to calculate the distance from the camera location to the point position.

2 Likes

I too wondered this, so I just tried swapping the camera for a cube and it seems to do the same thing.

I think tomorrow when I have more time I will try parenting an empty to the camera, then trying the “normal way” with proximity with the empty/cube.

EDIT actually, I just tried this using distance from an empty - see below. So strange you can get some instances upside down. Playing around with the node order (multiply/subtract) just seems to flip which values cause them to go upside down (1 or -1, etc.).

The camera object doesn’t contain any geometry. Try directly plugging the location value on the object info node into the vector math node. (Getting rid of the proximity node altogether)

2 Likes

Using -1 for scaling stuff will flip them in all three directions which ain’t what you want. You want to change the distance from going from 0 to 1 to instead be 1 to 0 (or instead of 0 just whatever you want your min scale to be). To do that you just want a Map Range node after that Distance node and change the To Min and To Max to 1 and 0 instead of 0 and 1. Then just change your From Max value to control the scaling distance from your camera.

3 Likes

You can also just do

1 / distance

3 Likes

@higgsas’s setup seems to work well. Dividing is the right way to go.

You can also add float curve and multiply nodes like I did to have control over the falloff.

3 Likes

At this rate I should be paying a monthly salary to @higgsas for solving all my geometry node woes

4 Likes