# Depth question

**URL:** https://discussions.unity.com/t/depth-question/423284
**Category:** Shaders & Materials
**Tags:** Shaders
**Created:** [September 17, 2010, 8:49pm UTC](https://discussions.unity.com/t/depth-question/423284 "2010-09-17T20:49:27Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![reissgrant](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/reissgrant/32/430141_2.png) [@reissgrant](https://discussions.unity.com/u/reissgrant)
#### Post date: [September 17, 2010, 8:49pm UTC](https://discussions.unity.com/t/depth-question/423284/1 "2010-09-17T20:49:27Z")

</div>

Noob question.

I’m using the R channel of a depth render to texture. The values start at the near clipping plane and extend all the way out to the far clipping plane. Is there a way to adjust this so that the closest object is 1 and the farthest is 0 without adjusting the clipping planes?

---

<div class="post-metadata">

### Author: ![Aras](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/aras/32/44145_2.png) [@Aras](https://discussions.unity.com/u/Aras)
#### Post date: [September 18, 2010, 8:12am UTC](https://discussions.unity.com/t/depth-question/423284/2 "2010-09-18T08:12:14Z")

</div>

No. But “1-value” in the shader would do just that, right?

---

<div class="post-metadata">

### Author: ![reissgrant](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/reissgrant/32/430141_2.png) [@reissgrant](https://discussions.unity.com/u/reissgrant)
#### Post date: [September 18, 2010, 2:00pm UTC](https://discussions.unity.com/t/depth-question/423284/3 "2010-09-18T14:00:12Z")

</div>

What I mean is that my objects only occupy the first 2% of the area between the near and far clip planes so everything appears black (in hrDepth.r) sans alpha. I have to bring the far clipping plane to the edge of the farthest object to see the full 0 - 1 range in the depth buffer.

However, I get the full 0 - 1 range with “hrDepth.g” and setting the far clipping plane to “5555”. I have no idea why this works, so I need to read up on it. I think I need to understand what’s going on more before I ask these questions ha 😉

---

<div class="post-metadata">

### Author: ![Aras](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/aras/32/44145_2.png) [@Aras](https://discussions.unity.com/u/Aras)
#### Post date: [September 18, 2010, 6:23pm UTC](https://discussions.unity.com/t/depth-question/423284/4 "2010-09-18T18:23:15Z")

</div>

The depth in the buffer is non-linear, and mostly depends on the distance of your _near_ plane.

Use these functions from UnityCG.cginc to linearize it: Linear01Depth(z) will return linear depth in 0…1 range; LinearEyeDepth(z) will return linear depth in world space units.

---

<div class="post-metadata">

### Author: ![reissgrant](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/reissgrant/32/430141_2.png) [@reissgrant](https://discussions.unity.com/u/reissgrant)
#### Post date: [September 18, 2010, 6:29pm UTC](https://discussions.unity.com/t/depth-question/423284/5 "2010-09-18T18:29:44Z")

</div>

I see, that’s what I’m missing.

Thanks Aras.
