// Lambert bump mapping
// (c) oP group 2008 Version 2.1
//edited by redphoenix 01.11 -> supporting 4 lights on shader version 3
#include <define>
#include <transform>
#include <fog>
#include <pos>
#include <normal>
#include <tangent>
#include <lights>
#include <color>
#include <phong>
texture entSkin1; // texture
texture entSkin2; // normal map or lightmap
texture entSkin3; // normal map on blocks
sampler sBaseTex = sampler_state { Texture = <entSkin1>; MipFilter = Linear; };
sampler sSkin2 = sampler_state { Texture = <entSkin2>; MipFilter = None; };
sampler sSkin3 = sampler_state { Texture = <entSkin3>; MipFilter = None; };
struct bumpOut
{
float4 Pos: POSITION;
float Fog: FOG;
//float4 Ambient: COLOR0;
float4 Tex12: TEXCOORD0;
//float3 PosView: TEXCOORD1;
float3 Light1: TEXCOORD1;
float3 Light2: TEXCOORD2;
float3 Light3: TEXCOORD3;
float3 Light4: TEXCOORD4;
float3 Diffuse1: TEXCOORD5;
float3 Diffuse2: TEXCOORD6;
float3 Diffuse3: TEXCOORD7;
float3 Diffuse4: TEXCOORD8;
};
bumpOut bump_VS(vertexIn In)
{
bumpOut Out;
Out.Pos = DoTransform(In.Pos);
Out.Tex12 = float4(In.Tex1,In.Tex2);
Out.Fog = DoFog(In.Pos);
//Out.Ambient = DoAmbient();
CreateTangents(In.Normal,In.Tangent);
float3 PosWorld = DoPos(In.Pos).xyz;
//Out.PosView = DoTangent(vecViewPos-PosWorld);
Out.Light1 = DoTangent(vecLightPos[0].xyz-PosWorld);
Out.Light2 = DoTangent(vecLightPos[1].xyz-PosWorld);
Out.Light3 = DoTangent(vecLightPos[2].xyz-PosWorld);
Out.Light4 = DoTangent(vecLightPos[3].xyz-PosWorld);
float3 Normal = DoNormal(In.Normal);
Out.Diffuse1 = DoLightFactorBump(vecLightPos[0],PosWorld,Normal) * vecLightColor[0].xyz;
Out.Diffuse2 = DoLightFactorBump(vecLightPos[1],PosWorld,Normal) * vecLightColor[1].xyz;
Out.Diffuse3 = DoLightFactorBump(vecLightPos[2],PosWorld,Normal) * vecLightColor[2].xyz;
Out.Diffuse4 = DoLightFactorBump(vecLightPos[3],PosWorld,Normal) * vecLightColor[3].xyz;
return Out;
}
float3 DoDiffuse(bumpOut In,float3 Normal)
{
float3 Diffuse = In.Diffuse1 * saturate(dot(normalize(In.Light1.xyz),Normal));
Diffuse += In.Diffuse2 * saturate(dot(normalize(In.Light2.xyz),Normal));
Diffuse += In.Diffuse3 * saturate(dot(normalize(In.Light3.xyz),Normal));
Diffuse += In.Diffuse4 * saturate(dot(normalize(In.Light4.xyz),Normal));
return Diffuse * vecDiffuse.xyz;
}
float4 diffuseBump_PS(bumpOut In): COLOR
{
float4 myambient = (vecAmbient * vecLight) + float4(vecEmissive.xyz*vecColor.xyz,vecLight.w);
float4 Base = tex2D(sBaseTex,In.Tex12.xy);
float3 Normalmap = tex2D(sSkin2,In.Tex12.xy).rgb*2-1;
float3 Diffuse = DoDiffuse(In,Normalmap);
return Base * DoColor(Diffuse,myambient);
}
float4 diffuseBumpLM_PS(bumpOut In): COLOR
{
float4 myambient = (vecAmbient * vecLight) + float4(vecEmissive.xyz*vecColor.xyz,vecLight.w);
float4 Base = tex2D(sBaseTex,In.Tex12.xy);
float4 Lightmap = tex2D(sSkin2,In.Tex12.zw);
float3 Normalmap = tex2D(sSkin3,In.Tex12.xy).rgb*2-1;
float3 Diffuse = DoDiffuse(In,Normalmap);
return Base * DoLightmap(Diffuse,Lightmap,myambient);
}
technique bump
{
pass one
{
VertexShader = compile vs_3_0 bump_VS();
PixelShader = compile ps_3_0 diffuseBump_PS();
}
}
technique bump_lm
{
pass one
{
VertexShader = compile vs_3_0 bump_VS();
PixelShader = compile ps_3_0 diffuseBumpLM_PS();
}
}
technique fallback { pass one { } }