Untitled Document Forex Trading Club

Paste from Guest at 2013-08-20 21:13:04 | Syntax: | Hits: 69 | Valid for: Never

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
// (C)2008 S2 Games
// mesh_shadowed.vsh
// 
// ...
//=============================================================================

//=============================================================================
// Uniform variables
//=============================================================================
uniform vec4	vColor;

uniform vec3	vSunPositionView;

uniform vec3	vAmbient;
uniform vec3	vSunColor;
uniform vec3	vSunColorSpec;

uniform float	fFogStart;
uniform float	fFogEnd;
uniform float	fFogScale;
uniform float	fFogDensity;
uniform vec3	vFog;

#if (SHADOWS == 1)
uniform mat4	mLightWorldViewProjTex;  // Light's World * View * Projection * Tex
#endif

#if (NUM_BONES > 0)
uniform vec4	vBones[NUM_BONES * 3];
#endif

#ifdef CLOUDS
uniform mat4	mCloudProj;
#endif

#if (FOG_OF_WAR == 1)
uniform mat4	mFowProj;
#endif

//=============================================================================
// Varying variables
//=============================================================================
varying vec4	v_vColor;

varying vec3	v_vNormal;

#if (LIGHTING_QUALITY == 0)
varying vec3	v_vTangent;
varying vec3	v_vBinormal;
#elif (LIGHTING_QUALITY == 1 || LIGHTING_QUALITY == 2)
varying vec3	v_vHalfAngle;
varying vec3	v_vSunLight;
#elif (LIGHTING_QUALITY == 3)
varying vec3	v_vDiffLight;
#endif

#if (LIGHTING_QUALITY == 0 || FALLOFF_QUALITY == 0)
varying vec3	v_vPositionView;
#endif

#if (SHADOWS == 1)
varying vec4	v_vTexcoordLight;
#endif

#ifdef CLOUDS
varying vec2	v_vClouds;
#endif

#if ((FOG_QUALITY == 1 && FOG_TYPE != 0) || (FALLOFF_QUALITY == 1 && (FOG_TYPE != 0 || SHADOWS == 1)) || FOG_OF_WAR == 1)
varying vec4	v_vData0;
#endif

//=============================================================================
// Vertex attributes
//=============================================================================
attribute vec3	a_vTangent;

#define OBJECT_SIZE 100 //ugly hack but hey S2upid at work
#define OBJECT_HALFSIZE OBJECT_SIZE/2 //ugly hack but hey S2upid at work
#define DEGREE_TO_RADIANS 0.017453f //constant for transforming degrees in radians
#define NUMBER_OF_IMAGES 16.0f //number of images in texture, per row!!!
#define DEGREE_SIZE_OF_IMAGE (360/NUMBER_OF_IMAGES) //if there a cirle of images, how many degrees of 360 has on single image. 16 images = 22.5
#define NUMBER_OF_ROWS 4.0f //if there a cirle of images, how many degrees of 360 has on single image. 16 images = 22.5


//=============================================================================
// Vertex Shader
//=============================================================================
void main()
{
#if ((FOG_QUALITY == 1 && FOG_TYPE != 0) || (FALLOFF_QUALITY == 1 && (FOG_TYPE != 0 || SHADOWS == 1)) || FOG_OF_WAR == 1)
	v_vData0 = vec4(0.0, 0.0, 0.0, 0.0);
#endif

	float	v_vImageId;
	vec4 vPosition = gl_Vertex;
	vec3 vNormal = gl_Normal;
	vec3 vTangent = a_vTangent;

	vec3 vPositionView = (gl_ModelViewMatrix * vPosition).xyz;

	//OWN CODE

	//calculate the angle between kamera view vector and normal of quad
	vec3 objectNormal  = normalize(gl_NormalMatrix * gl_Normal);
	vec3 camVector     = vec3(0,0,-1); 

	//get the INVERSE angel. calculate the angle between object and camera and go in the opposite angle
	//cos and sin can only go from -1 to 1, so 180 = -180 and he can decide
	float cosAngle = dot(objectNormal,camVector);
	//the sin is always positive, since it is the area of a parallelo gram. check if the quad face left or right from the cam (-1)
	float sinAngle = sin(acos(cosAngle)) * (objectNormal.x / max(abs(objectNormal.x), 0.001f));

	//build rotation matrix (used inverse negative values because the rotation angles are toward the camera)
	mat4 rotMatrixZ = mat4(1.0f);

	rotMatrixZ[0][0] = -cosAngle;
	rotMatrixZ[0][1] = -sinAngle;
	rotMatrixZ[1][0] = sinAngle;
	rotMatrixZ[1][1] = -cosAngle;

	//rotate in object space //transform to world space
	gl_Position      = gl_ModelViewProjectionMatrix * (rotMatrixZ * gl_Vertex);

	//shader angle for image "blending", angle is negative!

	//cos - 1 ... ups builded a cirle from -180 to 180... wtf this was not by purpose lol. 0 -> -180 -> +180 ->0
	//float angle = (cosAngle - 1) * 90 * (sinAngle/abs(sinAngle)) + min(0,sinAngle/abs(sinAngle)) * 180;
	//transform the creative solution *LOOOL* to a normal angle from 0 to 360 degree.
	//angle = -angle*(sinAngle/abs(sinAngle)) * max(sinAngle/abs(sinAngle),0) + 180 + abs(sinAngle)*180;
	//	0 - 180								//180 + i*180 where i = 0 to 1

	//fucked up but works. for normal people: first line 0 - 90, second 90 - 180, third 180-270, fourth 270 - 360
	//if sin > 0 and cos > 0 then first line, if sin > 0 and cos < 0 then second line + 90 and so on. 
	float angle = sinAngle * 90 * max(sinAngle/abs(sinAngle),0) * max(cosAngle/abs(cosAngle),0)  //sin pos cos pos
	+ min (cosAngle/abs(cosAngle),0) * (cosAngle/abs(cosAngle)) * max(0,sinAngle/abs(sinAngle)) * (90 + 90 * abs(cosAngle)) //cos neg sin pos
	+ min (cosAngle/abs(cosAngle),0) * (cosAngle/abs(cosAngle)) * min (sinAngle/abs(sinAngle),0)  * (sinAngle/abs(sinAngle)) * (180 + 90 * abs(sinAngle)) //cos neg sin neg
	+ max(0,cosAngle/abs(cosAngle)) * min (sinAngle/abs(sinAngle),0) * (sinAngle/abs(sinAngle)) * (270 + 90 * abs(cosAngle)); //cos neg sin pos

	/*
	v_vImageId = round(angle*NUMBER_OF_ROWS / DEGREE_SIZE_OF_IMAGE); // 360 / 16. 360 degrees angle to 16 images
	v_vImageId =  float((int (abs(v_vImageId)) ) % int(NUMBER_OF_IMAGES)) * (abs(v_vImageId) / v_vImageId);
	*/

	v_vImageId = floor(angle * NUMBER_OF_ROWS / DEGREE_SIZE_OF_IMAGE);
	v_vImageId =  float ( mod( int(v_vImageId) , int(NUMBER_OF_IMAGES) ) );

	gl_TexCoord[0]   = gl_MultiTexCoord0;
	//use min because the angle is negative

	gl_TexCoord[0].x = (gl_TexCoord[0].x/NUMBER_OF_IMAGES) + max(0,(v_vImageId))/NUMBER_OF_IMAGES;
	gl_TexCoord[0].y = (gl_TexCoord[0].y / NUMBER_OF_ROWS) + (NUMBER_OF_ROWS-1)/NUMBER_OF_ROWS  - (1/NUMBER_OF_ROWS) * floor(angle*NUMBER_OF_ROWS/360);

	//gl_TexCoord[0].x = (gl_TexCoord[0].x/NUMBER_OF_IMAGES) + min(0,(v_vImageId-1))/NUMBER_OF_IMAGES;
	//gl_TexCoord[0].y = (gl_TexCoord[0].y / NUMBER_OF_ROWS) + abs( floor(angle/ (DEGREE_SIZE_OF_IMAGE * NUMBER_OF_IMAGES))/NUMBER_OF_ROWS );
	//END OWN CODE

	//gl_TexCoord[0]   = gl_MultiTexCoord0;

	v_vColor         = vColor;
	v_vNormal        = normalize(gl_NormalMatrix * vNormal);
	
#if (LIGHTING_QUALITY == 0)

	v_vTangent       = normalize(gl_NormalMatrix * vTangent);
	v_vBinormal      = cross(v_vTangent, v_vNormal);
#elif (LIGHTING_QUALITY == 1 || LIGHTING_QUALITY == 2)
	vec3 vCamDirection = -normalize(vPositionView);
	vec3 vLight = vSunPositionView;
	vec3 vWVNormal = normalize(gl_NormalMatrix * vNormal);
	vec3 vWVTangent = normalize(gl_NormalMatrix * vTangent);
	vec3 vWVBinormal = cross(vWVTangent, vWVNormal);

	mat3 mRotate = transpose(mat3(vWVTangent, vWVBinormal, vWVNormal));
	
	v_vSunLight      = mRotate * vLight;
	v_vHalfAngle     = mRotate * normalize(vLight + vCamDirection);
#elif (LIGHTING_QUALITY == 3)
	vec3 vLight = vSunPositionView;		
	vec3 vWVNormal = normalize(gl_NormalMatrix * vNormal);

	float fDiffuse = max(dot(vWVNormal, vLight), 0.0);

	v_vDiffLight     =  vSunColor * fDiffuse;
#endif
	
#if (LIGHTING_QUALITY == 0 || FALLOFF_QUALITY == 0)
	v_vPositionView  = vPositionView;
#endif
	
#if (SHADOWS == 1)
	v_vTexcoordLight = mLightWorldViewProjTex * vPosition;
#endif

#ifdef CLOUDS
	v_vClouds = (mCloudProj * vPosition).xy;
#endif

#if (FALLOFF_QUALITY == 1 && (FOG_TYPE != 0 || SHADOWS == 1))
	v_vData0.z = length(vPositionView);
#endif

#if (FOG_QUALITY == 1 && FOG_TYPE != 0)
	#if (FOG_TYPE == 0) 
	// FOG_NONE
	v_vData0.w = 0.0;
	#elif (FOG_TYPE == 1) 
	// FOG_LINEAR
	v_vData0.w = clamp(length(vPositionView) * vFog.x + vFog.y, 0.0, 1.0) * vFog.z;
	#elif (FOG_TYPE == 2) 
	// FOG_EXP2
	v_vData0.w = 1.0 - exp2(-length(vPositionView) * fFogDensity);
	#elif (FOG_TYPE == 3) 
	// FOG_EXP
	v_vData0.w = 1.0 - exp(-length(vPositionView) * fFogDensity);
	#elif (FOG_TYPE == 4) 
	// FOG_HERMITE
	v_vData0.w = smoothstep(fFogStart, fFogEnd, length(vPositionView)) * fFogScale;
	#endif
#endif

#if (FOG_OF_WAR == 1)
	v_vData0.xy = (mFowProj * vPosition).xy;
#endif
}


» no title
« no title