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 AlexEvangelou · Mar 21, 2013 at 11:51 PM · shaderioscg

Shader no longer working on iOS

I have this shader I wrote (probably horribly, first time I've written a shader) which gets put on a plane and masks off most of the screen except a transparent circle based on the position of a light object. In the previous build on iOS it worked fine, I upgraded to 4.1, rewrote some of the math to add more knobs to tweak with and now it's not working on iOS. It works perfectly fine on Desktop in the simulator. Anyone know what might be causing it to misbehave? Not sure if there's some CG function or setting I'm using that iOS doesn't support.

 Shader "Masked/Mask" {
 
     Properties {
         _Color ("Main Color", Color) = (1,1,1,1)
         _LightPos ("Light Position", vector) = (0,0,0)
         _LightStr ("Light Strength", Float) = 50.0
         _MaxLightFalloff ("Max Light Falloff", Range (0.0, 1.0)) = 1
         _MinLightFalloff ("Min Light Falloff", Range (0.0, 1.0)) = 0
         _MaxLightRadius ("Max Light Radius", Float) = 3.0
         _MinLightRadius ("Min Light Radius", Float) = 0.5
     }
     
     SubShader {
         Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
         Blend SrcAlpha OneMinusSrcAlpha 
     
         //Unneeded features
         Cull Off Lighting Off ZWrite Off Fog { Mode Off }
          
         Pass {
             CGPROGRAM
 
             // Upgrade NOTE: excluded shader from DX11 and Xbox360; has structs without semantics (struct v2f members vertexWorldCoord)
             #pragma exclude_renderers d3d11 xbox360 d3d11_9x
 
             #pragma vertex vert
             #pragma fragment frag
  
             #include "UnityCG.cginc"
              
              fixed4 _Color;
             fixed4 _LightPos;
             fixed _LightStr;
             fixed _MaxLightFalloff;
             fixed _MinLightFalloff;
             fixed _MaxLightRadius;
             fixed _MinLightRadius;
              
              // TANH Function (Hyperbolic Tangent)
             float tanh(float val)
             {
                  float tmp = exp(val);
                 float tanH = (tmp - 1.0 / tmp) / (tmp + 1.0 / tmp);
                 return tanH;
             }
              
             //Vertex Shader Input / Output
             struct a2v {
                 float4 vertex : POSITION;
             };
             
             //Fragment Shader Input
             struct v2f {
                 float4 vertexWorldCoord;
                 float4 pos : POSITION;
             };
             
             //Vertex Shader
             v2f vert (a2v v) {
                 v2f o;
                 o.pos = mul( UNITY_MATRIX_MVP, v.vertex);
                 o.vertexWorldCoord = mul(_Object2World,v.vertex);
                 return o;
             }
              
              //Fragment Shader
             float4 frag(v2f i) : COLOR {
                 float4 c = _Color;
                 
                 //Distance the fragment is from the light source
                 float fragmentDistance = clamp(distance(_LightPos,i.vertexWorldCoord),0.0f,_LightStr);
                 
                 //The radius the light should reach given the depth
                 float lightRadius = (_MaxLightRadius-_MinLightRadius)*saturate((_LightStr+_LightPos.y)/_LightStr) + _MinLightRadius;
                 float falloff = (_MaxLightFalloff-_MinLightFalloff)*saturate((_LightStr+_LightPos.y)/_LightStr) + _MinLightFalloff;
                 
                 //Transition function for light falloff
                 float shift = lightRadius * falloff;
                 float scale = clamp(lightRadius * 1.0 - falloff,1,lightRadius);
                 
                 c.a *= saturate((tanh(4.0*((fragmentDistance-shift)/scale)-2.0)+1.0)/2.0);
           
                 return c;
             }
                     
              ENDCG
          }
     }
 }
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
Best Answer

Answer by AlexEvangelou · Mar 28, 2013 at 07:02 PM

Solved the problem. It had to do with precision. Made sure the precision values were correct and it was fine.

Comment
Add comment · Show 2 · 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
avatar image mtalbott · Jul 23, 2013 at 02:32 PM 0
Share

Can you elaborate on what precision values were incorrect. I am having a similar issue but do not know CG well enough to debug. Thanks.

avatar image kiwimatt001 · Dec 02, 2014 at 03:54 PM 0
Share

Yes, please say what you changed!!! Pleeeeeeeeeease

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

11 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

Related Questions

What rules govern backface culling on IOS hardware? 0 Answers

Multiple tex2D commands in fragment shader needed, is there a workaround? 0 Answers

Shader fails on iOS 0 Answers

Why does this IOS / OGLES shader not match PC version? 0 Answers

How to force the compilation of a shader in Unity? 5 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