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 MaxMonahs · May 10, 2016 at 05:51 AM · shadertransparencyblendingocclusionalpha-channel

Transparency and blending issues with custom-made shader

Hi Unity Community!

I am facing an issue involving transparency and blending. I know the theory on transparency and the rendering pipeline, but I am not an expert. The problem:

I am drawing some geometry shader custom made cubes over a textured quad in Unity: alt text

When I change the color alpha value in the fragment shader, it looks like this: alt text It behaves like blending color is the camera's background color (white)

So I've tried playing with the z buffer and disabling simply occlude my cubes.

Here is my [simplified] shader code:

Properties { _SpriteTex ("RGBA Texture Image", 2D) = "white" {} _Size ("Size", Range(0, 30)) = 0.5 _IndexPos ("IndexPos", Vector) = (15.0,15.0,15.0,15.0) _X("X",Float) = 15.0 _Y("Y",Float) = 15.0 _Z("Z",Float) = 15.0 _BrushSize("BrushSize",Float) = 0.05 _MinD0("MinD0",Float) = 0 _MaxD0("MaxD0",Float) = 0 _MinD1("MinD1",Float) = 0 _MaxD1("MaxD1",Float) = 0 _Alpha("Alpha", Float) = 0 }

 SubShader 
 {
     Pass
     {
         
         LOD 400

         Tags
         {
         "Queue" = "Transparent"
         "IgnoreProjector" = "True"
         "RenderType" = "Transparent"
         }
                     
         Blend SrcAlpha OneMinusSrcAlpha 
         Lighting Off
         //ZWrite Off
         Cull Off
         AlphaTest Greater 0
         
     
         CGPROGRAM
             #pragma target 5.0
             #pragma vertex VS_Main
             #pragma fragment FS_Main
             #pragma geometry GS_Main
             #include "UnityCG.cginc" 

             // **************************************************************
             // Data structures                                                *
             // **************************************************************
             
             struct VS_INPUT {
                   float4 position : POSITION;
                 float4 color: COLOR;
                 float4 normal:    NORMAL;
             };
             
             struct GS_INPUT
             {
                 float4    pos        : POSITION;
                 float3    normal    : NORMAL;
                 float2  tex0    : TEXCOORD0;
                 float4  col        : COLOR;
                 float    isBrushed : FLOAT;
             };

             struct FS_INPUT
             {
                 float4    pos        : POSITION;
                 float2  tex0    : TEXCOORD0;
                 float4  col        : COLOR;
                 float    isBrushed : FLOAT;
             };


             // **************************************************************
             // Vars                                                            *
             // **************************************************************

             float _Size;
             float4 _IndexPos;
             float _X;
             float _Y;
             float _Z;
             float _BrushSize;
             
             //*******************
             // DIMENSIONS
             //*******************

             float _MinD0;
             float _MaxD0;
             float _MinD1;
             float _MaxD1;
             float _Alpha;

             float4x4 _VP;
             Texture2D _SpriteTex;
             SamplerState sampler_SpriteTex;

             //*********************************
             // helper functions
             //*********************************

             float normaliseValue(float value, float i0, float i1, float j0, float j1)
             {
             float L = (j0 - j1) / (i0 - i1);
             return (j0 - (L * i0) + (L * value));
             }


             // Vertex Shader ------------------------------------------------
             GS_INPUT VS_Main(VS_INPUT v)
             {
                 [my geometry shader code...]
             }

             // Fragment Shader -----------------------------------------------
             float4 FS_Main(FS_INPUT input) : COLOR
             {
             
             if (input.isBrushed == 1.0)
             _Alpha=1.0;

             float4 colorReturn = float4(input.col.x*100.0, 0.0, 0.0, _Alpha);                
             return colorReturn; //ambient+diffuse*saturate(dot(Light,Norm));
         
             }
         

         ENDCG
     }

}

I read somewhere to change the rendering queue should be set to a number higher than 3000 (e.g, 3001). I did that and did not see a difference.

Any help is more than welcome!

Thanks for your help Unity Community :-)

semi-opaque.png (112.3 kB)
fully-transparent.png (112.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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MaxMonahs · May 24, 2016 at 04:17 AM

Ok I solved the problem: if you want to draw custom semi-opaque meshes with your own shaders, just disable the z-buffer on the other objects.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Transparent Fresnel Shader Sometimes Obscuring Objects 1 Answer

Can we change the color on my Virtual Object on AR Foundation ?,Can we change color on AR Foundation with a button or touch ? 1 Answer

Silhouette overlay shader 0 Answers

Unity's default shaders' blending is messed up? 1 Answer

Cutout Shader getting Opaque when turning alpha off and on again 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