Render only close to an object

Hi Guys
Brainstorming guys, different ways to do the following.
I’m just making a scene of a coin rolling through some scenery. I want to only render the scene within a certain distance of the coin.

I want to produce a short animation of the coin rolling down a slope and across a table. I will be rendering to transparent film. So I only want things close to the coin rendered

Edit
For clarity, I threw a demo scene together before i take the time to make it (I’ve not started this)
The demo scene contains a wooden ramp, a wooden table and a gold coin. It also contains a red sphere for the sake of visualisation. I want everything inside the sphere to be transparent and everything outside to sphere to not be rendered/be transparent. So the render should include the table, inside the sphere, the coin itself and any other object passing into the sphere.

Did a mod move this and not say anything?

I’m sure I put it in the rendering section

You could reduce the sensor size of the camera, which will give you a render only of a smaller section. Then reduce the render resolution by the same factor. If you choose nice, even factors it should give you pixel-accurate results you can paste over the full scenery image. Use the Lens Shift parameter of the camera to choose the section to render. You likely would have to that in fixes steps (instead of smoothly), to ensure it is shifted by an integer amount of pixels.

You can do that in the compositor, if you are just looking for the visual effect. if you are looking to save rendering time, @omgold’s solution is probably your best bet.

Here is how I set up the compositor nodes:

I have added an edit for clarity.

I’m not sure it woudl really work in the compositor, an object in the background will show when I don’t want it to.

@SterlingRoth I want soft edges exactly liek you have them there though.

@omgold I 'm not really sure how I woudl achieve the desired effect with what you are suggesting

I’m not much of a compositor, but one possible way would be to create a distance based mask material that you apply to all objects but the coin.

Here’s an example. As you move the cube around, surrounding objects appear based on their distance to the cube.


distance_mask.blend (812.7 KB)

This example is based on distance on the XY plane, but it can be expanded upon to create a sphere of influence if this is what you’re going for.

Okay, it was a complete misunderstanding then. I thought it was about saving render time.

But I fear I still don’t completely understand. What exactly is the criterion again for something to be shown or not? The table should always be shown? But the part behind the sphere is mostly outside of it.

It depends on your answer whether you want to do it in the compositor or go with a material-based solution like cgCody. Be aware that in the compositor you also get the z-depth from the Render Layers node, so you can easily compute the 3D distance from the coin of what is shown at each pixel.

@cgCody I think you are exactly on the right lines. It sounds right, I just want sure where to start.

I’ll put it in my test scene and see if it has the desired effect, thanks for the help.

@omgold anything outside the sphere should not render. So the part of the table inside the sphere should render and the part outside shouldnt. Also lets say another coin rolls into the sphere, only the part that is currently inside the sphere should show.

Before you go adding that into your scene, pump the breaks and take a look at the below update. I was just playing around with the material when I realized DUH! There’s already a procedural sphere texture in Blender.

I’ve been working on procedural materials all day, so my knee jerk response to this thread was to jump into the math nodes. :smile:

distance_mask.blend (792.5 KB)

And yes, it will do exactly what you are describing with your image above. Just note that the holdout shader will knock out anything in front of it, so if that’s not the desired effect, the transparency shader may be a better option. Or just use black and white emission shaders (plugged into that mix shader) to create a mask to be used in compositing.

@bigmonmulgrew: okay, but what exactly do you want to get rendered at locations behind the sphere, I mean for pixels where the camera ray passes through the sphere but hits the mesh behind?

@cgCody: maybe the holdout shader should only be used for camera rays, otherwise the lighting might look weird.

I guess I’m a little confused here: in BI there’s a camera setting which determines the inclusive range of distances away from the camera that will be considered for rendering. Anything outside of this range is “not there.”

However, as a matter of course I would ordinarily do this in the compositor, using MultiLayer OpenEXR files which capture Z-distance information along with everything else; possibly also object-IDs. Between these two, you will certainly then be able to mask out what you do and don’t need in a shot.

He doesn’t want to render objects based on the distance from the camera, but rather the distance from the coin.

Camera clipping and Z depth won’t work as they only factor in distance parallel to the camera view.