[SOLVED] Logo Decal on Player Mesh

I’m a complete noob when it comes to the ShaderLab. Anyway I’m trying to put a logo on the back of a unit in my strategy game, but its messed up. I based the whole thing off from the blob shadow projector.

The transparency is choppy (not smooth), and the decal shows up in front of the mesh.

The decal shows up front even though my far clip plane is short enough.

This is the test logo I’m trying to display:

here is my material shader code, which I based off on “FX/Projector Multiply”

Shader "Unit/Logo Projector" { 
	Properties {
		_LogoTex ("Cookie", 2D) = "fresnel.png" {
			TexGen ObjectLinear 	
		}
		_FalloffTex ("FallOff", 2D) = "fresnel.png" {
			TexGen ObjectLinear	
		}
	}

	Subshader {
	  Material {
         Diffuse (1,1,1,1)
         Ambient (1,1,1,1)
         Specular (1,1,1,1)
      }
	  Lighting On
		Pass {
			ZWrite off
			Offset -1, -1
			
			Fog { Color (1, 1, 1) }
			AlphaTest Greater 0


			SetTexture [_LogoTex] {
				combine primary * texture
				Matrix [_Projector]
			}
		}
	}
}

Ok, so I managed to get rid of the choppy transparency by changing

AlphaTest Greater 0

with

Blend SrcAlpha OneMinusSrcAlpha

Now the only problem is the logo shows up in front of the mesh…

Ok, I fixed the decal rendering in front by putting a falloff.

Now my problem is the decal doesn’t respond to lighting effects. It renders full lit in gray. I want it to get rendered according to the scene’s lights. In here I made the light red, but the decal doesn’t turn red:

Here is my shader code so far:

Shader "Unit/Logo Projector" { 
	Properties {
		_LogoTex ("Cookie", 2D) = "fresnel.png" {
			TexGen ObjectLinear 	
		}
		_FalloffTex ("FallOff", 2D) = "fresnel.png" {
			TexGen ObjectLinear	
		}
	}

	Subshader {
		Pass {
			Material {
				Diffuse (1,1,1,1)
				Ambient (1,1,1,1)
				Specular (1,1,1,1)
			}
			Lighting On

			Tags {"Queue" = "Transparent" }
			Blend SrcAlpha OneMinusSrcAlpha

			SetTexture [_LogoTex] {
				combine texture * primary // with lighting
				//combine texture // no lighting
				Matrix [_Projector]
			}
			SetTexture [_FalloffTex] {
				constantColor (1,1,1,0)
				combine previous lerp (texture) constant
				Matrix [_ProjectorClip]
			}
		}
	}
}

As much progress as you’ve made, I don’t think that a projector is the righ tool for this job. Even with correct lighting, the projection will look weird as the cape moves or deforms, and anything that gets too close to the cape will get projected on, as well. I recommend duplicating the cape mesh and moving the duplicate out slightly to avoid Z fighting. Then just apply a transparent shader, and make sure that the duplicate mesh moves in the same way as the original.

Yes, I know. I’m aware of the problems with using a projector, but using a duplicate mesh requires using UV coords. The problem is I want the logos to be user-submitted pictures of logos the players want to use for their units in the strategy game.

Doing it in uv would mean they have to know the uv coords so the picture would fit in the spot the logo is intended to be displayed. Plus, the picture would have to be different for each in-game unit since each unit’s 3d model uv’s are different.

With projectors they just submit a square-sized picture with the logo on it.

I’ve tested it while the unit is running. The cape doesn’t deform too much, so its fine. Plus, I parented the projector to the 3d model’s skeleton, in the chest, so when the unit animates, the projector follows accordingly.

I’ll just have to make sure that my units’ collider has enough space in it so no object can get too close. If only I can set the projector to ignore everything but the unit’s 3d model itself.

So its really just the lighting that’s the most prominent problem.

Ok, now I tried a different approach, using multiple UVs on the unit’s mesh to display a logo.

It eliminates the problems with using a projector, however my shader code seems to have a problem: white areas don’t show, they get considered as transparent:

Here is the texture in question:

Even more weird is, using the cat logo, the result is this:


alpha channel doesn’t seem to get recognized

this is my shader code:

Shader "Unit/Unit Shader" {
Properties {
	_Color ("Color", Color) = (1,1,1,1)
	_UnitColor ("Unit Color", Color) = (1,1,1,1)
	_MainTex ("Base (RGB)", 2D) = "white" {}
	_Mask ("Unit Color Mask (A)", 2D) = "white" {}
	_LogoTex ("Guild Logo (RGB)", 2D) = "black" {}
}

SubShader {
	Material {
		Diffuse [_Color]
		Ambient [_Color]
		Specular (1,1,1,1)
	}
     
	Lighting On

	Pass {
		BindChannels {
			Bind "Vertex", vertex
			Bind "normal", normal
			Bind "texcoord1", texcoord2 // logo uses secondary uv
			Bind "texcoord", texcoord1 // main uses primary uv
		}

		Cull Off
		//Blend SrcAlpha OneMinusSrcAlpha
		//Blend One One
		
		SetTexture [_Mask] {
			ConstantColor [_UnitColor]
			combine constant lerp(texture) texture
		}

		// main (texcoord1)
		SetTexture [_MainTex] {
			Combine texture * previous
		}

		// logo (texcoord2)
		SetTexture [_LogoTex] {
			combine texture * previous
		}

		SetTexture[_MainTex] {
			combine primary * previous
		}
	}
}

}

Ok, everything’s fixed now. :smile:

I changed:

SetTexture [_LogoTex] {
 combine texture * previous
}

to:

SetTexture [_LogoTex] {
 combine texture lerp (texture) previous
}

Hi,

Look great, but how does it work exactly? :o

JP

you have a 2nd UV channel on the model and use this as secondary texture that overlays the other and uses the second UV channel for positioning.

thats a pretty common way to do such stuff :slight_smile: (lightmapping works this way too on static objects for example)

Ah…ok.
Tx

Hello. Could you give a simple scene realizes this Methot?

I created a unitypackage that shows this. In http://anomalousunderdog.herobo.com/UnityProjectUploads/

there’s a link titled DecalTest.unitypackage. You can download it from there.

I used Blender to create the mesh so if you don’t have Blender installed, it might not show up. I created an fbx version of the mesh in that case.