
// ------- UNIFORMS (SHADER CONSTS) -------
cbuffer PMV
{
	mat4	hu_mPMVMatrix;
}
mat4		hu_mMVMatrix;
mat4		hu_mMVIMatrix;
float		hu_vCameraDistanceToMpp;
//float		hu_fSin11; // debug
vec2		u_vTextureUVScale;
float		u_fWidth;
vec4		u_fxWidthByDistance;
vec4		u_fxWidthByAngle;

// ------- ATTRIBUTES (VERTEX BUFFER DATA) -------
struct VIn
{
	vec4	a_vPosition0: POSITION;
	vec2	a_vTexCoord0: TEXCOORD0;
	vec3	a_vTexCoord1: TEXCOORD1;
};

// ------- INTERPOLATORS (SHADER OUTPUTS) -------
struct PIn
{
	vec4	v_vPosition: SV_POSITION;
	vec2	v_vTexCoord: TEXCOORD;
};

#include "functions.sh"

PIn main(VIn input)
{
	PIn output;

	output.v_vTexCoord = input.a_vTexCoord0*u_vTextureUVScale;
	vec4 vPos = input.a_vPosition0;
	vec3 vShift = input.a_vTexCoord1;

	//if (hu_fSin11 > 0.0)
	//{
		// eye space
		vec4 vPosEye = mul(hu_mMVMatrix, vPos);
		vec3 vShiftEye = normalize(mul(vShift, (mat3)hu_mMVIMatrix));
		
		vec3 vCam2Pos = normalize(vPosEye.xyz);
		float fAngle = dot(vShiftEye, vCam2Pos);
		float fWidthByAngle = GetGrowingValue(u_fxWidthByAngle, fAngle);

		float fDistToCamera = length(vPosEye.xyz);
		float fWidthByDistance = GetGrowingValue(u_fxWidthByDistance, fDistToCamera);
		//vPos.xyz += (fWidthByAngle*fWidthByDistance + u_fWidth)*vShift;
		float k = (fDistToCamera*hu_vCameraDistanceToMpp)*0.5;
		vPos.xyz += k*vShift;
		vPos.y += fWidthByAngle*fWidthByDistance;
	//}
	//else
	//{	
	//	vPos.xyz += u_fWidth*vShift;
	//}
	
	output.v_vPosition = mul(hu_mPMVMatrix, vPos);

	return output;
}
