//**************************************************************//
//  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. 
//**************************************************************//

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

//float4x4 view_proj_matrix;
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_Lava_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 noiseScale
<
   string UIName = "noiseScale";
   string UIWidget = "Numeric";
   bool UIVisible = true;
   float UIMin = 0.00;
   float UIMax = 1.00;
> = 0.21;
float morphRate
<
   string UIName = "morphRate";
   string UIWidget = "Numeric";
   bool UIVisible = true;
   float UIMin = 0.00;
   float UIMax = 0.20;
> = 0.05;
float bubbleRate
<
   string UIName = "bubbleRate";
   string UIWidget = "Numeric";
   bool UIVisible = true;
   float UIMin = 0.00;
   float UIMax = 0.50;
> = 0.12;
float bubbleScale
<
   string UIName = "bubbleScale";
   string UIWidget = "Numeric";
   bool UIVisible = true;
   float UIMin = 0.00;
   float UIMax = 5.00;
> = 0.95;
float time_0_X : Time0_X;
float scale
<
   string UIName = "scale";
   string UIWidget = "Numeric";
   bool UIVisible = true;
   float UIMin = 0.00;
   float UIMax = 2.00;
> = 0.82;
float bias
<
   string UIName = "bias";
   string UIWidget = "Numeric";
   bool UIVisible = true;
   float UIMin = -1.00;
   float UIMax = 1.00;
> = -0.12;

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;
};

// We use noise as our base texture. Then we use more noisy to
// bubble in that noise. Both the base noise and bubble noise is
// animated, though the bubbling at a higher rate.

//float4 Fire_Effects_Lava_Single_Pass_Pixel_Shader_main(float2 pos: TEXCOORD0) : COLOR 
float4 Fire_Effects_Lava_Single_Pass_Pixel_Shader_main(VertexOutput IN) : COLOR 
{

   // Bubble coords
   float3 coord;
   coord.xy = IN.TexCoord * bubbleScale;
   coord.z = bubbleRate * time_0_X;

   // Sample noise for x and y
   float noiseX = tex3D(Noise, coord) - 0.5;
   float noiseY = tex3D(Noise, coord + 0.5) - 0.5;

   // Offset our base noise with the bubble noise
   coord.x = IN.TexCoord.x + noiseX * noiseScale;
   coord.y = IN.TexCoord.y + noiseY * noiseScale;
   coord.z = time_0_X * morphRate;

   // Sample the base noise
   float base = tex3D(Noise, coord);

   // Assign a firey color from the base noise
   return tex1D(Flame, scale * base + bias);
   
   //float4 result = float4(0, 1, 0, 1);
  //return result;

}


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

      VertexShader = compile vs_1_1 Fire_Effects_Lava_Single_Pass_Vertex_Shader_main();
      PixelShader = compile ps_2_0 Fire_Effects_Lava_Single_Pass_Pixel_Shader_main();
   }

}

