	struct a2v
	{
		float4 vPosition : POSITION;
		float4 vEnvironmentRay : TEXCOORD0;
	};
	struct vertex2frag
	{
		float4 HPosition : POSITION;
		float4 fEnvironmentRay : TEXCOORD0;
	};
	struct frag2buffer
	{
		float4 color: COLOR0;
		float4 extra_target1: COLOR1;
		float4 extra_target2: COLOR2;
		float4 extra_target3: COLOR3;
		float  depth: DEPTH;
	};
//#define USE_TEXTURE_TRIG_FUNCTIONS
float4 texSPHERE(in sampler2D sphereTex, in float3 lookup_vector, in sampler1D acostex, in sampler2D atan2tex)
	{
	float2 index;
	float3 reflectDir;
	float4 sphereColor;
	reflectDir = lookup_vector;
	float pi = 3.1415925;
#ifdef USE_TEXTURE_TRIG_FUNCTIONS
	index.y = (tex1D(acostex, abs(reflectDir.y)).r);
#else
	index.y = (acos(abs(reflectDir.y))/pi);
#endif
	if (reflectDir.y<0.0) index.y = 1.0-index.y;
	//reflectDir.y = 0.0;
	//reflectDir = normalize(reflectDir);
#ifdef USE_TEXTURE_TRIG_FUNCTIONS
	reflectDir.xz = (reflectDir.xz+float2(1.0, 1.0))*float2(0.5, 0.5);
	index.x = tex2D(atan2tex, reflectDir.xz).r;
#else
	index.x = (atan2(reflectDir.x, reflectDir.z)+pi)/(2.0*pi);
#endif
	sphereColor = tex2D(sphereTex, index);
	return sphereColor;
	}
/**********************************************************************/
	vertex2frag vertEnvironment(in a2v app, 
		uniform float4x4 modelViewProj,
		uniform float4x4 reflectionTransformationMatrix)
	{
		vertex2frag vertOut;
		vertOut.HPosition = mul(modelViewProj, app.vPosition);
		vertOut.fEnvironmentRay.xyz = mul(reflectionTransformationMatrix, app.vEnvironmentRay).xyz;
		//vertOut.fEnvironmentRay.xyz = (app.vEnvironmentRay).xyz;
		vertOut.fEnvironmentRay.w = 0.0;
		return vertOut;
	}
/**********************************************************************/
	frag2buffer fragEnvironment(in vertex2frag interpolant
								,uniform sampler2D environment_texture
								,uniform sampler1D acos_texture
								,uniform sampler2D atan2_texture
								)
	{	frag2buffer fragOut;
		float4 envColor;
		//reflColor = texCUBE(environment_texture, reflectionVector);
		envColor = texSPHERE(environment_texture, normalize(interpolant.fEnvironmentRay.xyz),acos_texture,atan2_texture);
		fragOut.color = envColor;
		fragOut.color.a = 1.0;
		//fragOut.color = float4(0, 1, 0, 1.0);
		return fragOut;
	}