//*****************************************************************************
// TGEA -- HLSL procedural shader                                              
//*****************************************************************************
//-----------------------------------------------------------------------------
// Structures                                                                  
//-----------------------------------------------------------------------------
// Features:
// Vert Position
// Base Texture
// Dynamic Lighting
// Dynamic Lighting Dummy
// Bumpmap
struct ConnectData
{
   float2 texCoord        : TEXCOORD0;
   float4 dlightCoord     : TEXCOORD1;
   float4 dlightCoordSec  : TEXCOORD2;
   float3 lightVec        : TEXCOORD3;
   float3 lightVecSec     : TEXCOORD4;
};


struct Fragout
{
   float4 col : COLOR0;
};


//-----------------------------------------------------------------------------
// Main                                                                        
//-----------------------------------------------------------------------------
Fragout main( ConnectData IN,
              uniform sampler2D diffuseMap      : register(S0),
              uniform sampler3D dlightMap       : register(S1),
              uniform float4    lightColor      : register(C0),
              uniform sampler3D dlightMapSec    : register(S2),
              uniform float4    lightColorSec   : register(C1),
              uniform sampler2D bumpMap         : register(S3),
              uniform float4    ambient         : register(C2)
)
{
   Fragout OUT;

   float4 diffuseColor = tex2D(diffuseMap, IN.texCoord);
   OUT.col = diffuseColor;
   OUT.col.a = 1.0;
   float4 attn = tex3D(dlightMap, IN.dlightCoord) * lightColor;
   float4 attnsec = tex3D(dlightMapSec, IN.dlightCoordSec) * lightColorSec;
   OUT.col *= attn;
   float4 bumpNormal = tex2D(bumpMap, IN.texCoord);
   bumpNormal.xyz = bumpNormal.xyz * 2.0 - 1.0;

   float4 bumpDot = saturate( dot(bumpNormal.xyz, normalize(IN.lightVec.xyz)) * IN.dlightCoord.w );
   attnsec *= saturate( dot(bumpNormal.xyz, normalize(IN.lightVecSec.xyz)) * IN.dlightCoordSec.w );
   float shadowed = 1.0;
   OUT.col *= bumpDot;
   OUT.col += (attnsec * diffuseColor);

   return OUT;
}
