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
1
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 which fakes something 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 graphics processor, while 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 this 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) = "white" {}
         _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
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

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

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

Hey everyone,

I found what I think the issue was with this shader while working on another one.

It seems that a float can only hold a 0 -1 range on devices with the sgx535 graphics processor, while on the later processors it can hold something higher.

This 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
Add comment · 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
0

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

Thanks for the answer on this, color spaces on different devices was not something I was aware of. I'm not sure this is the problem I am experiencing, though.

I did a test by changing this line -

 o.color = light * _Color;

to this -

 o.color =  _Color;

which ignores all the lighting calculations. This shader produces the same output on all devices, which 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
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

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