- Home /
VertexLit Hilight Shader - Flicker on iOS Problem
Hi everyone! I'm pretty new to shader coding, but I managed to hack together a Hilight Shader that uses the Mobile VertexLit as its core, plus the outline code from Toon Basic Outline (both of these are builtin shaders).
BUT, the outline "higlight" is flickering on iOS devices. Could someone who is wise to shaders please take a look at this short shader and tell me why I'd be getting a flicker please? Thank you!
// Mobile VertexLit PLUS highlight outline
Shader "Custom/Mobile VertexLit Hilight" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" { }
}
CGINCLUDE
#include "UnityCG.cginc"
struct appdata {
half4 vertex : POSITION;
float3 normal : NORMAL;
};
struct v2f {
half4 pos : POSITION;
half4 color : COLOR;
};
// Outline relative to camera distance. See standard Toon Basic Outline shader for non-relative version
v2f vert(appdata v) {
v2f o;
o.pos = v.vertex;
o.pos.xyz += v.normal.xyz * 0.0225;//_Outline
o.pos = mul(UNITY_MATRIX_MVP, o.pos);
o.color.r = 0; //0
o.color.g = 0.377; //96
o.color.b = 1; //255
return o;
}
ENDCG
SubShader {
Tags { "RenderType"="Opaque" }
UsePass "Custom/Mobile VertexLit Named/BASIC"
Pass {
Name "OUTLINE"
Tags { "LightMode" = "Always" } //"Vertex" }
Cull Front
ZWrite On
ColorMask RGB
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
half4 frag(v2f i) :COLOR { return i.color; }
ENDCG
}
}
Fallback "Mobile/VertexLit"
}
Hey guys, sorry. Just want to bump again. Does anyone on Answers know shaders?
Answer by Sonaten · Oct 19, 2012 at 08:53 PM
Shaders are a quite complicated part of unity. And one important detail that probably won't solve your problem right away, is that you have chosen to code in CG. CG is the best supported language for unity, because it has a build in translater from CG to OpenGLSL. However this conversion is at it's best not fit for mobile devices. Efficiency will be higher when programming OpenGLSL in unity if only for Mac OS and mobile devices.
That said it might not at all be affecting your current output. But due to the translated code you might find that you do not have total control. I am not familiar with how well the translated shading works.
Hope this can bring some new pawns on the table.
Thanks Niklas! This is good to know for future Shader program$$anonymous$$g. For now, I'm 'using CG because it's copy-pasted and tweaked from the only Unity highlighting shader (Toon Basic Highlight). If I get savvier I'll try this out..
Looking more into it now, I think my flicker might be caused by using low-poly models for mobile, but that doesn't solve my problem yet :(
Flickering could also be cause by faces "battling" in the depth buffer. One could imagine that this battle is handled less neatly on mobile devices.
Your answer
Follow this Question
Related Questions
Why does this shader show up black on iOS? 1 Answer
What shader blending modes don't work on iOS? 1 Answer
How to achive the same look? Which shaders to use? 2 Answers
Iphone Shader Reflection Map 0 Answers
Unity Advanced Shader Help 0 Answers