// Digital Hellfire Shader
//
// Copyright Outerspace Software, all rights reserved

string description = "Digital Hellfire";

float4x4	World;
float4x4	ViewProjection;
float4		DiffuseCol;
float		Time;

float PI = 3.14159;

struct VS_INPUT{
	float4 position:	POSITION;
	float3 normal:		NORMAL;
	float3 diffuse:		COLOR;
	float2 tex:			TEXCOORD0;
};

struct VS_OUTPUT{
	float4 position:	POSITION;
	float4 diffuse:		COLOR;
	float2 tex:			TEXCOORD0;
};

VS_OUTPUT VS(VS_INPUT input){
	VS_OUTPUT output;

	float4 pos = input.position;

	float a = atan2(pos.x,pos.y);
	float r = sqrt(pos.x*pos.x+pos.y*pos.y);
	float b = atan2(pos.z,r);
	
	float da = (Time*PI*2)/7 + sin(4*b)*PI;
	float db = (Time*PI*2)/8 + sin(8*a)*PI;
	
	float s = (sin(2*(a+da))+1) * (cos(4*(b+db))+1);
	
	float3 v = s*5;
	
	pos = mul(pos,World);
	
	pos.xyz += v;

	output.position = mul(pos, ViewProjection);
	
	float3 C0 = float3(0.4,0.4,0)*DiffuseCol.w;
	float3 C1 = float3(0.4,0,0)*DiffuseCol.w;
	float3 C2 = float3(0,0,0)*DiffuseCol.w;

	float3 Col = float3(0,0,0);
	if(s<0.33)
		Col = C0 + s*(C1-C0)/0.33;
	else
		Col = C1 + (s-0.33)*(C2-C1)/0.33;
	
	output.diffuse.xyz = Col;
	output.diffuse.w   = 1;
	output.tex = input.tex;
	return output;
}

technique Shader
{
    pass P0
    {
	    ZWriteEnable		=FALSE;
		Alphablendenable	=TRUE;
		SrcBlend			=ONE;
		DestBlend			=ONE;
		CullMode			=NONE;
    
    
        VertexShader = compile vs_1_1 VS();
        PixelShader  = NULL;
    }
}
