- Home /
Doing a clipping effect with a 3D text mesh using shaders
I'm using a custom shader on my 3D text objects in order to create an effect where the text is revealed from left to right. I'm doing this with a surface shader that clips all pixels to the right of a certain screen position. This works great, and is just what I wanted, but Unity is throwing a lot of warnings because surface shaders are expected to use normals and the Text Mesh component doesn't generate any normals.
While this is workable for now, in the long run I need a way to stop getting my console spammed with these warnings. I can think of three approaches: 1) write a fragment shader that clips the text in the same way, 2) suppress the warning (which I'd prefer not to do) or 3) find a way to make the Text Mesh generate proper normals for its geometry. I'm not sure how to do any of these things... can someone point me in the right direction?
Thanks!
Like I said, I don't know how to write a fragment shader that would clip based on screen space, but the surface shader WOR$$anonymous$$S, so it's hardly pointless. Inappropriate, perhaps, but it DOES do the job. If there's a better way to do it, I'm all ears.
Just because you don't know how to do it without a surface shader doesn't mean that there's a point to using a surface shader. Surface shaders exist to make working with Unity's undocumented lighting system feasible. I don't see a clear question here. You just don't know how to use Cg or GLSL?
"Pointless" is a bit of a strong term for something that's fully functional.
The shader is basically just this:
void surf (Input IN, inout SurfaceOutput o)
{
clip(_ScreenXCull - IN.screenPos.x / IN.screenPos.w);
fixed4 c = tex2D($$anonymous$$ainTex, IN.uv$$anonymous$$ainTex) * _Color;
o.Albedo = c.rgb * _Color;
o.Alpha = c.a;
}
It functions as intended, but throws a warning when applied to my 3D Text meshes since they do not generate normals. How do I stop it from throwing warnings at me when applying it to a text mesh?
You don't; that's an annoyance of Unity, and has existed since the beginning. I logged a bug about it long ago; you can too. I don't think the term is strong; if I were to write this, I'd be using GLSL, and I'd see no point in using a surface shader. It depends on what you want to learn. I believe you should learn Cg. All you need to do is multiply the vertex position by the $$anonymous$$VP, and work with the result.
Answer by ScroodgeM · Jul 17, 2012 at 07:53 AM
the best and i think the only one way to complete this quest is to write a vertex shader. it's a good in perfomance reason, cause it doesn't use a lot of calculations like light and others, and it doesn't use any normals. show a shader u use for text - i'm sure it needs a bit changes to became a vertex 8)
Your answer
Follow this Question
Related Questions
3D Text diffuse shader? 1 Answer
How to use sprite mask interation for 3d text mesh ? 0 Answers
3D Texture and normals 0 Answers
CutOut diffuse shader visible from both sides on a plane? 1 Answer
Generic clipsafe fading ✿ 0 Answers