Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 relativegames · Nov 25, 2013 at 05:05 AM · shaderstransparency

Shaders : Is Transparency + Depth Testing possible ?

In unity I'm using CG Shaders and I want to fade objects in. There's a slight problem/pop-in/glitch when going from a shader that has depth testing enabled to a shader that has alpha blending on.

From the pragma flags in a CGPROGRAM I can only enable/disable alpha blending, but this turns off depth testing. I want to keep depth testing on, so my fading is smooth (and I only get the front faces of objects rendered, not backfaces too, like it seems to be the default when blending is on). All the other standard "shader" flags like ZTest do not seem to affect shaders written with CGPROGRAMs, nor does ZTest configure wether depth testing is on or off.

Another question I'd have is if I can control the color mask ?(i.e. glColorMask).

Is there any other way to control render states besides shaders ?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by relativegames · Nov 26, 2013 at 11:44 PM

Got my answer, the issue is CGPROGRAM + Surface "shaders". If you use the surface function path that adds in extra shader code behind the curtains about lights & shadows, you get your render states overwritten. So anything like

Blend SrcAlpha OneMinusSrcAlpha
ZTest Always
ZWrite Off

will get overwritten. What you need to do is provide full vertex & fragment shaders and probably reproduce Unity default functionality (lights & shadows).

Note that because of this there's 2 distinct ways to write CGPROGRAMs, one major difference being the extra "Pass {" bracket which is not required when writting "surface shaders".

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

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

16 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

Related Questions

Shader that makes object transparent as light hits it 0 Answers

Don't render an Area behind a plane 0 Answers

Fading objects to transparent - Apply shader with a script? 2 Answers

Transparent + affected by light shader 1 Answer

What is happening with sprite transparency in the standard shader in unity 5.6? 1 Answer


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