‰‰#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
attribute vec4 pos;
attribute vec4 texcoord;
attribute vec4 normal;
attribute vec4 tangent;
attribute vec4 texcoord1;

uniform mat4 Alice_Matrix_M;
uniform mat4 Alice_Matrix_V;
uniform mat4 Alice_Matrix_P;
uniform mat4 Alice_Matrix_IT_M;

uniform vec4 U_TextureFlag0;

varying vec3 V_WorldPos;
varying vec3 V_Normal;
varying vec2 V_Texcoord;
varying mat3 TBN;

void main()
{
	V_Texcoord=texcoord.xy;
	vec4 worldPos=Alice_Matrix_M*pos;
	V_WorldPos=worldPos.xyz;
	if(U_TextureFlag0.y==1.0){
		vec3 T = normalize((Alice_Matrix_M * tangent).xyz);
		vec3 N = normalize((Alice_Matrix_IT_M * normal).xyz);
		T = normalize(T - dot(T, N) * N);
		vec3 B = cross(N, T);
		TBN = mat3(T, B, N);
	}else{
		V_Normal=(Alice_Matrix_IT_M*normal).xyz;
	}
	gl_Position=Alice_Matrix_P*Alice_Matrix_V*Alice_Matrix_M*pos;
}ú#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
uniform sampler2D U_DiffuseTexture;//U_TextureFlag0.x
uniform sampler2D U_NormalTexture;//U_TextureFlag0.y
uniform sampler2D U_LuminanceTexture;//U_TextureFlag0.z
uniform sampler2D U_SpecularTexture;//U_TextureFlag0.w
uniform sampler2D U_AlphaTexture;//U_TextureFlag1.x

uniform vec4 U_TextureFlag0;
uniform vec4 U_TextureFlag1;
uniform vec4 U_LightPos;//current is direction light
uniform vec4 U_LightFactor;//x:pow
uniform vec4 U_AmbientColor;
uniform vec4 U_DiffuseColor;
uniform vec4 U_SpecularColor;

varying vec3 V_WorldPos;
varying vec3 V_Normal;
varying vec2 V_Texcoord;
varying mat3 TBN;

void main()
{
	if(U_TextureFlag1.x==1.0){
		if(texture2D(U_AlphaTexture,V_Texcoord).a==0.0){
			discard; 
		}
	}
	vec3 L=U_LightPos.xyz;
	L=normalize(L);
	vec3 n = normalize(V_Normal);
	//use normal map
	if(U_TextureFlag0.y==1.0){
		vec3 normal=texture2D(U_NormalTexture, V_Texcoord).rgb;
		normal = normalize(normal * 2.0 - 1.0);
		n = normalize(TBN * normal);
	}
	//diffuse light
	vec4 diffuseColor=U_DiffuseColor;
	float diffuseIntensity=max(0.0,dot(L,n));
	if(U_TextureFlag0.x==1.0){
		diffuseColor=texture2D(U_DiffuseTexture,V_Texcoord)*diffuseIntensity;
	}else{
		diffuseColor=U_DiffuseColor*diffuseIntensity;
	}
	//specular light
	vec4 specularColor=U_SpecularColor;
	if(U_TextureFlag0.w==1.0){
		
	}
	vec3 viewDir=vec3(0.0, 0.0, 0.0)-V_WorldPos;
	viewDir=normalize(viewDir);
	//blin-phong light model
	vec3 halfVector=L+viewDir;
	halfVector=normalize(halfVector);

	float specularIntensity=0.0;
	if(diffuseIntensity==0.0){
		specularIntensity=0.0;
	}else{
		specularIntensity=pow(max(0.0,dot(n,halfVector)),U_LightFactor.x);
	}
	if(U_TextureFlag0.w==1.0){
		specularColor=texture2D(U_SpecularTexture,V_Texcoord)*specularIntensity;
	}else{
		specularColor=U_SpecularColor*specularIntensity;
	}
	vec4 color=vec4(0.0);
	if(U_TextureFlag0.z==1.0){
		color=texture2D(U_LuminanceTexture,V_Texcoord)+U_AmbientColor+diffuseColor+specularColor;
	}else{
		color=U_AmbientColor+diffuseColor+specularColor;
	}
	gl_FragColor=color;
} c045951149ea11e797a8fcaa14d464d5