3D Text with lighting?

The “GUI/Text Shader” shader (Font.shader) used by 3D Text is a simple transparent emission-only shader, whereas I need the text to respond to lighting (imagine white text on a sign in a room with a point light).

I have tried all the “Transparent/…”, and writing my own shaders, but they all look as though no light is falling on the text.

Since other meshed work fine, the problem is the mesh generated by Text Mesh, presumably that it has no normals.

In my case, the text is in a fixed location (only the text itself changes), so normals could be set on the Material if necessary.

Here is an image using the “Debug/Normals” shader, showing the text as grey rectangles and normal mesh with normal colors. As you can see, the normals on the TextMesh are (0,0,0) (they become grey because the debug shader adds 0.5), so any perturbing normal provided by the surface shader multiplied with that gives (0,0,0).

The result of this is that the lightDir passed to the lighting function is always 0.

If you’re willing to work with shader code directly you can get the effect you’re looking for easily. You can download all the built-in shaders here. This article describes how to substitute one 3dtext material for another.

You can then duplicate and modify the GUI Text Shader (Font.shader) to include the surface shader from the diffuse shader (Normal-Diffuse.shader). You actually might be able to achieve the effect simply by removing the ‘Lighting Off’ from the shader (you could also turn fog back on if desired).

However, it looks like the shader by default does vertex shading (#pragma vertex vert, where vert is defined below) as opposed to surface shading (#pragma surface surf Lambert, which appears in the diffuse shader and where surf is defined below in the code).

Does that help you at all?