- Home /
MipMapBias alternative for Android?
Hello,
As far as I have read the MipMapBias option does not work for android. Is there a work around to it?
It is for VR, the mip map looks terribly blurry, but is a must have or the aliasing will make your eyes bleed.
Hopefully someone knows of a work around.
Answer by jeppe79 · May 24, 2020 at 09:50 AM
I found a an excellent solution that works right out of the box. By Correia55 https://answers.unity.com/questions/1212923/sprites-and-mip-maps-in-android-vs-ios.html
Basically Android and IOS supports MipMapBias when it goes via a custom shader. They added the MipMapBias setting to the default Sprites/Default shader. With this you simply set the bias you want in the shader properties in the editor. Very awesome!
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
}
}
}
I do get a little problem with this shader because i can't assign a texture to it and i'm not that into shaders so that i don't really find what i'm missing.
There was this line added on top of the shader: // Upgrade NOTE: replaced 'mul(UNITY_$$anonymous$$ATRIX_$$anonymous$$VP,)' with 'UnityObjectToClipPos()'
Help
Your answer
Follow this Question
Related Questions
Poor texture quality on baking 2 Answers
blurry screen/textures patch 1 Answer
Any way to remove the texture blur on camera? 2 Answers
How to control Terrain Texture Blur at Distance (pics) 1 Answer