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 arachnid · Aug 10, 2012 at 05:30 PM · shadercgglslzwrite

Shader problem with alpha blend and zwrite iOS

I am trying to get some characters rendering correctly while moving in front of and behind eachother. This is how the character should look normally:

alt text

This is how they look with overlap:

alt text

Currently, the red character on the right is closer to the camera and the body is correctly rendering on top of the orange body, but the mouth of the orange character shows through which is the problem.

The distance from the camera for the orange one is 200 with its eyes and mouth at 195. The distance from the camera for the red one is 170 with eyes and mouth at 165

I would like all of the the composed orange character to show behind the red character.

I have also tried the shader below with ZWrite On but that causes the entire eyes/mouth not to render at all when the other alien is on top.

Any help would be greatly appreciated!

Here is the shader I am using currently using:

Code:

 Shader "CustomGradientShader"
 {  
  Properties
   {
     _MainTex( "Particle Texture", 2D ) = "white" {}
   }
     SubShader
     {
         Tags { "RenderType"="Transparent"}  
         Tags { "Queue" = "Transparent+1" }  
         Blend SrcAlpha OneMinusSrcAlpha
         AlphaTest Off
         ColorMask RGB
         Cull Off
         Lighting Off
         ZWrite Off
         Fog {Mode Off}
         pass
         {
             CGPROGRAM
             #pragma vertex wfiVertCol
             #pragma fragment passThrough
             #include "UnityCG.cginc"
  
  
  
             sampler2D _MainTex;
            
             struct VertOut
             {
                 float4 position : POSITION;
                 float2 uv : TEXCOORD0;
                 float4 color : COLOR;
             };
  
             struct VertIn
             {
                 float4 vertex : POSITION;
                 float4 color : COLOR;
                 float4 texcoord : TEXCOORD0;
             };
            
             float4 _MainTex_ST;
  
             VertOut wfiVertCol(VertIn input, float3 normal : NORMAL)
             {
                 VertOut output;
                 output.position = mul(UNITY_MATRIX_MVP,input.vertex);
                 output.color = input.color;
                 output.uv = TRANSFORM_TEX (input.texcoord, _MainTex);
                 return output;
             }
  
             struct FragOut
             {
                 float4 color : COLOR;
             };
  
             FragOut passThrough(VertOut vertexOut)
             {
                 FragOut output;
                
                 float4 texColor = tex2D(_MainTex, vertexOut.uv);
                
                 float r = texColor[0]+(1-(texColor[0]/1))*vertexOut.color[0];
                 float g = texColor[1]+(1-(texColor[1]/1))*vertexOut.color[1];
                 float b = texColor[2]+(1-(texColor[2]/1))*vertexOut.color[2];
                
                 output.color = float4(r,g,b,texColor[3]);
                
                
                 return output;
             }
             ENDCG
  
         }
     }
     FallBack "Diffuse"
 }


Comment
Add comment · Show 3
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 ScroodgeM · Aug 10, 2012 at 06:28 PM 0
Share

does eyes and mouth uses this (not similar!) shader?

avatar image arachnid · Aug 11, 2012 at 05:40 PM 0
Share

Yes they all use this exact shader. I have also tried creating a separate shader for the eyes and mouth which didn't seem to have any effect.

avatar image ScroodgeM · Aug 13, 2012 at 10:03 PM 0
Share

hmm... could you make a package with this example to reproduce it?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Dragonlance · Aug 13, 2012 at 11:28 PM

I am not sure about your initial problem, but you can make the shader perform a lot better with

     if(texColor[0] != 0.0)
     {
        float r = texColor[0]+(1-(texColor[0]/1))*vertexOut.color[0];
        float g = texColor[1]+(1-(texColor[1]/1))*vertexOut.color[1];
        float b = texColor[2]+(1-(texColor[2]/1))*vertexOut.color[2];
        output.color = float4(r,g,b,texColor[3]);
     }
     else
     {
         output.color = float4(0, 0, 0, 0);
     }

What does that do? texColor[0]/1


About the eye and mouth problem.

Looks like you use z distance to order the guys for the orthographic camera. To avoid z-fight you surely popped the mouth and eyes out a put. Maybe that distance was to far and they came in front of the guys?

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

9 People are following this question.

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

Related Questions

Cg Language incompatibility Desktop VS GLSL Android 0 Answers

Grabpass refraction masking 0 Answers

How to prevent shader optimizations? 1 Answer

CG compiled to GLSL: hyperbolic functions not found. 0 Answers

Sizeof float in cg 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