Blending 2 textures with 2 uvs

Hello,

i have a problem with a shader i’m writing, i want to know if some one could help me with my problem.

this is my shader:

Shader "MyShaders/test" {
	Properties {
		_MainTex ("Texture (RGB)", 2D) = "white" {}
		_AmbientTex ("Ambient Occlusion", 2D) = "white" {}
		_BlendAmbient ("Blend Ambient Occlusion" , Range(-1,1)) = 1.0
		_BumpTex ("Bump map", 2D) = "bump" {}
	}
	SubShader {
		Tags { "RenderType"="Transparent" }
		LOD 200
		
		CGPROGRAM
		#pragma surface surf Lambert

		sampler2D _MainTex;
		sampler2D _AmbientTex;
		sampler2D _BumpTex;
		float _BlendAmbient;

		struct Input {
			float2 uv_MainTex: TEXCOORD0;
			float2 uv_AmbientTex: TEXCOORD1;
			float2 uv_BumpTex: TEXCOORD0;
		};

		void surf (Input IN, inout SurfaceOutput o) {
			o.Albedo = tex2D (_MainTex, IN.uv_MainTex) * tex2D(_AmbientTex, IN.uv_AmbientTex);
			o.Normal = UnpackNormal ( tex2D (_BumpTex, IN.uv_BumpTex));
		}
		ENDCG
	} 
	FallBack "Diffuse"
}

the only thing i get from this is a black object.

could some one tell me what i did wrong or what give this bug.

thanx

struct Input {
float2 uv_MainTex;
float2 uv_AmbientTex;
float2 uv_BumpTex;
};

change your struct to this.

The idea is that i can use my two uv coordinates for my material.

I really want to use my two uv channels that my object has on one material.
So i can bake my shadow maps in blender and put them over my color map.

I hope this explains beter

I tried also to export in .obj and .fbx but that didn’t work out.

From the documentation:

So instead of using uv_AmbientTex try using uv2_AmbientTex to actually get the secondary uv set of your object. I’d be interested to hear if that worked since I am doing some shader stuff myself at the moment.

I allready tried, but i got errors.
I readed at unity answers that i could be a bug in unity.
If some one knoes something about that i liked to hear from it.

I just tried this myself and it seems to work. Given a model which actually has a second uv set that differs from its first set this shader should produce different results when you swap UVs inside the import settings of the model (fbx/obj asset):

Shader "Custom/DebugUv2" {
	Properties {
		_MainTex ("Base (RGB)", 2D) = "white" {}
	}
	SubShader {
		Tags { "RenderType"="Opaque" }
		LOD 200
		
		CGPROGRAM
		#pragma surface surf Lambert

		sampler2D _MainTex;

		struct Input
		{
			float2 uv2_MainTex;
		};

		void surf (Input IN, inout SurfaceOutput o)
		{
			half4 c = half4(frac(IN.uv2_MainTex.xy), 0, 1);
			
			if (any(saturate(IN.uv2_MainTex.xy) - IN.uv2_MainTex.xy))
				c.b = 0.5;
				
			o.Albedo = c.rgb;
			o.Alpha = c.a;
		}
		ENDCG
	} 
	FallBack "Diffuse"
}

Also there is a vertex/fragment shader example describing the usage of secondary UVs in the docs as well:

That’s where I took the code inside the surf function from.

Thanx, i will try this.
But if you want the answer if i worked, i will post it later after new year.

Happy new year :slight_smile:

Can i know which version of unity you have?

Still won’t work

I think v4.0.0f7 it was - in editor mode. No build made.
Perhaps you should post a sample project including your model to for instance verify it actually has secondary uvs?

here is the object where this shader has to work on, with the shader :

http://www.4shared.com/rar/U02Yuc00/shaderobject.html

thank you very much for helping me out so much :slight_smile: .

No prob, I’ll have a look at it once I am back in Hamburg this evening. Probably posting tomorrow.

Several problems with the files you’ve uploaded:

  1. The shader in there does not use the syntax for accessing secondary UVs. Please change lines 22 and 29.
    22: float2 uv2_AmbientTex;
    29: o.Albedo *= tex2D (_AmbientTex, IN.uv2_AmbientTex) * _BlendAmbient;

  2. The mesh in there is provided in OBJ format. To my knowledge there is no standardized support for secondary UV channels in OBJ files. Solution: use another format like FBX or Collada. Both support multiple UV sets/channels. If you use Blender you may directly use your BLEND file (http://docs.unity3d.com/Documentation/Manual/HOWTO-ImportObjectBlender.html) and see what happens.

You can tell if a given model has kept its second UV set after import to Unity by looking at its mesh. That’s a child object (the one with the grid icon) of the model asset. Clicking on it reveals the information it got (like uv, uv2, verte colors, tri count etc.).

  1. Let me give you another tip: Next time you upload something for use in a forum discussion you may try and reduce the overall filesize somewhat by removing files not needed or by shrinking textures. Also try adding the files directly as an attachment to the discussion. Others might not go the difficult route of registering to a file sharing service. I did with the help of a one-time-email address. Again, others might not want to do this.

Happy new year and ask questions if something’s not clear to you.

He,

  1. 2.thanks for your great support.
    IT WORKS :slight_smile:

  2. thanks for this tip, but the problem was that the standard file includer don’t get this big of a file.
    so wanted it to share through mediafire, but i would work. so i did it through 4share.
    sorry for that.

So much thanks for this help again.