- Home /
Vertex Fragment Shaders are BROKEN?
Hello, I am trying this shader below from http://en.wikibooks.org/wiki/Cg_Programming/Unity/Billboards
and I keep getting error:
Material doesn't have a texture property '_MainTex'.
Along with these errors:
Unsupported: Cg shader for billboards
Unsupported: Cg shader for billboards
done. [Time: 84.483981 ms]
Unsupported: Cg shader for billboards
Shader error in 'Cg shader for billboards': FindCgParams failed (compiling for flash) at line 7
(Filename: wikibillboard Line: 7)
Shader error in 'Cg shader for billboards': Vertex program 'vert': unknown input channel 'tex' at line 7
(Filename: wikibillboard Line: 7)
Shader error in 'Cg shader for billboards': Shader program had errors at line 8
(Filename: wikibillboard Line: 8)
Anyone see any problems with this shader? I can't get it working. I'm trying to learn how it works, but hard when doesn't work from the start! :(
Shader "Cg shader for billboards" {
Properties {
_MainTex ("Texture Image", 2D) = "white" {}
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// User-specified uniforms
uniform sampler2D _MainTex;
struct vertexInput {
float4 vertex : POSITION;
float4 tex : TEXCOORD0;
};
struct vertexOutput {
float4 pos : SV_POSITION;
float4 tex : TEXCOORD0;
};
vertexOutput vert(vertexInput input)
{
vertexOutput output;
output.pos = mul(UNITY_MATRIX_P,
mul(UNITY_MATRIX_MV, float4(0.0, 0.0, 0.0, 1.0))
- float4(input.vertex.x, input.vertex.z, 0.0, 0.0));
output.tex = input.tex;
return output;
}
float4 frag(vertexOutput input) : COLOR
{
return tex2D(_MainTex, float2(input.tex.xy));
}
ENDCG
}
}
}
EDIT: I tested a sort of similar shader in the docs(the one called "Chess") and get the same type of errors: http://docs.unity3d.com/Documentation/Components/SL-VertexFragmentShaderExamples.html
It appears it doesnt understand texcoord0 in the "Chess" shader, which makes me think it doesnt understand TEXCOORD0 in the wiki shader. So, why is this?...
EDIT2: Did more testing. The problem is definately having to do with texture coordinates used in a struct, or possibly vertex positions. I tried just about all the shaders on the documentation, and none with texture coordinates work. If I use the "ChessOpt" shader, which has no texture coordinate structs, it works great, but the normal Chess shader, does not. I'm starting to think this might be a problem worth bringing to UT attention.
Do you build for flash here? At least it looks like due to the error message. The flash export had tons of restrictions and Unity abandoned the flash support as you can read here. They just keep up the premium support while in the 4.x cycle and after that it's finally dead.
Try a different target platform
You don't get what i'm saying. What is your selected target platform in the build settings? Unity behaves very differently depending on the target platform. $$anonymous$$ake sure you selected your desired platform. Unity usually reimports all assets on a platform change since a lot assets are treated differently on other platforms.
I understood, it is on PC standalone. I just meant to also say, I didn't try to build for flash, either.
Answer by bpears · Jan 04, 2014 at 11:02 AM
No, I didn't build, I don't know why it says that.
However, I am finding that that wiki page with the code was edited, to include TEXCOORD0 in the vertexInput struct. So I think maybe Unity did upgrade or change something in Unity 4, and so Unity 3.5 does not support updated code or documentation to have TEXCOORD0 set up like that, for some reason. Can only use it in the Output struct(for 3.5). So need to keep an eye out and calculate the input/output by hand.
Answer by pointcache · Jan 04, 2014 at 08:09 AM
Yes that's the thing with those wiki shaders some of them don't work because shaderlab is updating from time to time. I don't know shader lang so good to be able to fix that, but it's probably something with changed syntax.
I'm using Unity 3 AT$$anonymous$$, but it should be fine. I know surface shader syntax, and write those, and I understand what this shader is doing for the most part, but I don't get why it isn't compiling.