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 /
avatar image
0
Question by scraft · Nov 21, 2016 at 10:45 AM · shaderrenderingtransparentdepthqueue

Transparency shader that also writes to Camera Depth Texture

We have a game which is set in a 3D world, and the character graphics are 2D (as in made of Sprites, with transparency) the net effect is something similar to Paper Mario. In the world, we have some spherical fog, the way this effect is achieved is that opaque geometry gets rendered into the Camera Depth Texture (as a separate pass), the scene is then rendered (opaque first, then transparent) and then at the end the spherical fog volume is rendered (in the transparent pass), it does this by basically seeing where each pixels depth is, in relation to the fog centre, and based on that adding in some fog colour. For the scene this works great.

For the characters, the amount of fog which gets added on is incorrect, as the player isn't being added to the Camera Depth Texture (from our tests, it appears impossible to do this if you also want transparency support). Our characters transparency is more or less 'on/off' information (this isn't quite true, as there is blending on the edges to avoid jaggies), but if we force the character to be opaque, so it renders into the Camera Depth Texture, we can use a low alpha cut off value so the render to the Camera Depth Texture looks as we want, the fogging will then in turn render correctly, however our character will then be opaque. We can set the shader to be in the alpha test queue, which allows us to get a correctly fogged character, but with jagged edges. What we really want to do is have:

  1. The character render into the Camera Depth Texture render pass

  2. The character be rendered in the transparent render pass

So far we haven't found a way to achieve this; it appears to be impossible to write a shader which will add passes both to the Camera Depth Texture and Transparent. As a proof of concept, we attached two materials to one mesh, set each material to use a different shader, one which only renders into the Camera Depth Texture, and one that only renders in the Transparent pass and it does achieve the end result we want (see image, notice alpha blending on players leg in first image and 'normal' levels of fog, the second half of the image is with the fog value cranked crazy high), but it is not easy for us to do this in game (as our characters are rendered with Spine a 2D animation package + Unity Runtime, and it doesn't support having multiple materials per mesh).

Is there a way to coax Unity into allowing a shader to render to Camera Depth Texture + Transparent?

alt text

foggingwithtransparency.jpg (496.8 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Shader depth order 0 Answers

Multiple RenderTexture and depth buffer 1 Answer

Is it possible to create a depth render of scene using a replacement shader? 0 Answers

When only need depth texture 0 Answers

Transparent shader (water) showing over billboard trees 4 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