Hi forum This should be easy... I want to create a shader that can display self-ilumin alpha textures that are influenced by fog. Like the build in TextShader, effected by fog. On the screen-shot below, the far away dots are rendered on top of frontmost dots and I can't figure out why that is. I am new to shaders, but I have read the Unity shader documents. Thanks ~ce Code (csharp): Shader "SelfIluminAlphaFogged" { Properties { _MainTex ("Texture", 2D) = "white" {} _Color ("Color", Color) = (1,1,1,1) } SubShader { Lighting Off Cull Back ZTest Always ZWrite Off Blend SrcAlpha OneMinusSrcAlpha Pass { Color [_Color] SetTexture [_MainTex] { combine primary, texture * primary } } } }
I just tried out the following, seems to be what you are looking for. The "ZWrite Off" causes your far away particles to possibly render in front of your close particles. You can turn on sorting for the particlesystem, but then you would have the same problem with particles and your text. Instead I added in the "Alphatest Greater [_Cutoff]" (and the extra property). This prevents it from writing to the depthbuffer when the alpha drops below 0.5 which seems to work good. Code (csharp): Shader "GUI/Fog Font" { Properties { _MainTex ("Font Texture", 2D) = "white" {} _Color ("Text Color", Color) = (1,1,1,1) _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 } SubShader { Tags {"Queue" = "Transparent"} Lighting Off Cull Off //ZTest Always //ZWrite Off //Fog { Mode Off } Alphatest Greater [_Cutoff] Blend SrcAlpha OneMinusSrcAlpha Pass { Color [_Color] SetTexture [_MainTex] { combine primary, texture * primary } } } }
Thanks Proton, it makes sense ... but now the anti-aliasing is gone so edges are jagged and the text starts jittering, apparently because of the "Alphatest Greater [_Cutoff]". Why not use the alpha channel in the texture to make the cut off? I wish I knew how. ~ce
You can fix the aliasing problem with the particles by going to your ParticleRenderer and changing "Stretch Particles" from "Billboard" to "Sorded Billboard" The particles will now look fine, but where they intersect with the text will be a problem sometimes. The alphatest determines if the depth buffer is written to. It does use your alpha channel, but can only either write, or not write. That is why the anti-aliased parts get written to the screen the depth buffer causing them to look ugly. Try adjusting your font to be trilinear in the texture and crank up the ansio level, that may help.