1
$\begingroup$

I'm not sure if this is possible but I was wondering if there’s a way to set the thickness of a solidify modifier to adjust based on distance to camera so the thickness would be even in screen space.

Say if you had a plane of particles all based off one sphere object- the spheres farther from camera would have thicker solidify modifiers and the ones closer would be thinner.

I’ve searched high and low for an answer to this and haven’t returned much. I’m not great with drivers so my tests with that haven’t gotten me very far either. Any answer on this is appreciated. Thanks!

Edit: I've thrown a distance driver on the thickness input on the solidify modifier linked to the object and the camera which keeps the object the same size which is a start but I'm still after the expression to make the amount of thickness look the same from near and far. So an object up close would appear to have the same distance from the solidify modifier result and the original object from a screen space perspective when compared to an object with the same solidify modifier far away.

Second Edit: It seems that the driver doesn't update for each particle and only updates globally making this seemingly impossible with drivers unless I'm mistaken. Unless there's a workaround to use weight painting that updates through camera FOV like I've seen done before.

$\endgroup$
5
$\begingroup$

So originally, I recommended doing this with geometry nodes, and you've had some trouble with that. In preparing you a better answer, I've had nothing but trouble with trying to get geometry nodes to give me the proper materials, and GN instanced materials is one of those things that is still changing with every release (and is currently pretty wicked bugged.) At the same time, I realized that I was overthinking the alternatives, and they're not really hard to implement. So instead of doing it with GN, let's do it with regular old modifiers.

You've indicated in comments that your end goal for this is outlining, so let's work with an outlining example.

  1. Select your object and make sure that scale is applied. What I am demonstrating will not work with unapplied scale, even with inherited scale. You can do some tricks to make it work with uniform unapplied scale, but it will never ever work with non-uniform scale.

  2. Make a new VG for it, call that new VG "prox". Assign all vertices to "prox" at weight 1.0.

  3. Give your object a vertex weight proximity modifier. Set the target object to your camera. Set the vertex group to "prox". Set the proximity mode to geometry/vertex. Set the lowest weight to 0m and the highest weight equal to the far clip of your camera (default, 100m.)

  4. Give your object a solidify modifier. Set the offset to 1.0, disable rim fill, enabled flipped normals, and give it an appropriate material offset so that the solidified mesh acquires your outline material (talked about in a little more depth below.) Set the vertex group to "prox" and then, from your camera's perspective, set the thickness to eye.

Now you need an outline material. For mine, rendering in Eevee, I just made a black emission material with backface culling enabled. Because my object had only a single material before creating the outline material, I set the solidify Material Offset to 1. If you're ever having trouble with an outline material, remember that the direction of your normals is the most important thing, and that different directions of normals can be made to work, just in different ways.

Pic demonstrating all that:

enter image description here

Now let's zoom out the camera:

enter image description here

Outlines are the same width.

Here's a file so you can play with the camera and see it working:

Notes:

  1. When doing it this way, geometry that spans the far clip distance won't really work properly. This will probably be unnoticeable in practice, but it's possible to create theoretical situations that aren't right. (Really, any geometry that spans the far clip won't look right, so the fact that the outline also won't be right doesn't much matter.)

  2. SS thickness is not just a function of distance to camera, but of FoV as well. You can create a driver to change the thickness linearly as FoV increases, but it's kind of a pain because you have to figure FoV from sensor size and focal length. I'm assuming you won't be changing FoV in any animations.

  3. The way that these kinds of outlines work, the thickness of the line is not a single value-- the thickness, in pixels, depends not just on your solidify modifier's thickness, but on the angle of the face relative to your camera as well. What we're doing is establishing a constant maximum outline thickness. In practice, your outlines will vary from this zero to this maximum. Again, this does not depend on distance, but on relative angle.

  4. I mentioned that this will potentially work with unapplied uniform scale. Solidify thickness is in object space not world space, so if you want it to work with unapplied scale, create a driver for your solidify thickness that divides the thickness by your object's scale (x,y, or z, because if it's uniform scale, they're all the same.)

$\endgroup$
14
  • 1
    $\begingroup$ @Stray_Dog_ I would use a collection info node to get all the geometry in a single collection and to create the displaced outline mesh. $\endgroup$
    – Nathan
    Aug 17 at 3:16
  • 1
    $\begingroup$ @Stray_Dog_ Are you talking about your FoV? It can be irritating, because your actual FoV depends on your rendering dimensions. But see blender.stackexchange.com/questions/23431/… . Best is to just adjust to eye (the value node in pic above) and to use a fixed FoV. Adjust to eye in a preview that roughly matches your final rendering dimensions, as rendering resolution has a pretty large subjective effect on what thickness of edge to use. $\endgroup$
    – Nathan
    Aug 17 at 18:36
  • 1
    $\begingroup$ @Stray_Dog_ The biggest issue in what you're showing me is that you're using a negative value for the (relative) thickness of your line. It absolutely shouldn't be negative, or any line thickness is not what you think it is. I'm happy enough to edit this answer to offer a little more, was kinda planning to anyways, but I can't do that until tomorrow or so-- in the meantime, that bit of info might help. (It would be good, too, if you can edit the question a little bit to better establish your exact goal, which I personally understand, but which doesn't come through in the question.) $\endgroup$
    – Nathan
    Aug 17 at 22:56
  • 2
    $\begingroup$ @Stray_Dog_ Updated answer. Different technique (man, getting instanced material assignments in GN is awful and changes with every release...) $\endgroup$
    – Nathan
    Aug 18 at 23:35
  • 1
    $\begingroup$ @Stray_Dog_ There will be. And I have files with working GN outlines, so I don't know exactly what the issue is, it is currently very difficult to predict what GN will decide to do with a material assignment from an instance. Not alpha, 2.93.3 release, but GN is a WIP for now anyways. $\endgroup$
    – Nathan
    Aug 19 at 0:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.