FILEVERSION = 2.3.0.0;
PLATFORM = DX9;

RENDER_STATE RSC_0 {
  blendingFromSurface = true;
  rasterizerstylefromsurface = true;
  trackingmask = 3840;

  //------ Blend State Group ------
  alphatestref = 100;
  alphatestfunc = less_or_equal;

  //------ Depth Stencil Group ------

  //------ Rasterizer State Group ------
  rst_flags = 1;

  //------ Tesselation State Group ------
}

RENDER_STATE RSC_1 {
  blendingFromSurface = true;
  rasterizerstylefromsurface = true;
  trackingmask = 3840;

  //------ Blend State Group ------
  alphatestref = 100;
  alphatestfunc = less_or_equal;

  //------ Depth Stencil Group ------

  //------ Rasterizer State Group ------
  rst_flags = 1;

  //------ Tesselation State Group ------
}

RENDER_STATE RSC_2 {
  blendingFromSurface = true;
  rasterizerstylefromsurface = true;
  trackingmask = 3840;

  //------ Blend State Group ------
  alphatestref = 100;
  alphatestfunc = less_or_equal;

  //------ Depth Stencil Group ------

  //------ Rasterizer State Group ------
  rst_flags = 1;

  //------ Tesselation State Group ------
}

RENDER_STATE RSC_3 {
  blendingFromSurface = true;
  rasterizerstylefromsurface = true;
  trackingmask = 3840;

  //------ Blend State Group ------
  alphatestref = 100;
  alphatestfunc = less_or_equal;

  //------ Depth Stencil Group ------

  //------ Rasterizer State Group ------
  rst_flags = 1;

  //------ Tesselation State Group ------
}

SHADER Mixing {
  RenderStateContainerID = 0;
  IsAutoGenerated = false;
  UsesPermutationVariables = false;
  streammask = 17;
  RecompilationRequiredOnPlatforms = 0;
  supportedplatforms = 551;
  compileflags = 0;
  hs_controlpoints = 3;

  //------ Texture samplers ------
  numsamplers_vs = 0;
  numsamplers_hs = 0;
  numsamplers_ds = 0;
  numsamplers_gs = 0;
  numsamplers_ps = 6;
  SAMPLER_PS 0 = {
    samplername = "";
    texturetype = base_texture;
    textureindex = 0;
    texturefile = "";
    filtermode = default;
    textureaddressmode = wrap,wrap,wrap;
    m_fLodBias = 0.000000;
    m_iMaxAnisotropy = 1;
    comparisonfunc = less;
    bordercolor = 0.000000,0.000000,0.000000,1.000000;
    minlod = 0.000000;
    maxlod = 1024.000000;
  }
  SAMPLER_PS 1 = {
    samplername = "";
    texturetype = custom;
    textureindex = 0;
    texturefile = "";
    filtermode = default;
    textureaddressmode = wrap,wrap,wrap;
    m_fLodBias = 0.000000;
    m_iMaxAnisotropy = 1;
    comparisonfunc = less;
    bordercolor = 0.000000,0.000000,0.000000,1.000000;
    minlod = 0.000000;
    maxlod = 1024.000000;
  }
  SAMPLER_PS 2 = {
    samplername = "";
    texturetype = custom;
    textureindex = 0;
    texturefile = "";
    filtermode = default;
    textureaddressmode = wrap,wrap,wrap;
    m_fLodBias = 0.000000;
    m_iMaxAnisotropy = 1;
    comparisonfunc = less;
    bordercolor = 0.000000,0.000000,0.000000,1.000000;
    minlod = 0.000000;
    maxlod = 1024.000000;
  }
  SAMPLER_PS 3 = {
    samplername = "";
    texturetype = custom;
    textureindex = 0;
    texturefile = "";
    filtermode = default;
    textureaddressmode = wrap,wrap,wrap;
    m_fLodBias = 0.000000;
    m_iMaxAnisotropy = 1;
    comparisonfunc = less;
    bordercolor = 0.000000,0.000000,0.000000,1.000000;
    minlod = 0.000000;
    maxlod = 1024.000000;
  }
  SAMPLER_PS 4 = {
    samplername = "";
    texturetype = custom;
    textureindex = 0;
    texturefile = "";
    filtermode = default;
    textureaddressmode = wrap,wrap,wrap;
    m_fLodBias = 0.000000;
    m_iMaxAnisotropy = 1;
    comparisonfunc = less;
    bordercolor = 0.000000,0.000000,0.000000,1.000000;
    minlod = 0.000000;
    maxlod = 1024.000000;
  }
  SAMPLER_PS 5 = {
    samplername = "";
    texturetype = custom;
    textureindex = 0;
    texturefile = "";
    filtermode = default;
    textureaddressmode = wrap,wrap,wrap;
    m_fLodBias = 0.000000;
    m_iMaxAnisotropy = 1;
    comparisonfunc = less;
    bordercolor = 0.000000,0.000000,0.000000,1.000000;
    minlod = 0.000000;
    maxlod = 1024.000000;
  }
  numsamplers_cs = 0;

  //------ vertex shader source ------

  vs_sourcecode=$SOURCECODETAG{
//
#include <Shaders/VisionCommon.inc>

#ifdef _VISION_DX11
cbuffer g_GlobalConstantBufferObject : register (b1)
{
  float4x4 matWVP  : packoffset(c4); // model view projection matrix
}
#else
  float4x4 matWVP  : register(c8);
#endif

struct VS_IN
{
    float4 ObjPos   : POSITION;
    float2 UV0 : TEXCOORD0;
};

struct VS_OUT
{
   float4 ProjPos  : SV_Position;
   float2 UV0 : TEXCOORD0;
   float2 UVD0 : TEXCOORD1;
   float2 UVD1 : TEXCOORD2;
   float2 UVD2 : TEXCOORD3;
   float2 UVD3 : TEXCOORD4;
   float2 UVDbase : TEXCOORD5;
};

#ifdef _VISION_DX11
cbuffer g_GlobalConstantBufferUser : register (b2)
{
  float2 detail0scale : packoffset(c0);
  float2 detail1scale : packoffset(c1);
  float2 detail2scale : packoffset(c2);
  float2 detail3scale : packoffset(c3);
  float2 detailbasescale : packoffset(c4);
}
#else
	#if defined(_VISION_PS3) || defined(_VISION_PSP2) || defined(_VISION_GLES2) || defined(_VISION_WIIU)
	  float2 detail0scale : register(c64);
	  float2 detail1scale : register(c65);
	  float2 detail2scale : register(c66);
	  float2 detail3scale : register(c67);
	  float2 detailbasescale : register(c68);
	#else
	  float2 detail0scale;
	  float2 detail1scale;
	  float2 detail2scale;
	  float2 detail3scale;
	  float2 detailbasescale;
	#endif
#endif

VS_OUT vs_main( VS_IN In )
{
   VS_OUT Out;
   Out.ProjPos = mul( matWVP, In.ObjPos );
   Out.UV0 = In.UV0; // base texture
   Out.UVD0 = In.UV0*detail0scale; // detail 0
   Out.UVD1 = In.UV0*detail1scale; // detail 1
   Out.UVD2 = In.UV0*detail2scale; // detail 2
   Out.UVD3 = In.UV0*detail3scale; // detail 3
   Out.UVDbase = In.UV0*detailbasescale; // detail base
   return Out;
}
  }$SOURCECODETAG

  vs_function = "vs_main";
  vs_mintarget = vs_2_0;
  vs_mintargetDX11 = vs_4_0_level_9_1;
  svs_mintarget = vs_2_0;
  svs_mintargetDX11 = vs_4_0_level_9_1;

  //------ hull shader source ------
  hs_mintarget = hs_5_0;

  //------ domain shader source ------
  ds_mintarget = ds_5_0;

  //------ geometry shader source ------
  gs_mintarget = gs_4_0;
  gs_mintargetDX11 = gs_4_0;

  //------ pixel shader source ------

  ps_sourcecode=$SOURCECODETAG{
//
#include <Shaders/VisionCommon.inc>

#ifdef _VISION_DX11
  Texture2D <float4> weightingtex        : register(t0);
  sampler            weightingtexSampler : register(s0);
  Texture2D <float4> detail0tex        : register(t1);
  sampler            detail0texSampler : register(s1);
  Texture2D <float4> detail1tex        : register(t2);
  sampler            detail1texSampler : register(s2);
  Texture2D <float4> detail2tex        : register(t3);
  sampler            detail2texSampler : register(s3);
  Texture2D <float4> detail3tex        : register(t4);
  sampler            detail3texSampler : register(s4);
  Texture2D <float4> detailbasetex        : register(t5);
  sampler            detailbasetexSampler : register(s5);
#else
	sampler2D weightingtex : register(s0);
	sampler2D detail0tex : register(s1);
	sampler2D detail1tex : register(s2);
	sampler2D detail2tex : register(s3);
	sampler2D detail3tex : register(s4);
	sampler2D detailbasetex : register(s5);
#endif




struct PS_IN
{
   float4 ProjPos  : SV_Position;
   float2 UV0 : TEXCOORD0;
   float2 UVD0 : TEXCOORD1;
   float2 UVD1 : TEXCOORD2;
   float2 UVD2 : TEXCOORD3;
   float2 UVD3 : TEXCOORD4;
   float2 UVDbase : TEXCOORD5;
};


float4 ps_main( PS_IN In ) : SV_Target
{
    float4 weighting = vTex2D(weightingtex, weightingtexSampler, In.UV0);
    float4 d0 = vTex2D(detail0tex,detail0texSampler,In.UVD0);
    float4 d1 = vTex2D(detail1tex,detail1texSampler,In.UVD1);
    float4 d2 = vTex2D(detail2tex,detail2texSampler,In.UVD2);
    float4 d3 = vTex2D(detail3tex,detail3texSampler,In.UVD3);
    float4 result = vTex2D(detailbasetex,detailbasetexSampler,In.UVDbase);
    
    // mix the color like the old vision shader...
  	d3 = lerp( d3, d0, weighting.r );
  	d3 = lerp( d3, d1, weighting.g );
  	d3 = lerp( d3, d2, weighting.b );

    return d3 * result;
}
  }$SOURCECODETAG

  ps_function = "ps_main";
  ps_mintarget = ps_2_0;
  ps_mintargetDX11 = ps_4_0_level_9_1;

  //------ compute shader source ------
  cs_mintarget = cs_4_0;

  //------ platform specific bytecode ------
}

SHADER Mixingsm20 {
  RenderStateContainerID = 1;
  IsAutoGenerated = false;
  UsesPermutationVariables = false;
  streammask = 17;
  RecompilationRequiredOnPlatforms = 0;
  supportedplatforms = 551;
  compileflags = 0;
  hs_controlpoints = 3;

  //------ Texture samplers ------
  numsamplers_vs = 0;
  numsamplers_hs = 0;
  numsamplers_ds = 0;
  numsamplers_gs = 0;
  numsamplers_ps = 6;
  SAMPLER_PS 0 = {
    samplername = "";
    texturetype = base_texture;
    textureindex = 0;
    texturefile = "";
    filtermode = default;
    textureaddressmode = wrap,wrap,wrap;
    m_fLodBias = 0.000000;
    m_iMaxAnisotropy = 1;
    comparisonfunc = less;
    bordercolor = 0.000000,0.000000,0.000000,1.000000;
    minlod = 0.000000;
    maxlod = 1024.000000;
  }
  SAMPLER_PS 1 = {
    samplername = "";
    texturetype = custom;
    textureindex = 0;
    texturefile = "";
    filtermode = default;
    textureaddressmode = wrap,wrap,wrap;
    m_fLodBias = 0.000000;
    m_iMaxAnisotropy = 1;
    comparisonfunc = less;
    bordercolor = 0.000000,0.000000,0.000000,1.000000;
    minlod = 0.000000;
    maxlod = 1024.000000;
  }
  SAMPLER_PS 2 = {
    samplername = "";
    texturetype = custom;
    textureindex = 0;
    texturefile = "";
    filtermode = default;
    textureaddressmode = wrap,wrap,wrap;
    m_fLodBias = 0.000000;
    m_iMaxAnisotropy = 1;
    comparisonfunc = less;
    bordercolor = 0.000000,0.000000,0.000000,1.000000;
    minlod = 0.000000;
    maxlod = 1024.000000;
  }
  SAMPLER_PS 3 = {
    samplername = "";
    texturetype = custom;
    textureindex = 0;
    texturefile = "";
    filtermode = default;
    textureaddressmode = wrap,wrap,wrap;
    m_fLodBias = 0.000000;
    m_iMaxAnisotropy = 1;
    comparisonfunc = less;
    bordercolor = 0.000000,0.000000,0.000000,1.000000;
    minlod = 0.000000;
    maxlod = 1024.000000;
  }
  SAMPLER_PS 4 = {
    samplername = "";
    texturetype = custom;
    textureindex = 0;
    texturefile = "";
    filtermode = default;
    textureaddressmode = wrap,wrap,wrap;
    m_fLodBias = 0.000000;
    m_iMaxAnisotropy = 1;
    comparisonfunc = less;
    bordercolor = 0.000000,0.000000,0.000000,1.000000;
    minlod = 0.000000;
    maxlod = 1024.000000;
  }
  SAMPLER_PS 5 = {
    samplername = "";
    texturetype = custom;
    textureindex = 0;
    texturefile = "";
    filtermode = default;
    textureaddressmode = wrap,wrap,wrap;
    m_fLodBias = 0.000000;
    m_iMaxAnisotropy = 1;
    comparisonfunc = less;
    bordercolor = 0.000000,0.000000,0.000000,1.000000;
    minlod = 0.000000;
    maxlod = 1024.000000;
  }
  numsamplers_cs = 0;

  //------ vertex shader source ------

  vs_sourcecode=$SOURCECODETAG{
//
#include <Shaders/VisionCommon.inc>

#ifdef _VISION_DX11
cbuffer g_GlobalConstantBufferObject : register (b1)
{
  float4x4 mMV  : packoffset(c0); // model view matrix
  float4x4 mMVP  : packoffset(c4); // model view projection matrix
}
cbuffer g_GlobalConstantBufferFrame : register (b0)
{
  float3 FogParam : register(c19);
  float3 FogColor : register(c20);
}
#else
  float4x4 mMV  : register(c0);
  float4x4 mMVP  : register(c8);
  float3 FogParam : register(c62);
  float3 FogColor : register(c63);
#endif



struct VS_IN
{
    float4 ObjPos   : POSITION;
    float2 UV0 : TEXCOORD0;
};

struct VS_OUT
{
   float4 ProjPos  : SV_Position;
   float2 UV0 : TEXCOORD0;
   float2 UVD0 : TEXCOORD1;
   float2 UVD1 : TEXCOORD2;
   float2 UVD2 : TEXCOORD3;
   float2 UVD3 : TEXCOORD4;
   float2 UVDbase : TEXCOORD5;
   float4 Fog : TEXCOORD6; // xyz=fog color, w=fog weight
};

#ifdef _VISION_DX11
cbuffer g_GlobalConstantBufferUser : register (b2)
{
  float2 detail0scale : packoffset(c0);
  float2 detail1scale : packoffset(c1);
  float2 detail2scale : packoffset(c2);
  float2 detail3scale : packoffset(c3);
  float2 detailbasescale : packoffset(c4);
}
#else
#if defined(_VISION_PS3) || defined(_VISION_PSP2) || defined(_VISION_GLES2) || defined(_VISION_WIIU)
  float2 detail0scale : register(c64);
  float2 detail1scale : register(c65);
  float2 detail2scale : register(c66);
  float2 detail3scale : register(c67);
  float2 detailbasescale : register(c68);
#else
  float2 detail0scale;
  float2 detail1scale;
  float2 detail2scale;
  float2 detail3scale;
  float2 detailbasescale;
#endif
#endif

VS_OUT vs_main( VS_IN In )
{
   VS_OUT Out;
    Out.ProjPos = mul( mMVP, In.ObjPos );
   float4 eyePos = mul( mMV, In.ObjPos );;
   Out.UV0 = In.UV0; // base texture
   Out.UVD0 = In.UV0*detail0scale; // detail 0
   Out.UVD1 = In.UV0*detail1scale; // detail 1
   Out.UVD2 = In.UV0*detail2scale; // detail 2
   Out.UVD3 = In.UV0*detail3scale; // detail 3
   Out.UVDbase = In.UV0*detailbasescale; // detail base
   Out.Fog = float4(FogColor,(eyePos.z-FogParam.x)*FogParam.z);
   return Out;
}
  }$SOURCECODETAG

  vs_function = "vs_main";
  vs_mintarget = vs_2_0;
  vs_mintargetDX11 = vs_4_0_level_9_1;
  svs_mintarget = vs_2_0;
  svs_mintargetDX11 = vs_4_0_level_9_1;

  //------ hull shader source ------
  hs_mintarget = hs_5_0;

  //------ domain shader source ------
  ds_mintarget = ds_5_0;

  //------ geometry shader source ------
  gs_mintarget = gs_4_0;
  gs_mintargetDX11 = gs_4_0;

  //------ pixel shader source ------

  ps_sourcecode=$SOURCECODETAG{
//
#include <Shaders/VisionCommon.inc>

#ifdef _VISION_DX11
  Texture2D <float4> weightingtex        : register(t0);
  sampler            weightingtexSampler : register(s0);
  Texture2D <float4> detail0tex        : register(t1);
  sampler            detail0texSampler : register(s1);
  Texture2D <float4> detail1tex        : register(t2);
  sampler            detail1texSampler : register(s2);
  Texture2D <float4> detail2tex        : register(t3);
  sampler            detail2texSampler : register(s3);
  Texture2D <float4> detail3tex        : register(t4);
  sampler            detail3texSampler : register(s4);
  Texture2D <float4> detailbasetex        : register(t5);
  sampler            detailbasetexSampler : register(s5);
#else
	sampler2D weightingtex : register(s0);
	sampler2D detail0tex : register(s1);
	sampler2D detail1tex : register(s2);
	sampler2D detail2tex : register(s3);
	sampler2D detail3tex : register(s4);
	sampler2D detailbasetex : register(s5);
#endif

struct PS_IN
{
   float4 ProjPos  : SV_Position;
   float2 UV0 : TEXCOORD0;
   float2 UVD0 : TEXCOORD1;
   float2 UVD1 : TEXCOORD2;
   float2 UVD2 : TEXCOORD3;
   float2 UVD3 : TEXCOORD4;
   float2 UVDbase : TEXCOORD5;
   float4 Fog : TEXCOORD6;
};


float4 ps_main( PS_IN In ) : SV_Target
{
    float4 weighting = vTex2D(weightingtex, weightingtexSampler, In.UV0);
    float4 d0 = vTex2D(detail0tex,detail0texSampler,In.UVD0);
    float4 d1 = vTex2D(detail1tex,detail1texSampler,In.UVD1);
    float4 d2 = vTex2D(detail2tex,detail2texSampler,In.UVD2);
    float4 d3 = vTex2D(detail3tex,detail3texSampler,In.UVD3);
    float4 result = vTex2D(detailbasetex,detailbasetexSampler,In.UVDbase);
    
    // mix the color like the old vision shader...
  	d3 = lerp( d3, d0, weighting.r );
  	d3 = lerp( d3, d1, weighting.g );
  	d3 = lerp( d3, d2, weighting.b );

    float4 finalResult = d3 * result;
    finalResult.xyz = lerp(finalResult,In.Fog.xyz,clamp(In.Fog.w,0,1));
    return finalResult;
}
  }$SOURCECODETAG

  ps_function = "ps_main";
  ps_mintarget = ps_2_0;
  ps_mintargetDX11 = ps_4_0_level_9_1;

  //------ compute shader source ------
  cs_mintarget = cs_4_0;

  //------ platform specific bytecode ------
}

SHADER Mixingsm20_lightmap {
  RenderStateContainerID = 2;
  IsAutoGenerated = false;
  UsesPermutationVariables = false;
  streammask = 49;
  RecompilationRequiredOnPlatforms = 0;
  supportedplatforms = 551;
  compileflags = 0;
  hs_controlpoints = 3;

  //------ Texture samplers ------
  numsamplers_vs = 0;
  numsamplers_hs = 0;
  numsamplers_ds = 0;
  numsamplers_gs = 0;
  numsamplers_ps = 7;
  SAMPLER_PS 0 = {
    samplername = "";
    texturetype = base_texture;
    textureindex = 0;
    texturefile = "";
    filtermode = default;
    textureaddressmode = wrap,wrap,wrap;
    m_fLodBias = 0.000000;
    m_iMaxAnisotropy = 1;
    comparisonfunc = less;
    bordercolor = 0.000000,0.000000,0.000000,1.000000;
    minlod = 0.000000;
    maxlod = 1024.000000;
  }
  SAMPLER_PS 1 = {
    samplername = "";
    texturetype = custom;
    textureindex = 0;
    texturefile = "";
    filtermode = default;
    textureaddressmode = wrap,wrap,wrap;
    m_fLodBias = 0.000000;
    m_iMaxAnisotropy = 1;
    comparisonfunc = less;
    bordercolor = 0.000000,0.000000,0.000000,1.000000;
    minlod = 0.000000;
    maxlod = 1024.000000;
  }
  SAMPLER_PS 2 = {
    samplername = "";
    texturetype = custom;
    textureindex = 0;
    texturefile = "";
    filtermode = default;
    textureaddressmode = wrap,wrap,wrap;
    m_fLodBias = 0.000000;
    m_iMaxAnisotropy = 1;
    comparisonfunc = less;
    bordercolor = 0.000000,0.000000,0.000000,1.000000;
    minlod = 0.000000;
    maxlod = 1024.000000;
  }
  SAMPLER_PS 3 = {
    samplername = "";
    texturetype = custom;
    textureindex = 0;
    texturefile = "";
    filtermode = default;
    textureaddressmode = wrap,wrap,wrap;
    m_fLodBias = 0.000000;
    m_iMaxAnisotropy = 1;
    comparisonfunc = less;
    bordercolor = 0.000000,0.000000,0.000000,1.000000;
    minlod = 0.000000;
    maxlod = 1024.000000;
  }
  SAMPLER_PS 4 = {
    samplername = "";
    texturetype = custom;
    textureindex = 0;
    texturefile = "";
    filtermode = default;
    textureaddressmode = wrap,wrap,wrap;
    m_fLodBias = 0.000000;
    m_iMaxAnisotropy = 1;
    comparisonfunc = less;
    bordercolor = 0.000000,0.000000,0.000000,1.000000;
    minlod = 0.000000;
    maxlod = 1024.000000;
  }
  SAMPLER_PS 5 = {
    samplername = "";
    texturetype = custom;
    textureindex = 0;
    texturefile = "";
    filtermode = default;
    textureaddressmode = wrap,wrap,wrap;
    m_fLodBias = 0.000000;
    m_iMaxAnisotropy = 1;
    comparisonfunc = less;
    bordercolor = 0.000000,0.000000,0.000000,1.000000;
    minlod = 0.000000;
    maxlod = 1024.000000;
  }
  SAMPLER_PS 6 = {
    samplername = "";
    texturetype = lightmap;
    textureindex = 0;
    texturefile = "";
    filtermode = default;
    textureaddressmode = wrap,wrap,wrap;
    m_fLodBias = 0.000000;
    m_iMaxAnisotropy = 1;
    comparisonfunc = less;
    bordercolor = 0.000000,0.000000,0.000000,1.000000;
    minlod = 0.000000;
    maxlod = 1024.000000;
  }
  numsamplers_cs = 0;

  //------ vertex shader source ------

  vs_sourcecode=$SOURCECODETAG{
//
#include <Shaders/VisionCommon.inc>

#ifdef _VISION_DX11
cbuffer g_GlobalConstantBufferObject : register (b1)
{
  float4x4 mMV  : packoffset(c0); // model view matrix
  float4x4 mMVP  : packoffset(c4); // model view projection matrix
}
cbuffer g_GlobalConstantBufferFrame : register (b0)
{
  float3 FogParam : packoffset(c19);
  float3 FogColor : packoffset(c20);
}
#else
  float4x4 mMV  : register(c0);
  float4x4 mMVP  : register(c8);
  float3 FogParam : register(c62);
  float3 FogColor : register(c63);
#endif



struct VS_IN
{
    float4 ObjPos   : POSITION;
    float2 UV0 : TEXCOORD0;
    float2 Lightmaptex : TEXCOORD1;
};

struct VS_OUT
{
   float4 ProjPos  : SV_Position;
   float2 UV0 : TEXCOORD0;
   float2 UVD0 : TEXCOORD1;
   float2 UVD1 : TEXCOORD2;
   float2 UVD2 : TEXCOORD3;
   float2 UVD3 : TEXCOORD4;
   float2 UVDbase : TEXCOORD5;
   float4 Fog : TEXCOORD6; // xyz=fog color, w=fog weight
   float2 Lightmaptex : TEXCOORD7; 
};

#ifdef _VISION_DX11
cbuffer g_GlobalConstantBufferUser : register (b2)
{
  float2 detail0scale : packoffset(c0);
  float2 detail1scale : packoffset(c1);
  float2 detail2scale : packoffset(c2);
  float2 detail3scale : packoffset(c3);
  float2 detailbasescale : packoffset(c4);
}
#else
#if defined(_VISION_PS3) || defined(_VISION_PSP2) || defined(_VISION_GLES2) || defined(_VISION_WIIU)
  float2 detail0scale : register(c64);
  float2 detail1scale : register(c65);
  float2 detail2scale : register(c66);
  float2 detail3scale : register(c67);
  float2 detailbasescale : register(c68);
#else
  float2 detail0scale;
  float2 detail1scale;
  float2 detail2scale;
  float2 detail3scale;
  float2 detailbasescale;
#endif
#endif

VS_OUT vs_main( VS_IN In )
{
   VS_OUT Out;
    Out.ProjPos = mul( mMVP, In.ObjPos );
   float4 eyePos = mul( mMV, In.ObjPos );;
   Out.UV0 = In.UV0; // base texture
   Out.UVD0 = In.UV0*detail0scale; // detail 0
   Out.UVD1 = In.UV0*detail1scale; // detail 1
   Out.UVD2 = In.UV0*detail2scale; // detail 2
   Out.UVD3 = In.UV0*detail3scale; // detail 3
   Out.UVDbase = In.UV0*detailbasescale; // detail base
   Out.Fog = float4(FogColor,(eyePos.z-FogParam.x)*FogParam.z);
   Out.Lightmaptex = In.Lightmaptex;
   return Out;
}
  }$SOURCECODETAG

  vs_function = "vs_main";
  vs_mintarget = vs_2_0;
  vs_mintargetDX11 = vs_4_0_level_9_1;
  svs_mintarget = vs_2_0;
  svs_mintargetDX11 = vs_4_0_level_9_1;

  //------ hull shader source ------
  hs_mintarget = hs_5_0;

  //------ domain shader source ------
  ds_mintarget = ds_5_0;

  //------ geometry shader source ------
  gs_mintarget = gs_4_0;
  gs_mintargetDX11 = gs_4_0;

  //------ pixel shader source ------

  ps_sourcecode=$SOURCECODETAG{
//
#include <Shaders/VisionCommon.inc>

#ifdef _VISION_DX11
  Texture2D <float4> weightingtex        : register(t0);
  sampler            weightingtexSampler : register(s0);
  Texture2D <float4> detail0tex        : register(t1);
  sampler            detail0texSampler : register(s1);
  Texture2D <float4> detail1tex        : register(t2);
  sampler            detail1texSampler : register(s2);
  Texture2D <float4> detail2tex        : register(t3);
  sampler            detail2texSampler : register(s3);
  Texture2D <float4> detail3tex        : register(t4);
  sampler            detail3texSampler : register(s4);
  Texture2D <float4> detailbasetex        : register(t5);
  sampler            detailbasetexSampler : register(s5);
  Texture2D <float4> Lightmap        : register(t6);
  sampler            LightmapSampler : register(s6);
#else
	sampler2D weightingtex : register(s0);
	sampler2D detail0tex : register(s1);
	sampler2D detail1tex : register(s2);
	sampler2D detail2tex : register(s3);
	sampler2D detail3tex : register(s4);
	sampler2D detailbasetex : register(s5);
	sampler2D Lightmap : register(s6);
#endif

#ifdef _VISION_DX11
cbuffer g_GlobalConstantBufferFrame : register (b0)
{
  float4 LightmapMult : register(c22);
}
#else
  float4 LightmapMult : register(c0);
#endif


struct PS_IN
{
   float4 ProjPos  : SV_Position;
   float2 UV0 : TEXCOORD0;
   float2 UVD0 : TEXCOORD1;
   float2 UVD1 : TEXCOORD2;
   float2 UVD2 : TEXCOORD3;
   float2 UVD3 : TEXCOORD4;
   float2 UVDbase : TEXCOORD5;
   float4 Fog : TEXCOORD6;
   float2 Lightmaptex : TEXCOORD7;
};


float4 ps_main( PS_IN In ) : SV_Target
{
    float4 weighting = vTex2D(weightingtex, weightingtexSampler, In.UV0);
    float4 d0 = vTex2D(detail0tex,detail0texSampler,In.UVD0);
    float4 d1 = vTex2D(detail1tex,detail1texSampler,In.UVD1);
    float4 d2 = vTex2D(detail2tex,detail2texSampler,In.UVD2);
    float4 d3 = vTex2D(detail3tex,detail3texSampler,In.UVD3);
    float4 result = vTex2D(detailbasetex,detailbasetexSampler,In.UVDbase);
    float4 Lmap = vTex2D(Lightmap, LightmapSampler, In.Lightmaptex);// * LightmapMult.x;
    
    // mix the color like the old vision shader...
  	d3 = lerp( d3, d0, weighting.r );
  	d3 = lerp( d3, d1, weighting.g );
  	d3 = lerp( d3, d2, weighting.b );

    float4 finalResult = d3 * result * Lmap;
    finalResult.xyz = lerp(finalResult,In.Fog.xyz,clamp(In.Fog.w,0,1));
    return finalResult;
}
  }$SOURCECODETAG

  ps_function = "ps_main";
  ps_mintarget = ps_2_0;
  ps_mintargetDX11 = ps_4_0_level_9_1;

  //------ compute shader source ------
  cs_mintarget = cs_4_0;

  //------ platform specific bytecode ------
}

SHADER Mixing_Lmap_fog {
  RenderStateContainerID = 3;
  IsAutoGenerated = false;
  UsesPermutationVariables = false;
  streammask = 17;
  RecompilationRequiredOnPlatforms = 0;
  supportedplatforms = 551;
  compileflags = 0;
  hs_controlpoints = 3;

  //------ Texture samplers ------
  numsamplers_vs = 0;
  numsamplers_hs = 0;
  numsamplers_ds = 0;
  numsamplers_gs = 0;
  numsamplers_ps = 7;
  SAMPLER_PS 0 = {
    samplername = "";
    texturetype = base_texture;
    textureindex = 0;
    texturefile = "";
    filtermode = default;
    textureaddressmode = wrap,wrap,wrap;
    m_fLodBias = 0.000000;
    m_iMaxAnisotropy = 1;
    comparisonfunc = less;
    bordercolor = 0.000000,0.000000,0.000000,1.000000;
    minlod = 0.000000;
    maxlod = 1024.000000;
  }
  SAMPLER_PS 1 = {
    samplername = "";
    texturetype = lightmap;
    textureindex = 0;
    texturefile = "";
    filtermode = default;
    textureaddressmode = wrap,wrap,wrap;
    m_fLodBias = 0.000000;
    m_iMaxAnisotropy = 1;
    comparisonfunc = less;
    bordercolor = 0.000000,0.000000,0.000000,1.000000;
    minlod = 0.000000;
    maxlod = 1024.000000;
  }
  SAMPLER_PS 2 = {
    samplername = "";
    texturetype = custom;
    textureindex = 0;
    texturefile = "";
    filtermode = default;
    textureaddressmode = wrap,wrap,wrap;
    m_fLodBias = 0.000000;
    m_iMaxAnisotropy = 16;
    comparisonfunc = less;
    bordercolor = 0.000000,0.000000,0.000000,1.000000;
    minlod = 0.000000;
    maxlod = 1024.000000;
  }
  SAMPLER_PS 3 = {
    samplername = "";
    texturetype = custom;
    textureindex = 0;
    texturefile = "";
    filtermode = default;
    textureaddressmode = wrap,wrap,wrap;
    m_fLodBias = 0.000000;
    m_iMaxAnisotropy = 16;
    comparisonfunc = less;
    bordercolor = 0.000000,0.000000,0.000000,1.000000;
    minlod = 0.000000;
    maxlod = 1024.000000;
  }
  SAMPLER_PS 4 = {
    samplername = "";
    texturetype = custom;
    textureindex = 0;
    texturefile = "";
    filtermode = default;
    textureaddressmode = wrap,wrap,wrap;
    m_fLodBias = 0.000000;
    m_iMaxAnisotropy = 16;
    comparisonfunc = less;
    bordercolor = 0.000000,0.000000,0.000000,1.000000;
    minlod = 0.000000;
    maxlod = 1024.000000;
  }
  SAMPLER_PS 5 = {
    samplername = "";
    texturetype = custom;
    textureindex = 0;
    texturefile = "";
    filtermode = default;
    textureaddressmode = wrap,wrap,wrap;
    m_fLodBias = 0.000000;
    m_iMaxAnisotropy = 16;
    comparisonfunc = less;
    bordercolor = 0.000000,0.000000,0.000000,1.000000;
    minlod = 0.000000;
    maxlod = 1024.000000;
  }
  SAMPLER_PS 6 = {
    samplername = "";
    texturetype = lightmap;
    textureindex = 0;
    texturefile = "";
    filtermode = default;
    textureaddressmode = wrap,wrap,wrap;
    m_fLodBias = 0.000000;
    m_iMaxAnisotropy = 16;
    comparisonfunc = less;
    bordercolor = 0.000000,0.000000,0.000000,1.000000;
    minlod = 0.000000;
    maxlod = 1024.000000;
  }
  numsamplers_cs = 0;

  //------ vertex shader source ------

  vs_sourcecode=$SOURCECODETAG{
//
#include <Shaders/VisionCommon.inc>

#ifdef _VISION_DX11
cbuffer g_GlobalConstantBufferObject : register (b1)
{
  float4x4 mMV  : packoffset(c0); // model view matrix
  float4x4 mMVP  : packoffset(c4); // model view projection matrix
}
cbuffer g_GlobalConstantBufferFrame : register (b0)
{
  float3 FogParam : packoffset(c19);
  float3 FogColor : packoffset(c20);
}
#else
  float4x4 mMV  : register(c0);
  float4x4 mMVP  : register(c8);
  float3 FogParam : register(c62);
  float3 FogColor : register(c63);
#endif


struct VS_IN                   
{                              
  float4 ObjPos   : POSITION;
  float2 UV0 : TEXCOORD0;
  float2 UV1 : TEXCOORD1;
};                                           

struct VS_OUT                                 
{                                             
  float4 ProjPos  : SV_Position;              
  float2 UV0 : TEXCOORD0;
  float2 UV1 : TEXCOORD1;
  float2 UVD0 : TEXCOORD2;
  float2 UVD1 : TEXCOORD3;
  float2 UVD2 : TEXCOORD4;
  float2 UVD3 : TEXCOORD5;
  float2 UVDbase : TEXCOORD6;
  float4 Fog : TEXCOORD7; // xyz=fog color, w=fog weight
};                                             

#ifdef _VISION_DX11
cbuffer g_GlobalConstantBufferUser : register (b2)
{
  float2 detail0scale : packoffset(c0);
  float2 detail1scale : packoffset(c1);
  float2 detail2scale : packoffset(c2);
  float2 detail3scale : packoffset(c3);
  float2 detailbasescale : packoffset(c4);
}
#else
#if defined(_VISION_PS3) || defined(_VISION_PSP2) || defined(_VISION_GLES2) || defined(_VISION_WIIU)
  float2 detail0scale : register(c64);
  float2 detail1scale : register(c65);
  float2 detail2scale : register(c66);
  float2 detail3scale : register(c67);
  float2 detailbasescale : register(c68);
#else
  float2 detail0scale;
  float2 detail1scale;
  float2 detail2scale;
  float2 detail3scale;
  float2 detailbasescale;
#endif
#endif

VS_OUT vs_main( VS_IN In )                        
{                                              
  VS_OUT Out;                                
  Out.ProjPos = mul( mMVP, In.ObjPos );
  //float4 eyePos = mul( mMV, In.ObjPos );  
  Out.UV0 = In.UV0;
  Out.UV1 = In.UV1;
  Out.Fog = float4(FogColor,(Out.ProjPos.z-FogParam.x)*FogParam.z);
  Out.UVD0 = In.UV0*detail0scale; // detail 0
  Out.UVD1 = In.UV0*detail1scale; // detail 1
  Out.UVD2 = In.UV0*detail2scale; // detail 2
  Out.UVD3 = In.UV0*detail3scale; // detail 3
  Out.UVDbase = In.UV0*detailbasescale;
  return Out;                              
}
  }$SOURCECODETAG

  vs_function = "vs_main";
  vs_mintarget = vs_2_0;
  vs_mintargetDX11 = vs_4_0_level_9_1;
  svs_mintarget = vs_2_0;
  svs_mintargetDX11 = vs_4_0_level_9_1;

  //------ hull shader source ------
  hs_mintarget = hs_5_0;

  //------ domain shader source ------
  ds_mintarget = ds_5_0;

  //------ geometry shader source ------
  gs_mintarget = gs_4_0;
  gs_mintargetDX11 = gs_4_0;

  //------ pixel shader source ------

  ps_sourcecode=$SOURCECODETAG{
//
#include <Shaders/VisionCommon.inc>

#ifdef _VISION_DX11
  Texture2D <float4> weightingtex        : register(t0);
  sampler            weightingtexSampler : register(s0);
  Texture2D <float4> detail0tex        : register(t1);
  sampler            detail0texSampler : register(s1);
  Texture2D <float4> detail1tex        : register(t2);
  sampler            detail1texSampler : register(s2);
  Texture2D <float4> detail2tex        : register(t3);
  sampler            detail2texSampler : register(s3);
  Texture2D <float4> detail3tex        : register(t4);
  sampler            detail3texSampler : register(s4);
  Texture2D <float4> detailbasetex        : register(t5);
  sampler            detailbasetexSampler : register(s5);
  Texture2D <float4> Lightmap        : register(t6);
  sampler            LightmapSampler : register(s6);
#else
	sampler2D weightingtex : register(s0);
	sampler2D detail0tex : register(s1);
	sampler2D detail1tex : register(s2);
	sampler2D detail2tex : register(s3);
	sampler2D detail3tex : register(s4);
	sampler2D detailbasetex : register(s5);
	sampler2D Lightmap : register(s6);
#endif

#ifdef _VISION_DX11
cbuffer g_GlobalConstantBufferFrame : register (b0)
{
  float4 LightmapMult : register(c22);
}
#else
  float4 LightmapMult : register(c0);
#endif

struct PS_IN
{                  
  float4 ProjPos  : SV_Position;
  float2 UV0 : TEXCOORD0; 
  float2 UV1 : TEXCOORD1; 
  float2 UVD0 : TEXCOORD2;
  float2 UVD1 : TEXCOORD3;
  float2 UVD2 : TEXCOORD4;
  float2 UVD3 : TEXCOORD5;
  float2 UVDbase : TEXCOORD6;
  float4 Fog : TEXCOORD7;
};

float4 ps_main( PS_IN In ) : SV_Target
{
    float4 weighting = vTex2D(weightingtex, weightingtexSampler, In.UV0);
    float4 d0 = vTex2D(detail0tex,detail0texSampler,In.UVD0);
    float4 d1 = vTex2D(detail1tex,detail1texSampler,In.UVD1);
    float4 d2 = vTex2D(detail2tex,detail2texSampler,In.UVD2);
    float4 d3 = vTex2D(detail3tex,detail3texSampler,In.UVD3);
    float4 result = vTex2D(detailbasetex,detailbasetexSampler,In.UVDbase);
    float4 Lmap = vTex2D(Lightmap, LightmapSampler, In.UV1);// * LightmapMult.x;
    
    d3 = lerp( d3, d0, weighting.r );
  	d3 = lerp( d3, d1, weighting.g );
  	d3 = lerp( d3, d2, weighting.b );
    
  result = result * d3 * Lmap;
  //float4 result =  tex2D(BaseTexture, In.UV0) * tex2D(LightMap, In.UV1) * LightmapMult.x;
  result.xyz = lerp(result,In.Fog.xyz,clamp(In.Fog.w,0,1));
  return result;
}
  }$SOURCECODETAG

  ps_function = "ps_main";
  ps_mintarget = ps_2_0;
  ps_mintargetDX11 = ps_4_0_level_9_1;

  //------ compute shader source ------
  cs_mintarget = cs_4_0;

  //------ platform specific bytecode ------
}

//////////////////////////////////////////////////////////////////////////////

EFFECT landscape_mix {
  DESCRIPTION = {};
  PARAMCOMMENT={"weightingtex","","",texture,texturefile};
  PARAMCOMMENT={"detailbasetex","","",texture,texturefile};
  PARAMCOMMENT={"detail0tex","","",texture,none};
  PARAMCOMMENT={"detail1tex","","",texture,none};
  PARAMCOMMENT={"detail2tex","","",texture,none};
  PARAMCOMMENT={"detail3tex","","",texture,none};
  PARAMCOMMENT={"detailbasescale","","1,1",float2,none};
  PARAMCOMMENT={"detail0scale","","100,100",float2,none};
  PARAMCOMMENT={"detail1scale","","100,100",float2,none};
  PARAMCOMMENT={"detail2scale","","100,100",float2,none};
  PARAMCOMMENT={"detail3scale","","100,100",float2,none};
  TECHNIQUE "sm20"
  {
    passes="Mixingsm20";
    passtype = pre_basepass;
    IsPermutationTechnique=false;
    IsAutoGenerated=false;
  }
  TECHNIQUE "all"
  {
    passes="Mixing";
    passtype = pre_basepass;
    IsPermutationTechnique=false;
    IsAutoGenerated=false;
  }
}

EFFECT landscape_mix_lightmap {
  DESCRIPTION = {};
  PARAMCOMMENT={"weightingtex","","",texture,texturefile};
  PARAMCOMMENT={"detailbasetex","","",texture,texturefile};
  PARAMCOMMENT={"detail0tex","","",texture,none};
  PARAMCOMMENT={"detail1tex","","",texture,none};
  PARAMCOMMENT={"detail2tex","","",texture,none};
  PARAMCOMMENT={"detail3tex","","",texture,none};
  PARAMCOMMENT={"detailbasescale","","1,1",float2,none};
  PARAMCOMMENT={"detail0scale","","20,20",float2,none};
  PARAMCOMMENT={"detail1scale","","20,20",float2,none};
  PARAMCOMMENT={"detail2scale","","20,20",float2,none};
  PARAMCOMMENT={"detail3scale","","20,20",float2,none};
  TECHNIQUE "sm20"
  {
    passes="Mixing_Lmap_fog";
    passtype = pre_basepass;
    IsPermutationTechnique=false;
    IsAutoGenerated=false;
  }
  TECHNIQUE "all"
  {
    passes="Mixing";
    passtype = pre_basepass;
    IsPermutationTechnique=false;
    IsAutoGenerated=false;
  }
}

