Strange problem with a simple 1 pass 2 textures shader

Hi all,

I have a very strange problem. I’m not sure if it’s a bug or just an error on my part.
I have created a very simple shader that combines color, lightmap and texture.
The problem is, when I use it, it looks well on the editor, but on the application the texture dissapears. Also, if I save and reload Unity, the texture also dissapears.
But this is the most weird part: if I use it in a multiple material object, and at least one of the materials doesn’t use this shader, then it works. ¿?
Maybe it will look clearer with an example:

http://www.tetravol.com/tetravol/problemwithshader.html

This is how it should look(I’m using a regular diffuse lightmap shader on the floor)

http://www.tetravol.com/tetravol/problemwithshader-1differentmaterial.html

Here is the code for the shader. Do you see something wrong?

Shader "Lightmapped/LightmapOnly" {
Properties {
	_Color ("Main Color", Color) = (0.6,0.6,0.6,1)
	_MainTex ("Base (RGB)", 2D) = "white" {}
	_LightMap ("Lightmap (RGB)", 2D) = "black" {}
}



// ------------------------------------------------------------------
// Two texture cards - lightmap and texture in one pass; no lighting

SubShader {

	Pass {
		Name "BASE"
		Tags {"LightMode" = "Always"}
		BindChannels {
			Bind "Vertex", vertex
			Bind "texcoord", texcoord0 // main uses 1st uv
			Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
		}
		SetTexture [_LightMap] { constantColor [_Color] combine texture * constant}
		SetTexture [_MainTex] {  combine texture * previous double, previous}
	}
	
}

Fallback "VertexLit", 1

}

Finally, here is the Unity project if someone wants to take a look:

http://www.tetravol.com/tetravol/unity-problemwithshader.zip

Thanks,

On first glance, your line:

Bind “texcoord1”, texcoord0

should be

bind “texcoord1”, texcoord1

???

You have both sets to uv’s pointing to the same texturing stage?

You also might want to swap both Bind’s around because at the moment you said you wanted to use uv2 for the lightmap but you’re using both uv1 and uv2 for the lightmap stage and nothing for the main texture?

You are right… in theory.
I don’t know why, but it only works if I use Bind “Texcoord1”, texcoord0.

Try the included project if you have the time. If you bind it like it should, it doesn’t work.

Please! I’m I doing something terribly wrong or have I encountered a bug?

Thanks,

Look at the order of your SetTextures. You’re tinting the lightmap first. As such, what you actually need is

Bind "texcoord1", texcoord0 // lightmap uses 2nd uv 
Bind "texcoord", texcoord1 // main uses 1st uv

I think this page is really clear. Are you hung up on something?

As for the problem you described, I don’t understand that at all, but perhaps if you fix your code, it will sort things out.

Also, what’s the point of this in your code?

, previous

or

Tags {"LightMode" = "Always"}

You don’t need a LightMode tag if it doesn’t accept lighting!

Thank you Jessy!!!

It worked like a charm. Now that the code is correct, the problem is gone.

Please excuse me, I am a total newbie at programming shaders. I had read the shaderlab reference of course, but I found it confusing that it uses the same name texcoord for both the mesh coordinates and the pass coordinates. Now it’s all clear to me.

Best regards,

I agree. The naming is pretty bad. “uv1” and “uv2”, along with “textureStage1, textureStage2, etc.” would be a lot better.

Happy to hear that this worked out.