Model of Distance From Camera

Hello,
I have a very interesting problem to solve.
I’m trying to use Blender in order to create an image or an animation that has only one feature: The color should be a function of distance from the camera.
For instance, the closer an object is to the camera, the whiter it is, and the further away it is from the camera, the darker it is.
In short, the image/animation should only contain information about the distance from the camera.

I tried manipulating the lighting to make this happen. I put a spot lamp at the same location as the camera and pointing in the same direction. This created problems with “pointy” shapes such as a cube.

Is there any script/tool/plugin that can perform this operation?
Does anybody have a suggestion on, maybe, more intelligent light manipulation that would actually make this work?

Thanks in advance,
Elez

This cas easiley be solved with nodes, using the ‘Camera Data’ node. - I just cant remember how. :wink:

You could also add a script link to the object and put explicit python code in the script link that examines the distance from the object to the camera and then calculates a color based upon that value.

Thanks a lot to both of you for your information so far!

Can someone please elaborate a bit further on the use of the ‘Camera Data’ node?

@Atom: Could you refer me to some example?

Thanks again,
Elez

It is not an exact fit for your requested solution, but Cambell Barton uploaded this BLEND file a while back. It changes the color of spheres in the scene via a script link. The color change is controlled by moving the empty.

Perhaps you could parent the empty to your camera, then put in some distance calculations in the script. I don’t know those math functions, but the framework is in place in this BLEND file.

Attachments

color_balls_via_sciptlink.blend (57.3 KB)

What you need to use for this is a depth map. (Z-map.)

If you use render-nodes (and you should…) this is one of the standard outputs. Add a scaling-node to let you map its values to whatever numeric range you might require. Then, use that to modify one or more of the R/G/B color outputs, and pass that along down-stream.

Thanks a lot, people!
I was lacking even the basic terms in order to google for a solution.
Now, with your help, I even found a video with an example for this exact thing.

http://www.yofrankie.org/blender-glsl-shading-nodes-goodies/

I tried it and it works just as I required!

I will, however, examine the other solutions you offered, as they probably will come in handy as well…

Thanks again! What a wonderfully active community you have here :slight_smile:

Hey.
I wrote a reply maybe 11-12 days ago and it didn’t get published for some reason…
Anyway, here’s another attempt at it :slight_smile:

I want to thank all of you very very much!
I’ve never done anything with Blender (or any other equivalent application) so I was lacking even the most basic terms, and you helped me with that.

Using what I learned from you, I Googled some words and came up with a wonderful tutorial, that covers exactly what I wanted.
So here it is for future reference:
http://www.yofrankie.org/blender-glsl-shading-nodes-goodies/

And I’ll look into the other solutions suggested here, as I might need more advanced things in the future.

I can’t thank you enough, people! You’ve been tremendously helpful!
What an awesome community you have here.

Thanks

Hey.
I wrote a reply maybe 11-12 days ago and it didn’t get published for some reason…
Anyway, here’s another attempt at it :slight_smile:

I want to thank all of you very very much!
I’ve never done anything with Blender (or any other equivalent application) so I was lacking even the most basic terms, and you helped me with that.

Using what I learned from you, I Googled some words and came up with a wonderful tutorial, that covers exactly what I wanted.
So here it is for future reference:
http://www.yofrankie.org/blender-glsl-shading-nodes-goodies/

And I’ll look into the other solutions suggested here, as I might need more advanced things in the future.

I can’t thank you enough, people! You’ve been tremendously helpful!
What an awesome community you have here.

Thanks