• 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
Question by pajamajama · Aug 28, 2013 at 10:04 PM · shaderiosopenglopengl es2.0

Shader on IOS turns dark

I'm porting a game to IOS and one of my shaders is giving me a headache. Thank you for taking the time to help me out on this.

The attached image is of what the shader looks like on the computer (left), and what it looks like on the IPad (right). For the IPad It seems to be losing some of its transparency, turning those pixels black. Strangely though it isn't losing all of it's transparency as you can see towards the center.

alt text

I'm using IOS 6, Unity 4, and OpenGL ES 2 Here's the shader in question:

 Shader "Shield"
 {
 
 Properties
 {
     _Color("_Color", Color) = (0.0,1.0,0.0,1.0)
     _Inside("_Inside", Range(0.0,2.0) ) = 0.0
     _Rim("_Rim", Range(0.0,2.0) ) = 1.2
     _Texture("_Texture", 2D) = "white" {}
     _Speed("_Speed", Range(0.5,5.0) ) = 0.5
     _Tile("_Tile", Range(1.0,10.0) ) = 5.0
     _Strength("_Strength", Range(0.0,5.0) ) = 1.5
 }
    
 SubShader
 {
     Tags
     {
         "Queue"="Transparent+2"
         "IgnoreProjector"="True"
         "RenderType"="Transparent"
 
     }
     
     Pass{
         ZWrite On
         ColorMask 0 
     
     }
 
        
 Cull Back
 ZWrite On
 ZTest LEqual
 
 
 CGPROGRAM
 #pragma surface surf BlinnPhongEditor alpha vertex:vert
 //#pragma target 3.0
 
 
 fixed4 _Color;
 sampler2D _CameraDepthTexture;
 fixed _Inside;
 fixed _Rim;
 sampler2D _Texture;
 fixed _Speed;
 fixed _Tile;
 fixed _Strength;
 
 struct EditorSurfaceOutput
     {
         half3 Albedo;
         half3 Normal;
         half3 Emission;
         half3 Gloss;
         half Specular;
         half Alpha;
     };
            
 inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
 {
     half3 spec = light.a * s.Gloss;
    
     half4 c;
    
     c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
    
     c.a = s.Alpha + Luminance(spec);
    
     return c;
 
 
 }
 
 inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
 {
     viewDir = normalize(viewDir);
     half3 h = normalize (lightDir + viewDir);
    
     half diff = max (0, dot (s.Normal, lightDir));
    
     float nh = max (0, dot (s.Normal, h));
     float3 spec = pow (nh, s.Specular*128.0) * s.Gloss;
    
     half4 res;
     res.rgb = _LightColor0.rgb * (diff * atten * 2.0);
     res.w = spec * Luminance (_LightColor0.rgb);
 
     return LightingBlinnPhongEditor_PrePass( s, res );
 }
 
 struct Input
 {
     float4 screenPos;
     float3 viewDir;
     float2 uv_Texture;
 };
 
 
 void vert (inout appdata_full v, out Input o)
 {
 
 }
            
 
 void surf (Input IN, inout EditorSurfaceOutput o)
 {
     o.Albedo = fixed3(0.0,0.0,0.0);
     o.Normal = fixed3(0.0,0.0,1.0);
     o.Emission = 0.0;
     o.Gloss = 0.0;
     o.Specular = 0.0;
     o.Alpha = 1.0;
     float4 ScreenDepthDiff0= LinearEyeDepth (tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(IN.screenPos)).r) - IN.screenPos.z;
     float4 Saturate0=fixed4(0.3,0.3,0.3,1.0);//
     float4 Fresnel0_1_NoInput = fixed4(0,0,1,1);
     float4 Fresnel0=float4( 1.0 - dot( normalize( float4(IN.viewDir, 1.0).xyz), normalize( Fresnel0_1_NoInput.xyz ) ) );
     float4 Step0=step(Fresnel0,float4( 1.0 ));
     float4 Clamp0=clamp(Step0,_Inside.xxxx,float4( 1.0 ));
     float4 Pow0=pow(Fresnel0,_Rim.xxxx);
     float4 Multiply5=_Time * _Speed.xxxx;
     float4 UV_Pan0=float4((IN.uv_Texture.xyxy).x,(IN.uv_Texture.xyxy).y + Multiply5.x,(IN.uv_Texture.xyxy).z,(IN.uv_Texture.xyxy).w);
     float4 Multiply1=UV_Pan0 * _Tile.xxxx;
     float4 Tex2D0=tex2D(_Texture,Multiply1.xy);
     float4 Multiply2=Tex2D0 * _Strength.xxxx;
     float4 Multiply0=Pow0 * Multiply2;
     float4 Multiply3=Clamp0 * Multiply0;
     float4 Multiply4=Saturate0 * Multiply3;
     o.Emission = Multiply3.xyz * _Color.rgb;
     o.Alpha =  Multiply3.w * _Color.a;
 
 }
 ENDCG
 }
 Fallback "Diffuse"
 }


Comment
iviaguic

People who like this

1 Show 0
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

Answer by pajamajama · Sep 01, 2013 at 06:13 PM

The problem was that my alpha channel was being pre-multiplied. I was able to resolve it by using Alpha From Grayscale instead of from Alpha Channel.

I hope this helps other people with the same problem!

Comment

People who like this

0 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

[iOS] Metal API looks good, OpenGL doesnt 1 Answer

iOS Custom Specular Shader 2 Answers

Standard Shader and Height Map on iOS using OpenGL ES 2.0 0 Answers

Black Screen Comes when building an iOS Build 1 Answer

Why Unity compiled shader doesn't use the GLSLPROGRAM/GLSL syntax? 0 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