Shader with 2 decals

I should start by saying that I don’t know the first thing about building shaders… however, I’d like to know if what I’m about to ask is even possible.

I would like to use a shader that has:

  • 2 decals
  • a background color that can be changed without altering the tint of either decal

Preferably, it would be a VertexLit shader, because those do seem to render faster. Is this possible? Has it been done before?

I sort of did it yesterday. However, if you only need a solid color as the base, and not a texture, we can do a lot better! None of the “caveats” I listed there apply to this one, except the SeparateSpecular issue. I put “SeparateSpecular On” in the first subshader below, that requires three texture units, so the specular lighting won’t match between really old cards, and modern ones, but I think that’s reasonable. Just get rid of that line if you want an exact match at the expense of probably looking better.

Shader "Color + 2 Decals, Vertex Lit" { 

Properties
{ 
	_Color ("Main Color", Color) = (1,1,1) 
	_SpecColor ("Spec Color", Color) = (1,1,1) 
	_Emission ("Emmisive Color", Color) = (0,0,0) 
	_Shininess ("Shininess", Range (0.01, 1)) = 0.7 
	_DecalTex ("Decal A (RGBA)", 2D) = ""
	_DecalTexB ("Decal B (RGBA)", 2D) = ""
} 

// More than two texture units
SubShader {Pass
{
	Lighting On
	SeparateSpecular On
	Material
	{ 
		Diffuse (1,1,1) 
		Ambient (1,1,1) 
		Shininess [_Shininess] 
		Specular [_SpecColor] 
		Emission [_Emission] 
	} 
	SetTexture[_DecalTex]
	{
		ConstantColor[_Color]
		Combine texture Lerp(texture) constant
	} 
	SetTexture[_DecalTexB] {Combine texture Lerp(texture) previous}
	SetTexture[_] {Combine previous * primary Double}
}}

// Two texture units
SubShader
{ 
	Lighting On
	Material
	{ 
		Diffuse (1,1,1) 
		Ambient (1,1,1) 
		Shininess [_Shininess] 
		Specular [_SpecColor] 
		Emission [_Emission]
	}
	Pass
	{
		SetTexture[_DecalTex]
		{
			ConstantColor[_Color]
			Combine texture Lerp(texture) constant
		}
		SetTexture[_DecalTexB] {Combine texture Lerp(texture) previous}
	}
	
	// 'Double' Lighting
	Pass {Blend DstColor SrcColor}
} 

}

268661–9666–$color__2_decals_vertex_lit_105.shader (1.14 KB)

My apologies, I forgot to thank you for this. It works perfectly! Thanks!

Awesome. Glad to hear it.

This shader doesn’t appear to work on the iPhone.

Is there any ay to make a decal shader that will work on the iPhone?

It should work fine and perform better on the 3GS and later due to one fewer draw call. What problem are you having?

I’ve attached images of your decal shader applied to a shadow texture (top) and the Unity Transparent-Diffuse shader on the same (bottom).

Hope this helps.

324783--11449--$decal_jessy_333.jpg
324783--11450--$transparent__diffuse_107.jpg

This shader isn’t for a “shadow texture”. This is for an entire object, an object that is colored solid and has two decals on it. Also, it looks like you’re using pixel lighting; this shader can’t handle that. (And neither can the iPhone for that matter.)

Yeah, I’m using a decal as a trick to achieve a contact shadow.

No pixel lights here, but thanks for pointing that out. :wink:

Anyway, I found the problem. Sort of. I was using Unity primitives when things weren’t working. Once I switched to mesh-only FBX exports from 3ds Max, everything worked fine.

Interesting, but I’m not going to argue with it. :stuck_out_tongue:

Thanks again for your help and for the nice shader!