How would you make it so the model is lit by the sun differently as it turns(faces sun it's brighter, not facing sun it's darker). Currently, it takes the suns position and uses that on the model, but it does not change as you rotate the model(seems local). It's an environment mapping by the alpha map shader.
Code:
extern matrix matWorldViewProj;
extern matrix matWorldInv;
extern matrix matWorldView;
extern float4 vecFog;
extern matrix matWorld;
extern float3 vecViewPos;
extern texture entSkin1;
extern texture entSkin2;
extern texture mtlSkin1;
extern float4 vecAmbient;
extern float4 vecDiffuse;
extern float4 vecSunDir;
extern float4 vecLight;
sampler colorMap = sampler_state
{ Texture = (entSkin1);
MINFILTER = LINEAR; MIPFILTER = LINEAR; MAGFILTER = LINEAR; };
sampler envmap = sampler_state
{ Texture = (mtlSkin1);
MINFILTER = LINEAR; MIPFILTER = LINEAR; MAGFILTER = LINEAR; };
struct VS_INPUT0
{
float4 pos: POSITION;
float2 texCoord0: TEXCOORD0;
float4 normal: NORMAL;
};
struct VS_OUTPUT0
{
float4 pos: POSITION;
float2 texCoord0: TEXCOORD0;
float3 texCoord1: TEXCOORD1;
float4 diffuse: COLOR;
float fog: FOG;
};
struct PS_INPUT0
{
float2 texCoord0: TEXCOORD0;
float3 texCoord1: TEXCOORD1;
float4 diffuse: COLOR;
};
float DoFog(float4 Pos)
{
// convert the vector position to view space to get it's depth (.z)
float3 P = mul(Pos,matWorldView);
// apply the linear fog formula
return saturate((vecFog.y-P.z) * vecFog.z);
}
VS_OUTPUT0 vs_main0( VS_INPUT0 In )
{
VS_OUTPUT0 Out;
Out.pos = mul(In.pos,matWorldViewProj);
float3 I = In.pos - mul(vecViewPos,matWorld);
float3 Position_World = mul(In.pos, matWorld).xyzw;
float3 Normal_World = normalize(mul(In.normal, (float3x3)matWorld));
float3 Refl_Proj = Position_World - vecViewPos;
Out.texCoord0 = In.texCoord0;
Out.texCoord1 = reflect( Refl_Proj , Normal_World );
Out.diffuse = dot(vecSunDir.xyz,In.normal)*vecDiffuse;
Out.fog = DoFog(In.pos);
return Out;
}
float4 ps_main0( PS_INPUT0 In ) : COLOR0
{
float4 color = tex2D(colorMap,In.texCoord0);
float3 reflection = texCUBE( envmap, In.texCoord1 );
color.rgb = lerp((color * In.diffuse * 2),reflection,color.a);
color.a = 1.0f;
return (color);
}
technique t0
{
pass p0 //colormap
{
AlphaBlendEnable=true;
zwriteenable= true;
zenable = true;
//FogEnable=true;
//AlphaBlendEnable=true;
//SrcBlend=srcAlpha;
//DestBlend=destAlpha;
//zwriteenable= true;
//zenable = true;
VertexShader = compile vs_1_0 vs_main0();
PixelShader = compile ps_1_0 ps_main0();
}
}