Welcome to the Oculus Developer Forums!

Your participation on the forum is subject to the Oculus Code of Conduct.

In general, please be respectful and kind. If you violate the Oculus Code of Conduct, your access to the developer forums may be revoked at the discretion of Oculus staff.

Mip Map Bias workaround for Android (Unity)

JepplenJepplen Posts: 21
NerveGear
Hello,

According to this Oculus blogg guide, setting the texture.MipMapBias to -0.7 is a recommended setting to keep the texture relatively sharp.
Google this: ( I can't post links )
common-rendering-mistakes-how-to-find them-and-how-to-fix-them

But as far as I can make out of the unity documentation, Android builds for such as Oculus GO and Quest, does not support this feature.

I am looking for a work around for Android in Unity.

Does anyone have any ideas?

Comments

  • JepplenJepplen Posts: 21
    NerveGear

    I found a an excellent solution that works right out of the box.
    By Correia55
    Unfortunately I can't post links, you can find their Unity Answer by googling the following string:
    sprites-and-mip-maps-in-android-vs-ios

    Basically Android and IOS supports MipMapBias when it goes via a custom shader.
    Correia55 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!!


    Here is the shader code:
    1. Shader "Sprites/Modified"
    2. {
    3. Properties
    4. {
    5. [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
    6. _Color ("Tint", Color) = (1,1,1,1)
    7. _MainTexBias ("Mip Bias (-1 to 1)", float) = -0.65
    8. [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
    9. }
    10. SubShader
    11. {
    12. Tags
    13. {
    14. "Queue"="Transparent"
    15. "IgnoreProjector"="True"
    16. "RenderType"="Transparent"
    17. "PreviewType"="Plane"
    18. "CanUseSpriteAtlas"="True"
    19. }
    20. Cull Off
    21. Lighting Off
    22. ZWrite Off
    23. Blend One OneMinusSrcAlpha
    24. Pass
    25. {
    26. CGPROGRAM
    27. #pragma vertex vert
    28. #pragma fragment frag
    29. #pragma multi_compile _ PIXELSNAP_ON
    30. #pragma shader_feature ETC1_EXTERNAL_ALPHA
    31. #include "UnityCG.cginc"
    32. struct appdata_t
    33. {
    34. float4 vertex : POSITION;
    35. float4 color : COLOR;
    36. float2 texcoord : TEXCOORD0;
    37. };
    38. struct v2f
    39. {
    40. float4 vertex : SV_POSITION;
    41. fixed4 color : COLOR;
    42. float2 texcoord : TEXCOORD0;
    43. };
    44. fixed4 _Color;
    45. v2f vert(appdata_t IN)
    46. {
    47. v2f OUT;
    48. OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex);
    49. OUT.texcoord = IN.texcoord;
    50. OUT.color = IN.color * _Color;
    51. #ifdef PIXELSNAP_ON
    52. OUT.vertex = UnityPixelSnap (OUT.vertex);
    53. #endif
    54. return OUT;
    55. }
    56. sampler2D _MainTex;
    57. sampler2D _AlphaTex;
    58. half _MainTexBias;
    59. fixed4 SampleSpriteTexture (float2 uv)
    60. {
    61. fixed4 color = tex2D (_MainTex, uv);
    62. #if ETC1_EXTERNAL_ALPHA
    63. // get the color from an external texture (usecase: Alpha support for ETC1 on android)
    64. color.a = tex2D (_AlphaTex, uv).r;
    65. #endif //ETC1_EXTERNAL_ALPHA
    66. return color;
    67. }
    68. fixed4 frag(v2f IN) : SV_Target
    69. {
    70. fixed4 c = tex2Dbias(_MainTex, half4(IN.texcoord.x, IN.texcoord.y, 0.0, _MainTexBias)) * IN.color;
    71. c.rgb *= c.a;
    72. return c;
    73. }
    74. ENDCG
    75. }
    76. }
    77. }
Sign In or Register to comment.