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 gCave · Mar 11, 2016 at 01:21 PM · androidshadershaderslod

My shader's LOD levels arn't respected when I run my game on android tablets or phones

I've made a shader with LOD levels. The shader is suppose to be able to change during run-time from using alpha test to using Alpha blend depending on the quality of the android tablet my game is running on. But strangely android devices just ignore the LOD levels and just display the alpha blend version even if I forced the LOD level so the shader uses the alpha test SubShader. My shader works perfectly in the editor. Also I made sure it was actually possible to use the alpha test shader alone on the Android devices and it worked. It realy seems to be the LOD levels that don't work. I could try to do what I'm trying to do by just changing the shader my materials are using during run-time but this isn't practical because I have hundreds of materials spread thru the project that use this shader. Thanks in advance for any help.Ill take anything.

Im using unity 5.3.1 p3.

Hear is the code I use on a script out of the shader to change the LOD levels.

 SpriteVariableLODshader.maximumLOD = 100;

This is the code of the shader I use:

 Shader "Neopica/SpriteLODvariable"
 {
     Properties
     {
         _MainTex("Sprite Texture", 2D) = "white" {}
         _Color("Main Color", Color) = (1,1,1,1)
     }
 
     SubShader
     {
     LOD 200
     Tags
     {
         "Queue" = "Transparent"
         "IgnoreProjector" = "True"
         "RenderType" = "Transparent"
     }
         
         Cull Off
         Lighting Off
         ZWrite Off
         ZTest Off
         Blend SrcAlpha OneMinusSrcAlpha
         Pass
         {
             
                 CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             #pragma fragmentoption ARB_precision_hint_fastest
             #include "UnityCG.cginc"
             
             
             sampler2D _MainTex;
             float4 _MainTex_ST;
             fixed4 _Color;
             uniform float _Frequency;
             uniform float _Speed;
             uniform float _Amplitude;
             uniform float _Progress;
 
             struct appdata_t
             {
                 float4 vertex   : POSITION;
                 float2 texcoord : TEXCOORD0;
             };
             
             struct v2f
             {
                 float4 vertex        : POSITION;
                 float2 texcoord      : TEXCOORD0;
             };
             
             v2f vert(appdata_t IN)
             {
                 v2f OUT;
                 OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex);
                 OUT.texcoord = TRANSFORM_TEX(IN.texcoord, _MainTex);
                 return OUT;
             }
             
             fixed4 frag(v2f IN) : COLOR
             {
                 fixed4 col = tex2D(_MainTex, IN.texcoord) * _Color;
                 return col;
             }
             ENDCG
         }
     }
     SubShader
     {
      LOD 100
         Tags
         {
             "Queue" = "Transparent"
             "IgnoreProjector" = "True"
             "RenderType" = "Transparent"
         }
         
         Cull Off
         Lighting Off
         ZWrite Off
         ZTest Off
         Fog{ Mode Off }
         
         Pass
         {
 
         CGPROGRAM
         #pragma vertex vert
         #pragma fragment frag
         #pragma fragmentoption ARB_precision_hint_fastest
         #include "UnityCG.cginc"
 
 
         sampler2D _MainTex;
         float4 _MainTex_ST;
         fixed4 _Color;
         uniform float _Frequency;
         uniform float _Speed;
         uniform float _Amplitude;
         uniform float _Progress;
 
         struct appdata_t
         {
             float4 vertex   : POSITION;
             float2 texcoord : TEXCOORD0;
         };
 
         struct v2f
         {
             float4 vertex        : POSITION;
             float2 texcoord      : TEXCOORD0;
         };
 
         v2f vert(appdata_t IN)
         {
             v2f OUT;
             OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex);
             OUT.texcoord = TRANSFORM_TEX(IN.texcoord, _MainTex);
             return OUT;
         }
 
         fixed4 frag(v2f IN) : COLOR
         {
             fixed4 col = tex2D(_MainTex, IN.texcoord) * _Color;
         clip(col.a - 0.5);
         return col;
         }
             ENDCG
         }
     }
 }
Comment
Add comment · Show 4
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 tanoshimi · Mar 11, 2016 at 01:51 PM 0
Share

At what point are you setting the maximumLOD? Have you tried global$$anonymous$$aximumLOD ins$$anonymous$$d?

avatar image gCave · Mar 15, 2016 at 01:32 PM 0
Share

Thanks a lot for your help. To answer your question I set the $$anonymous$$aximumLOD in the update of a script attached to an object in the scene.The shader that I use to set $$anonymous$$aximumLOD on is a public variable of my script. I now tried to use global$$anonymous$$aximumLOD and it actually worked that been said I feel that $$anonymous$$aximumLOD should work too else I wont be able to have some shaders with higher lod then others.

avatar image tanoshimi gCave · Mar 15, 2016 at 01:49 PM 0
Share

Yes, maximumLOD should work. You're setting it in Update()? But not repeatedly, right? If you're doing it based on the capability of the device, I'd be doing it in a one-off function, perhaps Start(), something like this:

 void Start() {
   if(condition$$anonymous$$etToChangeLOD){
     GetComponent<Renderer>().shared$$anonymous$$aterial.shader.maximumLOD = 100;
   }
 }

Is that right?

avatar image gCave tanoshimi · Mar 17, 2016 at 03:38 PM 0
Share

Your right I only change it once in the update, I don't see why it would make a difference whether you change it in the update or the start but I geuse I could give it a try but I'd like to have a full comprehension of this LOD thing though. thx a lot for the help anyway :-)

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Why is shader behavior different between Android and iOS? 1 Answer

My shader works on desktop, but black screen on Android. 0 Answers

Shader works differently on Android (OpenGL) and Editor (DX11) 0 Answers

RWTexture2D in Compute Shader on Android? 2 Answers

Foliage shader makes objects invisible on Android Build 0 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