- Home /
How do I correctly invert depth values from an active camera?
After reading Unity's documentation on getting depth value, I get a display where far away objects are shown whiter then closer object.
My question
how do I correctly invert the depth values so that far away objects can be displayed darker?
It seems to be some kind of fog, no ? You can play with the diffuse color of your object according to the depth value.
A fog is what I got from Unity's documentation. Well, what I want is to get a inverse of a fog. Close whiter, further, more black.
To literally 'invert' the depth
camera.depth = -camera.depth;
But I'm guessing it's not what you want and will maybe throw up error everywhere. Urg...messy!
If you are using multiple cameras you can iterate them all into an array and swap all the values.
Somehow I think you are asking about Rendering order ins$$anonymous$$d?
$$anonymous$$ool! I'll convert to answer so u can close the ticket. Thanks!
Answer by OP_toss · Jan 06, 2014 at 11:03 PM
Camera.depth has nothing to do with depth passes, nor with fog.
Either make your fog black, and your objects white, or write a custom shader. Once you're in shader land, you can simply 1-depth to invert it, and you have full control of how it is rendered. But a simple fix would be to use black fog.
EDIT: Looks like you are in shaderland! Just 1.0-depth to do a simple invert. You may want to remap it to make the effect more or less intense. You can also raise to an exponent to create exponential falloff. Options are endless!
Your answer
Follow this Question
Related Questions
FunkyGlowingThingsEffect fix for inverted y on Windows 1 Answer
I'am new to shaders and I'am making games for mobile devices should I switch over to LWRP? 0 Answers
Fog of War overlay for overhead map. 1 Answer
Encoding Float to RG/RGBA and Blending 0 Answers
Setting up a simple depth-based Shader Replacement material? 0 Answers