Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 correia55 · Jul 08, 2016 at 12:15 PM · androidiosspritemipmaps

Sprites and Mip Maps in Android vs iOS

We are currently developing a 2D game in Unity for both Android and iOS.

After going through all the trouble of manually converting every image into a POT, allowing for PVRTC compression in iOS. Our current problem is to ensure that the graphics quality is good and similar in both platforms.

So far the best solution we found was to use mip maps in Android and not use them in iOS. This has two major disadvantages which is the need to two different configurations for each image, as the Mip maps option is not overridable for a specific platform; and that they both look different, but better than using one configuration in both.

Below we attached images that show the differences with and without mip maps in both platforms.

Thank you in advance.

alt text

alt text

android.png (12.0 kB)
ios.png (41.8 kB)
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
1
Best Answer

Answer by correia55 · Jul 24, 2016 at 10:09 AM

The solution we found was to create our own shader, which included "tex2Dbias". We modified the sprites-default shader to add this option.

In case someone else needs it, here's the complete shader, based on the article by bluescrn from http://inverseblue.com/?p=287:

 Shader "Sprites/Modified"
 {
     Properties
     {
         [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
         _Color ("Tint", Color) = (1,1,1,1)
         _MainTexBias ("Mip Bias (-1 to 1)", float) = -0.65
         [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
     }
 
     SubShader
     {
         Tags
         { 
             "Queue"="Transparent" 
             "IgnoreProjector"="True" 
             "RenderType"="Transparent" 
             "PreviewType"="Plane"
             "CanUseSpriteAtlas"="True"
         }
 
         Cull Off
         Lighting Off
         ZWrite Off
         Blend One OneMinusSrcAlpha
 
         Pass
         {
         CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             #pragma multi_compile _ PIXELSNAP_ON
             #pragma shader_feature ETC1_EXTERNAL_ALPHA
             #include "UnityCG.cginc"
             
             struct appdata_t
             {
                 float4 vertex   : POSITION;
                 float4 color    : COLOR;
                 float2 texcoord : TEXCOORD0;
             };
 
             struct v2f
             {
                 float4 vertex   : SV_POSITION;
                 fixed4 color    : COLOR;
                 float2 texcoord  : TEXCOORD0;
             };
             
             fixed4 _Color;
 
             v2f vert(appdata_t IN)
             {
                 v2f OUT;
                 OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex);
                 OUT.texcoord = IN.texcoord;
                 OUT.color = IN.color * _Color;
                 #ifdef PIXELSNAP_ON
                 OUT.vertex = UnityPixelSnap (OUT.vertex);
                 #endif
 
                 return OUT;
             }
 
             sampler2D _MainTex;
             sampler2D _AlphaTex;
             half _MainTexBias;
 
             fixed4 SampleSpriteTexture (float2 uv)
             {
                 fixed4 color = tex2D (_MainTex, uv);
 
 #if ETC1_EXTERNAL_ALPHA
                 // get the color from an external texture (usecase: Alpha support for ETC1 on android)
                 color.a = tex2D (_AlphaTex, uv).r;
 #endif //ETC1_EXTERNAL_ALPHA
 
                 return color;
             }
 
             fixed4 frag(v2f IN) : SV_Target
             {
                 fixed4 c = tex2Dbias(_MainTex, half4(IN.texcoord.x, IN.texcoord.y, 0.0, _MainTexBias)) * IN.color;
                 c.rgb *= c.a;
                 return c;
             }
         ENDCG
         }
     }
 }
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 jeppe79 · May 24, 2020 at 09:52 AM 0
Share

This was exactly what I was looking for, thank you for posting it!!!!

avatar image Aupuma · Oct 26, 2020 at 11:30 AM 0
Share

Hi, how could I apply this code to a standard/PBR shader? (I don't know much about editing shaders...)

avatar image
0

Answer by Jessespike · Jul 08, 2016 at 05:07 PM

The texture importer doesn't have a platform specific option for mip-maps, but this can still be achieved. There's a property called mipMapBias, that controls when mip-maps are used depending on the distance from the camera. Lesser bias will instruct the texture to use mip-maps at further distances.

 public float mipMapBiasForIos = -1000f;
 void Awake () {
     if (Application.platform == RuntimePlatform.IPhonePlayer) //iOS
     {
         GetComponent<Renderer>().material.mainTexture.mipMapBias = mipMapBiasForIos;
     }
 }


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 correia55 · Jul 24, 2016 at 09:10 AM 0
Share

After trying your solution, nothing seemed to change.

We then discovered this in the Texture.mip$$anonymous$$apBias scripting page: "Also note that mip map bias does not work with ... some platforms, e.g., OpenGL ES based do not support it without custom shaders.", which seems to explain why it didn't seem to work on Android or iOS.

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

6 People are following this question.

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

Related Questions

MipMapBias not working on mobile 1 Answer

GUITexture with Sphere Collider 2 Answers

Resources.asset huge after iOS install. 0 Answers

Record a video from camera 3 Answers

How do i make a variable that wont change when i re-open the app 3 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