Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Impersivevr · Mar 04, 2020 at 12:31 PM · shadershadersalphashader writingdepthmask

Depth mask with alpha / adding alpha to frag grabpass shader

I'm trying to get a depth mask shader to get alpha blending, to no avail.

The problem I'm trying to solve is to be able to fade out multiple objects with different types of renderers with complicated geometry like it were a group on photoshop, i.e. all at the same time, no double rendering of hidden tris, without having to calculate complicated alpha/z buffer or bother with cull masks etc.

Since my scene is very simple, I thought of using a plane that occludes the objects with a depth mask shader, but a normal depth mask shader just won't both be able to draw over an object while at the same time having alpha for queue ordering reasons (or at least, this is the conclusion I've come to).

So my plan has changed to making a grabpass of the background (I'm trying to fade to the skybox for now) and then applying the resulting texture to the plane and applying alpha. I've been trying to do so for the past week. By setting the geometry I need to fade to a cool queue 3000 and making the shader transparency -1, I'm able to make the grabpass before the geometry has rendered. Then I make a Zwrite on pass, enable alpha blending and just project the pixels I grabbed before while adding alpha... but no matter what I do, the end result will be a) always opaque b) instead of fading to transparent, fades to black/white c) always transparent This is how it is right now: almost there, but the alpha won't affect the end result at all. alt text

Here's the shader – what am I getting wrong?

 Shader "Custom/Maskv5"
 {
     Properties 
     { _Color ("Color", Color) = (0.5, 0.5, 0.5, 0.5) } 
     SubShader
     {
 
         Tags { "Queue" = "Transparent-1"}
 
         // Grab the screen behind the object into _BackgroundTexture
         GrabPass
         {
             "_BackgroundTexture"
         }
         // Render the object with the texture generated above and apply alpha
 
         ZWrite On
         Pass
         {
             Blend SrcAlpha OneMinusSrcAlpha
 
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag alpha
 
             #include "UnityCG.cginc"
             fixed4 _Color;
             struct v2f
             {
                 float4 grabPos : TEXCOORD0;
                 float4 pos : SV_POSITION;
             };
 
             v2f vert(appdata_base v) {
                 v2f o;
                 // use UnityObjectToClipPos from UnityCG.cginc to calculate 
                 // the clip-space of the vertex
                 o.pos = UnityObjectToClipPos(v.vertex);
                 // use ComputeGrabScreenPos function from UnityCG.cginc
                 // to get the correct texture coordinate
                 o.grabPos = ComputeGrabScreenPos(o.pos);
 
                 return o;
             }
 
             sampler2D _BackgroundTexture;
             half4 frag(v2f i) : SV_Target
             {
 
                 half4 bgcolor = tex2Dproj(_BackgroundTexture, i.grabPos);
                 bgcolor.a = (_Color.a);
                 return bgcolor;
             }
             ENDCG
         }
 
     }
 }   


schermata-2020-03-04-alle-132837.png (390.7 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

195 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 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

How can i add a alpha value to this shader? 1 Answer

How to add Emission to my custom shader? 2 Answers

Making shader not ignore Light on transparent areas ? 0 Answers

shader material showing over every object. 0 Answers

How to add alpha cutout shader to this curveworld shader 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