- Home /
Shader wants texture coordinates, but the mesh doesn't have them
Hey!
So, I'm working with a shader that I'm using with a mesh that I've generated in a script, using the graphics class, and the Graphics.DrawMesh() function. My trouble is that the shader I'm using is continually spitting out this message:
"Shader wants texture coordinates, but the mesh doesn't have them".
The shader doesn't seem to be malfunctioning -- I'm just using it to display a flat color. But What I'd like is to have the shader stop crowding my console with this message. The shader code is below -- what do I have to change to stop the shader from "wanting texture coordinates"? It doesn't seem to need them...let me know if there's something else you need in order to figure out the problem.
Shader "Sprite/Vertex Colored" {
Properties {
_Color ("Main Color", Color) = (0.5,0.5,0.5,1)
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}
Category {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
SubShader {
Material {
Diffuse [_Color]
}
Pass {
ColorMaterial AmbientAndDiffuse
Lighting Off
Cull Off
SetTexture [_MainTex] {
Combine texture * primary, texture * primary
}
SetTexture [_MainTex] {
constantColor [_Color]
Combine previous * constant DOUBLE, previous * constant
}
}
}
}
}
So, when you create the mesh, create some texture coordinates. Your shader uses a texture, so Unity is telling you the mesh should provide texture coords.
Answer by nsxdavid · Mar 10, 2013 at 05:02 PM
Your shader is not just displaying a flat color, it's trying to use a texture (i.e. _MainTex). So the model must contain texture coordinates, which are added in the 3D application that authored the model, or some external app, via UV Mapping.
indeed. TBC, if you are building the mesh programatically you must of course create and set the UVs.
http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$esh.html
http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$esh-uv.html
the arcana of this is endlessly discussed on here!
Hey guys! Thanks heaps. $$anonymous$$, my old friend, you're right -- I just forgot. I am using a single white pixel as my texture to get a flat color effect. As far as creating and setting UVs, I actually would prefer not to do this, if it's going to save me memory. Because the drawing class I'm using this for needs to be maximally speedy. How would you recommend removing the need for UVs from this shader, then, Fattie? Is that even possible?
Your answer
Follow this Question
Related Questions
Shader wants texture coordinates... 1 Answer
Effects of Graphics.Blit to rendertexture are temporary 2 Answers
Always included shaders (Graphics settings) 1 Answer
Dymanic Mesh Hiding 2 Answers
Shader effect gone when I hit Play 0 Answers