lightmap plus per material color

Hey,

I’m trying to make the fastest shader for mobile (iOS) with support for: texture, lightmap and per material color.
I’ve got it working by just stripping the Mobile/diffuseDetail shader of its detail texture.

Shader "Mobile/VertexLitColor" {
Properties {
	_Color ("Main Color", Color) = (1,1,1,1)
	_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
	
	Pass{
		
		Material{
			Diffuse [_Color]
		}
		
		Lighting On
		SetTexture [_MainTex] { combine texture * primary Double, texture * primary}
	}

} 
FallBack "VertexLit", 2

}

Can anyone tell me if this is the faster thing to do or if it’s just the same as using a diffuse texture (I only use lights for baking, no realtime lights)

Thanks a lot!


Ok after some great tips/link from Jessy I’m trying to build a GLSL shader but its seaming way over my heat atm.
Here is my current attempt, it has the color, texture and the lightmap kind of works but then if I rotate the camera the object goes black at certain angles.

I’m starting to get bits and pieces of how this works but its still way over my head :slight_smile:

Shader "Mobile/VertexLitColor" {
Properties {
 _MainTex ("Texture Image", 2D) = "white" {} 
 _Color ("Main Color", Color) = (1,1,1,1)

}
SubShader {
  Pass {      
     GLSLPROGRAM

     uniform sampler2D _MainTex, unity_Lightmap; 
     uniform mat4 unity_LightmapMatrix; 
     uniform vec4 _Color ;

     varying vec4 textureCoordinates; 
     varying vec2 textureCoordinatesLM;

     #ifdef VERTEX

     void main()
     {
        textureCoordinates = gl_MultiTexCoord0;
        textureCoordinatesLM = vec2(unity_LightmapMatrix[0].x, unity_LightmapMatrix[1].y) * gl_MultiTexCoord1.xy + unity_LightmapMatrix[3].xy;
        gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
     }

     #endif

     #ifdef FRAGMENT

     void main()
     {
        gl_FragColor = texture2D(_MainTex, vec2(textureCoordinates)) * _Color * texture2D(unity_Lightmap, textureCoordinatesLM);     
                    
     }

     #endif

     ENDGLSL
  }
  }
  // The definition of a fallback shader should be commented out during development:
  // Fallback "Unlit/Texture"
  }

Here’s a shader that uses vert colors and Unity’s lightmapping. I don’t know what you want to do about the realtime preview; Unity doesn’t provide a good means of dealing with that, that I know of. Maybe use Diffuse, and then switch shaders after you’ve baked?

Shader "Vert Color Diffuse" {

Properties {
	_MainTex ("Base", 2D) = "white"
}

SubShader {	
	Pass {
		Tags {"LightMode"="VertexLM" }
		GLSLPROGRAM
		uniform mediump mat4 unity_LightmapMatrix;
		varying lowp vec4 color;
		varying mediump vec2 uv;
		varying lowp vec2 uv2;
				
		#ifdef VERTEX
		void main() {
			gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
			uv = gl_MultiTexCoord0.xy;
			uv2 = vec2(unity_LightmapMatrix[0].x, unity_LightmapMatrix[1].y)
				* gl_MultiTexCoord1.xy + unity_LightmapMatrix[3].xy;
			color = gl_Color * 2.;
		}
		#endif
		
		#ifdef FRAGMENT
		uniform lowp sampler2D _MainTex, unity_Lightmap;
		void main() {
			gl_FragColor = texture2D(_MainTex, uv) * texture2D(unity_Lightmap, uv2) * color;
		}
		#endif		
		ENDGLSL
	}	
	Pass {	// Editor only - Graphics Emulation uses the wrong lightmap type
		Tags {"LightMode"="VertexLMRGBM" }
		GLSLPROGRAM
		uniform mat4 unity_LightmapMatrix;
		varying vec4 color;
		varying vec2 uv, uv2;
				
		#ifdef VERTEX
		void main() {
			gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
			uv = gl_MultiTexCoord0.xy;
			uv2 = vec2(unity_LightmapMatrix[0].x, unity_LightmapMatrix[1].y)
				* gl_MultiTexCoord1.xy + unity_LightmapMatrix[3].xy;
			color = gl_Color * 2.;
		}
		#endif
		
		#ifdef FRAGMENT
		uniform sampler2D _MainTex, unity_Lightmap;
		void main() {
			gl_FragColor = texture2D(_MainTex, uv) * texture2D(unity_Lightmap, uv2) * color;
		}
		#endif		
		ENDGLSL
	}
}

SubShader {	
	Pass {
		BindChannels {
			Bind "vertex", vertex
			Bind "color", color
			Bind "texcoord", texcoord0
			Bind "texcoord1", texcoord1
		}
		SetTexture[_MainTex] {Combine primary * texture}
		SetTexture[unity_Lightmap] {
			Matrix[unity_LightmapMatrix]
			Combine previous * texture Double
		}
	}
}
 
}