float4x4 WorldViewProj : WorldViewProjection;
float4x4 WorldView : WorldView;
float4x4 World : World;
float4x4 ViewProj : ViewProj;
float3 Camera : CameraPosition;










texture ImageImg< string ResourceName = "";>;
sampler ImageMap = sampler_state { Texture = <ImageImg>; };



float RangeMin<
	string UIWidget = "slider";
	float UIMax = 1000;
	float UIMin = 0;
	float UIStep = 1;
> = 0;

float RangeMax<
	string UIWidget = "slider";
	float UIMax = 1000;
	float UIMin = 0;
	float UIStep = 1;
> = 1000;

float Highlight<
	string UIWidget = "slider";
	float UIMax = 1;
	float UIMin = 0;
	float UIStep = .01;
> = 0;

float LightX<
	string UIWidget = "slider";
	float UIMax = 1;
	float UIMin = 0;
	float UIStep = .01;
> = .5;
float LightY<
	string UIWidget = "slider";
	float UIMax = 1;
	float UIMin = 0;
	float UIStep = .01;
> = .5;
float LightZ<
	string UIWidget = "slider";
	float UIMax = 1000;
	float UIMin = 0;
	float UIStep = 1;
> = 250;

float LightClip<
	string UIWidget = "slider";
	float UIMax = 1;
	float UIMin = 0;
	float UIStep = .01;
> = 0;



struct ShaderIN
{
	float4 pos : POSITION;
	float2 uv : TEXCOORD0;
	float3 normal : NORMAL;
};


//====================================BASE
struct BaseOUT
{
	float4 pos : POSITION;
	float3 wPos : TEXCOORD0;
	float2 uv : TEXCOORD1;
	float4 wvPos : TEXCOORD2;
};

BaseOUT BaseVS( ShaderIN IN )
{
	BaseOUT OUT;
	
	OUT.pos = mul( IN.pos, WorldViewProj );
	OUT.uv = IN.uv;
	OUT.wPos = mul( IN.pos, World );
	OUT.wvPos = OUT.pos;
	
	return OUT;
}

float4 BasePS( BaseOUT IN) : COLOR
{
	float2 proj = float2( IN.wvPos.x*0.5 + 0.5*IN.wvPos.w, 0.5*IN.wvPos.w - IN.wvPos.y*0.5)/IN.wvPos.z;
	float3 image=tex2D(ImageMap,IN.uv);
	clip(.5-image.y);
	float dist=distance(IN.wPos,Camera);
	float color=smoothstep(RangeMax,RangeMin,dist);
	color=1-color;
	
	if (dist<RangeMin) color=(smoothstep(RangeMin,0,dist)*.25);
	
	float light=smoothstep(.5,0,distance(proj,float2(LightX,LightY)))*(1-smoothstep(0,LightZ,dist));
	float lightcolor=image.x+(color*Highlight);
	color+=Highlight*.1;
	
	lightcolor+=smoothstep(LightClip,LightClip-.1,1-image.z);
	
	color=saturate(color+(saturate(lightcolor)*light))*.9;
	
	return float4(color,color,color,1);
}



























//======================TECHNIQUES
technique Default{
	pass p0{
		VertexShader = compile vs_1_1 BaseVS();
		PixelShader = compile ps_2_0 BasePS();
	}
}