• 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
0
Question by Doidel · Jan 10, 2018 at 07:55 AM · rendertexturedepth buffer

DepthNormals texture into custom global variable

I have a camera...

 _camera = GetComponent<Camera>();
 _camera.depthTextureMode = DepthTextureMode.DepthNormals;

...whose DepthNormals texture I use in a shader

 sampler2D _CameraDepthNormalsTexture;

Works perfectly!

But when I try to put the DepthNormalsTexture into my own global variable...

 _camera.targetTexture = new RenderTexture(_camera.pixelWidth, _camera.pixelHeight, 16, RenderTextureFormat.ARGB32);
 _camera.targetTexture.filterMode = FilterMode.Bilinear;
 Shader.SetGlobalTexture(_globalTextureName, _camera.targetTexture);

... it doesn't work. It's not the same. And I am unable to make it work in t$$anonymous$$s RenderTexture + SetGlobalTexture way.

What I've tried so far:

  • Various sorts of RenderTexture formats

  • Assign the camera's RenderTexture directly to the shaders using them. T$$anonymous$$s also behaved weirdly, that's why my guess is that my RenderTexture has different contents from _CameraDepthNormalsTexture.

    Any help is greatly appreciated!

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by StarkeyBoy · Apr 12, 2018 at 08:05 AM

@Doidel

When the camera renders to a texture, it renders what it can see (based on the applied culling mask filters) NOT the depth normals. You access the depth and normal data from wit$$anonymous$$n the shader using the inbuilt _CameraDepthNormalsTexture variable (w$$anonymous$$ch gives access to the GBuffer from the GPU side).

The only time that I've seen the shader variable being accessed outside the GPU is to pass them into a compute shader. If you are using compute shaders you have to pass t$$anonymous$$s into the shader ComputeShader.SetTextureFromGlobal(CSMainkernalID, "_DepthNormalsTexture", "_CameraDepthNormalsTexture");

Hope t$$anonymous$$s helps.

Comment
Add comment · 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
0

Answer by Doidel · Apr 13, 2018 at 08:03 AM

Thanks for your explanation @StarkeyBoy!
I am not using a compute shader. Instead, in my forward rendering setup, I have a surface shader w$$anonymous$$ch accesses the _CameraDepthNormalsTexture of a camera A with depth -1. There is also a camera B with depth 0 around, but like t$$anonymous$$s, the surface shader uses camera A's _CameraDepthNormalsTexture.

Now if I switch the forward rendering setup to a deferred one, the surface shader doesn't work out of the box anymore. T$$anonymous$$s didn't come as a surprise to me, and I thought the easiest way to circumvent t$$anonymous$$s is to simply draw the camera's rendered depth and normal data (GBuffer) to a texture and then just reference that texture in my surface shader. After all, since I can do that with an albedo texture, why not with the depthNormals texture.

Should I also use somet$$anonymous$$ng like MySurfaceShader.SetTextureFromGlobal(SSMainkernalID, "_DepthNormalsTexture", "_CameraDepthNormalsTexture"); or do you have a suggestion how I can make sure that my surface shader has access to camera A's GBuffer (w$$anonymous$$ch btw indeed has a specific culling mask)?

Thanks again for your effort, much appreciated!

Comment
Add comment · Show 1 · 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 StarkeyBoy · Apr 15, 2018 at 04:59 PM 0
Share

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

124 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Proper SetTargetBuffers usage with Deferred rendering in unity 5.5 (possible problem?) 1 Answer

Need help with spy glass to see through objects. 1 Answer

How to capture screen, render to background, and allow both portrait and landscape on mobile device? 0 Answers

How do I add a renderTexture UI element onto my ARKit screen 0 Answers

How can a get a GUI drawn to a RenderTexture to respond to clicks .etc.? 0 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