• 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 caseyc · Jun 02, 2012 at 08:21 AM · shaderiosmobilegpudiffuse

Different Shader Display on 3gs vs. 4s

Hey all,

I wrote a shader in cg w$$anonymous$$ch fakes somet$$anonymous$$ng similar to vertex lighting.

It works as intended in the editor, on iPad 2, new iPad, and iPhone 4s.

On the original iPad, iPhones 3gs and 4, however, it seems to work, but the "lighting" (output color) is much fainter to the point that it is almost not visible (it is there, though).

I realize that those models have the sgx535 grap$$anonymous$$cs processor, w$$anonymous$$le the others have the sgx543mp2 (mp4 for new iPad), but why would that make the shader behave differently?

I also noticed that the built - in unity shader "Mobile/Diffuse" seems to fall back to the vertex-lit shader for these devices as well, despite manually setting the shader LOD myself, not sure if t$$anonymous$$s is related at all.

Thank you for any help you can give, source for the shader follows.

 Shader "Custom/UnlitCollectable" {
     Properties {
         _MainTex ("Base (RGB)", 2D) = "w$$anonymous$$te" {}
         _Color ("Color", Color) = (1,1,1,1)
         _Length("Length", Float) = 8
     }
     SubShader {
         Tags { "RenderType"="Opaque" }
         LOD 150
         
         Pass {
             Lighting Off
             
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             
             #include "UnityCG.cginc"
     
             sampler2D _MainTex;
             fixed4 _Color;
             float4 _Position; //Set using Shader.SetGlobalVector
             fixed _Length;
     
             struct v2f {
                 float4  pos : SV_POSITION;
                 float2  uv : TEXCOORD0;
                 float4  color : COLOR;
             };
             
             float4 _MainTex_ST;
             v2f vert (appdata_base v) {
                 v2f o;
                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
                 o.uv = TRANSFORM_TEX (v.texcoord, _MainTex);
                 
                 float4 P = mul(_Object2World, v.vertex);
                 float dist = distance(P, _Position);
                 float4 L = normalize(_Position - P);
                 float3 n = mul((float3x3)_Object2World, v.normal);
                 
                 float light = dot(n, L.xyz) + ((_Length - dist) / _Length);
                 light = clamp(light, 0, 1);
                 o.color = light * _Color;
         
                 return o;
             }
             
             half4 frag (v2f i) : COLOR {
                 half4 texcol = tex2D (_MainTex, i.uv);
                 return texcol + i.color;
             }
             ENDCG
         }
     }
     
     Fallback "Mobile/Unlit (Supports Lightmap)"
 }
Comment
Fattie

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

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by caseyc · Jun 06, 2012 at 11:58 PM

Hey everyone,

I found what I t$$anonymous$$nk the issue was with t$$anonymous$$s shader w$$anonymous$$le working on another one.

It seems that a float can only hold a 0 -1 range on devices with the sgx535 grap$$anonymous$$cs processor, w$$anonymous$$le on the later processors it can hold somet$$anonymous$$ng $$anonymous$$gher.

T$$anonymous$$s is a weird behavior and as far as I know is not documented anywhere, so heads up to anyone facing the same issue.

Thanks again for the help.

Comment
Fattie
burtonposey

People who like this

2 Show 1 · 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 Fattie · Jun 07, 2012 at 06:25 AM 0
Share

an amazing tip, thanks !

avatar image

Answer by caseyc · Jun 04, 2012 at 04:47 PM

Thanks for the answer on t$$anonymous$$s, color spaces on different devices was not somet$$anonymous$$ng I was aware of. I'm not sure t$$anonymous$$s is the problem I am experiencing, though.

I did a test by changing t$$anonymous$$s line -

 o.color = light * _Color;

to t$$anonymous$$s -

 o.color =  _Color;

w$$anonymous$$ch ignores all the lighting calculations. T$$anonymous$$s shader produces the same output on all devices, w$$anonymous$$ch leads me to believe that my issue is most likely related to the lighting calculations producing different results depending on device.

Once again thank you for your help.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Snow scene is a neon blue in an iOS build, but looks normal on the computer 1 Answer

iOS Custom Specular Shader 2 Answers

Shader Fails to Compile on iOS: GL_EXT_frag_depth 2 Answers

How to create a mirror reflection for mobile devices 1 Answer

Mobile Devices - how many times can I access the same texture on a 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