- Home /
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
}
}
}
At what point are you setting the maximumLOD? Have you tried global$$anonymous$$aximumLOD ins$$anonymous$$d?
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.
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?
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 :-)
Your answer
Follow this Question
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