Text Mesh Shader isn't working - Occlusion

Shader "GUI/Text Shader Z" {
Properties {
   _MainTex ("Font Texture", 2D) = "white" {}
   _Color ("Text Color", Color) = (1,1,1,1)
}

SubShader {
   Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
   Lighting Off Cull Off ZTest Always ZWrite Off Fog { Mode Off }
   Blend SrcAlpha OneMinusSrcAlpha
   Pass {
      ZTest LEqual
      Color [_Color]
      SetTexture [_MainTex] {
         combine primary, texture * primary
      }
   }
}
}

My text mesh is still showing in front of all objects. I am running Unity 3b6 pro. Help please.

it does what you tell it and thats to ignore cull and don’t have a depth value

as such it will always be in front.

no idea why you put in a z there if you don’t set the flags corresponding to the name (cull off - zwrite off and your pass overwrite is doesn’t help its performance as it has to switch states twice for that one)

How do I revise this shader code? This is the shader others have used to make 3d text not appear in front of other objects. The shader on the wiki (for making 3d text not show in front of other objects) doesn’t work on Unity 3 either. I would think there should be a simple check box on a Text Mesh that says something like “Appear Above Objects”. I don’t know how to write shaders so any help would be great.

Anyone know of a shader that will do what I want in Unity 3? The 3d Text shader on the wiki does not work (meaning that it does not make my text NOT show in front of other objects).

It works for me.

Are you creating a new material for the text…

I do this and it works…

  1. Import your font as normal.
  2. Create a new material… drag on the image from the font. Change the shader to the Object Cull Text Shader.
  3. Then on your 3D text object, drag this new material onto the Mesh Renderer Element 0 Slot.
  4. Don’t forget to drag the corresponding font into the TextMesh font.

Shader "GUI/3D Text Shader" { 

Properties { 
   _MainTex ("Font Texture", 2D) = "white" {} 
   _Color ("Text Color", Color) = (1,1,1,1) 
} 

	SubShader { 
	   Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } 
	   Lighting Off Cull Off ZWrite On Fog { Mode Off } 
	   Blend SrcAlpha OneMinusSrcAlpha 
	   Pass { 
		  Color [_Color] 
		  SetTexture [_MainTex] { 
			 combine primary, texture * primary 
		  } 
	   } 
	}  
}

Is this what you are after?

Regards,
Matt.

It still isn’t working, even with the code you posted. I have posted an image of the problem.

The letters shown should be behind the other image (and yes their z position is behind the image).

A few other things:
a) It is an orthographic camera
b) The objects with the letters are TextMesh’s
c) The objects that should be covering the letters consist of a simple mesh filter and a mesh renderer (its a 2d game)
d) I’m using Unity 3b6

if the z position is behind does not have an impact.

if their distance to camera is higher has one and depending on the camera orientation this can be z but also x or y thats required to have a higher depth

What shader does the other image there use?

And what do you mean with “are text meshes”? Are you creating distinct meshes for every single letter?

Its just a transparent diffuse. But I also forgot to mention that I am using Brady’s EZGUI, and every “image” (except the blocks) is a managed sprite, meaning that all of the sprites are combined into one mesh (skinned mesh) so there is only one draw call.

And yes every different letter is a separate textmesh

well thats a problem then.

with transparency, the 0,0,0 point of the mesh defines its sorting point, not where the mesh is.
so when you run it in the editor, see to which root the objects are attached and compare them.

I’m pretty sure you batched stuff at different depths here, but yet as they might have the same root, they don’t sort the way you might think

Ah yes, that was it! Thanks. Also on another note, do you think there is a more efficient way to manage a word type game (like scrabble) than having 10 different text mesh objects (10 draw calls)? They need to be moved and scaled at certain points.

textmeshes in u3 / iphone 1.7+ won’t be 10 drawcalls unless you use 10 distinct materials.

they are batched (unlike GUIText / GUITexture / OnGUI which won’t batch)

assuming EZGUI does not use skinnedmeshrenderers which don’t batch in U3. Can’t remember, haven’t used it the past weeks on my last project.

Yeah, thats how I would think it is, but my objects aren’t scaled 1,1,1 and for some reason I get an extra draw call for every mesh that changes scale.

Your shader has ZWrite Off and the poster with the example uses ZWrite On.

ZWrite is your drawing order.

Thanks guys for this thread — I’m trying to do some 3D text now, and without this shader and discussion, I would have been sunk.

There’s still one problem though: where the bounding box of one character overlaps the bounding box of the next character, I’m getting an ugly scissoring effect. You can easily this in the word “To” for example.

Any idea how to fix that? Is it something that can be fixed with a tweak to the shader, or would a completely different approach be needed?

Thanks,

  • Joe

OK, I think we’ve found the answer… in the shader, “ZWrite On” should be changed to “ZWrite Off”. These are transparent objects and shouldn’t be writing to the depth buffer.

I’ll correct this on the wiki so others don’t run into the same issue…

Cheers,

  • Joe