<?xml version="1.0" encoding="utf-8" ?>
<shader compiler="xmlshader" name="std_character2">

  <?Include /shader/snippets/shaderframework-cg.inc ?>

  <?Include /shader/character/cg-skinning.inc ?>
  <?Include /shader/surface/cg-surface-classic.inc ?>
  <?Include /shader/lighting/cg-light-classic.inc ?>
  <?Include /shader/fog/cg-fog-sector.inc ?>
  <?Include /shader/surface/cg-parallax.inc ?>
  <?Include /shader/snippets/cg-mixmode-alpha.inc ?>
  
  <?Template CgProgram?>
    struct VertToFrag
    {
      float4 Hposition : POSITION;
          
      VertToFrag_Framework framework;
      
      Skinning vertSkinning;
      SurfaceClassic surfClassic;
      LightingClassic lightClassic;
      FogSector fog;
      Parallax parallax;
    };

    VertToFrag VertexMain (uniform float4x4 ModelViewProj : state.matrix.mvp,
			   varying float4 Position : POSITION)
    {
      VertToFrag V2F;
 
      // Setup and skin vertex position
      V2F.vertSkinning.SetupVert();
      V2F.Hposition = mul (ModelViewProj, 
			   V2F.vertSkinning.SkinnedPosition(Position));
      // Let the snippets setup themselves
      V2F.surfClassic.SetupVert();
      V2F.lightClassic.SetupVert();
      V2F.fog.SetupVert();
      V2F.parallax.SetupVert();
    
      V2F.framework.SetupVert();
    
      return V2F;
    }
    
    // The fragment program.
    float4 FragmentMain (VertToFrag V2F) : COLOR
    {
      V2F.framework.SetupFrag();
  
      float4 color = V2F.surfClassic.GetDiffuse (V2F.parallax.GetTCOffset()) * 
        float4 (V2F.lightClassic.IllumAmbient()+V2F.lightClassic.IllumDiffuse(),
	  GetMixmodeAlpha());
      if (V2F.fog.HasFog())
      {
        color.rgb = lerp(color.rgb, V2F.fog.GetColor(), V2F.fog.GetIntensity());
      }
      return color;
    }
    <?Endtemplate?>
  
   <?Template CgVertexOptions?>
	<profile>arbvp1</profile>
  <?Endtemplate?>
    
  <?CgSetVertexFunc VertexMain ?>   
  <?CgSetFragmentFunc FragmentMain ?>
  
  <?WriteShaderTechnique 150?>
    
  <?! Shader variables that might be used by snippets must be written out
        as well. ?>
  <?WriteShaderVars?>
  
  <!-- Last but not least, fall back to a fixed function version, for older
         hardware.-->
  
  <fallbackshader name="std_character_fixed2" file="/shader/character/std_character_fixed2.xml" />
</shader>
