Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
1
Question by pragmascript · Jun 29, 2011 at 11:55 PM · depthdepth-buffer

accessing depth information of rendertexture

Hey,

I can create a RenderTexture and have the cam render into it.

 depth = new RenderTexture(Width, Height, 16);

i have specified a depth buffer of 16 bit. How can I access the depth values of this 16 bit depth buffer via scripting?

(i need both color and depth values, if possible with only one draw call)

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Peter G · Jun 30, 2011 at 11:57 PM 0
Share

Have you seen this page:

http://unity3d.com/support/documentation/ScriptReference/RenderTextureFormat.Depth.html

You specify it when you create your rendertexture how it will be used.

avatar image DaveA · Oct 03, 2011 at 08:23 PM 1
Share

That doc seems to tell how a shader might access it. How would a c# script access it? I'm assu$$anonymous$$g that was what the original question was about. If not, will open new question.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by weatxyz · Dec 24, 2016 at 11:48 PM

I'm going to resurrect this post since I have the same question, and think the original commentor didn't quite understand the question.

I know a render texture is a texture that you can render to instead of the frame buffer. You can treat that texture the same as any other texture. This means it's a Texture2D and it can be bound to a 2D texture property to be used in a shader.

The OP is asking where the Depth Texture2D is. I did some OpenGL programming a long time ago and thought that you could access the depth buffer somehow, or maybe it's just an option you pass into the binding statement that enables the z buffer for when the colors are drawn, and that's it. After that it's gone. Is that the case, or can the depth values be accessed like the colors in a render texture?

Thanks :)

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image weatxyz · Dec 24, 2016 at 03:33 AM 0
Share

O$$anonymous$$, found this at gamedev.net, although he's only setting up the FBO for depth.

 glGenFramebuffers(1, &m_shadow$$anonymous$$apFboId);
 glGenTextures(1, &m_shadow$$anonymous$$apTextureId);
 
 // Allocate GPU-memory for the depth-texture.
 glBindTexture(GL_TEXTURE_2D, m_shadow$$anonymous$$apTextureId);
 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_CO$$anonymous$$PONENT32,
 m_shadow$$anonymous$$apSize, m_shadow$$anonymous$$apSize, 0, GL_DEPTH_CO$$anonymous$$PONENT, GL_FLOAT, 0);
 
 // Bind the texture to the framebuffers depth-attachment.
 glBindFramebuffer(GL_FRA$$anonymous$$EBUFFER, m_shadow$$anonymous$$apFboId);
 glFramebufferTexture(GL_FRA$$anonymous$$EBUFFER, GL_DEPTH_ATTACH$$anonymous$$ENT,  m_shadow$$anonymous$$apTextureId, 0);
 
 // Tell the Framebuffer we won't provide any color-atachments.
 glDrawBuffer(GL_NONE);   // For depth-only-renderings, if you need also frag-color don't use this.
 
 if (glCheckFramebufferStatus(GL_FRA$$anonymous$$EBUFFER) != GL_FRA$$anonymous$$EBUFFER_CO$$anonymous$$PLETE)
 { ... }

So in this example he's only generating and then binding a 32 bit depth texture to be used for shadow maps, but in this code snippet it's clear that the depth is a texture, so it's possible to access it...somehow. He does mention the color buffer in there, he's just not setting up the FBO in that way is all.

Is this a feature request?

avatar image weatxyz · Dec 24, 2016 at 06:17 AM 0
Share

Here's a sample code snippet of what I'm doing:

 // render texture is set up as an ARGB32 with 32 bit depth
 CameraRef.targetTexture = renderTexture;
 
 // render the colors to ARGB and should automatically render to 32 bit depth
 CameraRef.Render();

 // assign the awesomeEffectShader to the camera that renders the awesome effect
 CameraAwesomeEffect.SetReplacementShader(awesomeEffectShader, "RenderType");

 // set renderTexure like usual to be used as an ARGB texture
 Shader.SetGlobalTexture("_$$anonymous$$ainTex", renderTexture);

 // I need access to the depth texture so I can use it in my shader, but where is it?
 Shader.SetGlobalTexture("_DepthTex", ???);

 // render awesome effect
 CameraAwesomeEffect.Render();

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

AOV depth recorder not working 0 Answers

Pre-rendered backgrounds with depth map in LWRP? 0 Answers

I'm trying to calculate the world-space position in a shader using the camera's depth buffer. I'm getting values that vary a lot based on the camera's rotation. Why? 1 Answer

How draw only on object behind another object(like stencils)? (Using Ink Painter Asset) 1 Answer

Two fog color in the same scene 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges