//**************************************************************//
//  Effect File exported by RenderMonkey 1.6
//
//  - Although many improvements were made to RenderMonkey FX  
//    file export, there are still situations that may cause   
//    compilation problems once the file is exported, such as  
//    occasional naming conflicts for methods, since FX format 
//    does not support any notions of name spaces. You need to 
//    try to create workspaces in such a way as to minimize    
//    potential naming conflicts on export.                    
//    
//  - Note that to minimize resulting name collisions in the FX 
//    file, RenderMonkey will mangle names for passes, shaders  
//    and function names as necessary to reduce name conflicts. 
//**************************************************************//

//--------------------------------------------------------------//
// Inferno
//--------------------------------------------------------------//
//--------------------------------------------------------------//
// Single Pass
//--------------------------------------------------------------//
//string Fire_Effects_Inferno_Single_Pass_ScreenAlignedQuad : ModelData = "../Program Files (x86)/ATI Research Inc/RenderMonkey 1.6/Examples/Media/Models/ScreenAlignedQuad.3ds";

float4x4 WorldViewProj : WorldViewProjection < string UIWidget = "None"; >;


/* data from application vertex buffer */
struct Appdata {
    float3 Position	: POSITION;
    float2 UV		: TEXCOORD0;
    float3 Normal	: NORMAL;
    float3 Tangent	: TANGENT0;
    float3 Binormal	: BINORMAL0;
};
 
struct VertexOutput {
    float4 HPosition : POSITION;
    float2 TexCoord	: TEXCOORD0;
};



VertexOutput Fire_Effects_Inferno_Single_Pass_Vertex_Shader_main(Appdata IN)
{
   VertexOutput OUT;
   float4 Po = float4(IN.Position.xyz,1.0);
   OUT.HPosition = mul(Po, WorldViewProj);
   OUT.TexCoord = IN.UV;

   // Clean up inaccuracies   
  // Pos.xy = sign(Pos.xy);

  // Out.Pos = float4(Pos.xy, 0, 1);
   // Image-space
   //Out.TextureUV = 0.5 * Pos.xy;

   return OUT;
}










float time_0_X : Time0_X;
float sideFade
<
   string UIName = "sideFade";
   string UIWidget = "Numeric";
   bool UIVisible = true;
   float UIMin = 0.00;
   float UIMax = 30.00;
> = 18.60;
float sideFadeSharpness
<
   string UIName = "sideFadeSharpness";
   string UIWidget = "Numeric";
   bool UIVisible = true;
   float UIMin = 0.00;
   float UIMax = 1.00;
> = 0.05;
float wobbleScale
<
   string UIName = "wobbleScale";
   string UIWidget = "Numeric";
   bool UIVisible = true;
   float UIMin = 0.00;
   float UIMax = 0.10;
> = 0.03;
float burnSpeed
<
   string UIName = "burnSpeed";
   string UIWidget = "Numeric";
   bool UIVisible = true;
   float UIMin = 0.00;
   float UIMax = 1.00;
> = 0.57;
float randomnessRate
<
   string UIName = "randomnessRate";
   string UIWidget = "Numeric";
   bool UIVisible = true;
   float UIMin = 0.00;
   float UIMax = 1.00;
> = 0.24;
float yFade
<
   string UIName = "yFade";
   string UIWidget = "Numeric";
   bool UIVisible = true;
   float UIMin = 0.00;
   float UIMax = 2.00;
> = 0.60;
float xScale
<
   string UIName = "xScale";
   string UIWidget = "Numeric";
   bool UIVisible = true;
   float UIMin = 0.00;
   float UIMax = 3.00;
> = 1.50;
float yScale
<
   string UIName = "yScale";
   string UIWidget = "Numeric";
   bool UIVisible = true;
   float UIMin = 0.00;
   float UIMax = 1.50;
> = 0.60;

texture Flame_Tex
<
   string ResourceName = "Flame.tga";
>;
sampler Flame = sampler_state
{
   Texture = (Flame_Tex);
   ADDRESSU = CLAMP;
   ADDRESSV = CLAMP;
   MAGFILTER = LINEAR;
   MINFILTER = LINEAR;
   MIPFILTER = LINEAR;
};
texture Noise_Tex
<
   string ResourceName = "NoiseVolume.dds";
>;
sampler Noise = sampler_state
{
   Texture = (Noise_Tex);
   ADDRESSU = WRAP;
   ADDRESSV = WRAP;
   ADDRESSW = WRAP;
   MAGFILTER = LINEAR;
   MINFILTER = LINEAR;
   MIPFILTER = LINEAR;
};

float4 Fire_Effects_Inferno_Single_Pass_Pixel_Shader_main(VertexOutput IN) : COLOR 
{
    // Wobble for the noise to get a more realistic appearance
   float wobbX = 2 * cos(6 * IN.TexCoord.x + time_0_X);
   float wobbY = 7 * (1 - IN.TexCoord.y) * (1 - IN.TexCoord.y);
   float wobble = sin(time_0_X + wobbX + wobbY);
   // Alternative approach
   //   float wobble = 9 * (2 * tex3D(Noise, float3(IN.TexCoord * 0.4, 0.2 * time_0_X)) - 1);

   float3 coord;
   // Wobble more in the flames than at the base
   coord.x = xScale * IN.TexCoord.x + wobbleScale * (IN.TexCoord.y + 1) * wobble;
   // Create an upwards movement
   coord.y = yScale * IN.TexCoord.y - burnSpeed * time_0_X;
   // Move in Z to get some randomness
   coord.z = randomnessRate * time_0_X;
   float noisy = tex3D(Noise, coord);

   // Define the shape of the fire
   float t = sideFadeSharpness * (1 - sideFade * IN.TexCoord.x * IN.TexCoord.x);

   // Get the color out of it all
   float heat = saturate(2 *(t + noisy - yFade * IN.TexCoord.y));
   float4 flame = tex1D(Flame, heat);

   return flame;
}


//--------------------------------------------------------------//
// Technique Section for Effect Workspace.Fire Effects.Inferno
//--------------------------------------------------------------//
technique Inferno
{
   pass Single_Pass
   {
      CULLMODE = NONE;

      VertexShader = compile vs_1_1 Fire_Effects_Inferno_Single_Pass_Vertex_Shader_main();
      PixelShader = compile ps_2_0 Fire_Effects_Inferno_Single_Pass_Pixel_Shader_main();
   }

}

