Untitled Document Forex Trading Club

Paste from Guest at 2013-08-20 21:12:24 | Syntax: | Hits: 83 | Valid for: Never

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
// (C)2006 S2 Games
// mesh_shadowed.vsh
// 
// Default mesh vertex shader with shadowmap support
//=============================================================================

//=============================================================================
// Headers
//=============================================================================
#include "../common/common.h"
#include "../common/fog.h"

//=============================================================================
// Global variables
//=============================================================================
float4x4	mWorldViewProj;	         // World * View * Projection transformation
float4x4	mWorldView;	             // World * View
float3x3	mWorldViewRotate;        // World rotation for normals

float4		vSunPositionView;

float3		vAmbient;
float3		vSunColor;
float3		vSunColorSpec;

float		fGlossiness;

#if (SHADOWS == 1)
	#ifdef SHADOW_SPLIT_PROJECTION
		float4x4	mLightWorldViewProjTexSplit[4];  // Light's World * View * Projection * Tex
	#else
		float4x4	mLightWorldViewProjTex;  // Light's World * View * Projection * Tex
	#endif
#endif

float4		vColor;

#if (NUM_BONES > 0)
	float4x3		vBones[NUM_BONES];
#endif

#ifdef CLOUDS
	float4x4	mCloudProj;
#endif

#if (FOG_OF_WAR == 1)
	float4x4	mFowProj;
#endif

//=============================================================================
// Vertex shader output structure
//=============================================================================

#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


struct VS_OUTPUT
{
	float4 Position      : POSITION;
	float4 Color0        : COLOR0;
	float2 Texcoord0     : TEXCOORDX;
		#include "../common/inc_texcoord.h"
#if (LIGHTING_QUALITY == 0 || FALLOFF_QUALITY == 0)
	float3 PositionView : TEXCOORDX;
		#include "../common/inc_texcoord.h"
#endif
#if (LIGHTING_QUALITY == 0)
	float3 Normal        : TEXCOORDX;
		#include "../common/inc_texcoord.h"
	float3 Tangent       : TEXCOORDX;
		#include "../common/inc_texcoord.h"
	float3 Binormal      : TEXCOORDX;
		#include "../common/inc_texcoord.h"
#elif (LIGHTING_QUALITY == 1)
	float3 HalfAngle     : TEXCOORDX;
		#include "../common/inc_texcoord.h"
	float3 SunLight      : TEXCOORDX;
		#include "../common/inc_texcoord.h"
#elif (LIGHTING_QUALITY == 2)
	float3 DiffLight  : TEXCOORDX;
		#include "../common/inc_texcoord.h"
	float3 SpecLight  : TEXCOORDX;
		#include "../common/inc_texcoord.h"
#elif (LIGHTING_QUALITY == 3)
	float3 DiffLight  : TEXCOORDX;
		#include "../common/inc_texcoord.h"
#endif
#if (SHADOWS == 1)
	#ifdef SHADOW_SPLIT_PROJECTION
		float4 TexcoordLight0 : TEXCOORDX;
			#include "../common/inc_texcoord.h"
		float4 TexcoordLight1 : TEXCOORDX;
			#include "../common/inc_texcoord.h"
		float4 TexcoordLight2 : TEXCOORDX;
			#include "../common/inc_texcoord.h"
		float4 TexcoordLight3 : TEXCOORDX;
			#include "../common/inc_texcoord.h"
	#else
		float4 TexcoordLight : TEXCOORDX; // Texcoord in light texture space
			#include "../common/inc_texcoord.h"
	#endif
#endif
#ifdef CLOUDS
	float4 TexcoordClouds : TEXCOORDX;
			#include "../common/inc_texcoord.h"
#endif
#if ((FOG_QUALITY == 1 && FOG_TYPE != 0) || (FALLOFF_QUALITY == 1 && (FOG_TYPE != 0 || SHADOWS == 1)) || FOG_OF_WAR == 1)
	float4 Last : TEXCOORDX;
		#include "../common/inc_texcoord.h"
#endif
};


//=============================================================================
// Vertex shader input structure
//=============================================================================
struct VS_INPUT
{
	float3 Position   : POSITION;
	float3 Normal     : NORMAL;
	float2 Texcoord0  : TEXCOORD0;
	float3 Tangent    : TEXCOORD1;
#if (NUM_BONES > 0)
	int4 BoneIndex    : TEXCOORD_BONEINDEX;
	float4 BoneWeight : TEXCOORD_BONEWEIGHT;
#endif
};


//=============================================================================
// Vertex Shader
//=============================================================================
VS_OUTPUT VS( VS_INPUT In )
{
	VS_OUTPUT Out;
	
#if ((FOG_QUALITY == 1 && FOG_TYPE != 0) || (FALLOFF_QUALITY == 1 && (FOG_TYPE != 0 || SHADOWS == 1)) || FOG_OF_WAR == 1)
	Out.Last = 0;
#endif
	
	float3 vInNormal = (In.Normal / 255.0f) * 2.0f - 1.0f;
	float3 vInTangent = (In.Tangent / 255.0f) * 2.0f - 1.0f;
	
#if (NUM_BONES > 0)
	float3 vPosition = 0.0f;
	float3 vNormal = 0.0f;
	float3 vTangent = 0.0f;

	//
	// GPU Skinning
	// Blend bone matrix transforms for this bone
	//
	
	int4 vBlendIndex = In.BoneIndex;
	float4 vBoneWeight = In.BoneWeight / 255.0f;
	
	float4x3	mBlend = 0.0f;
	for (int i = 0; i < NUM_BONE_WEIGHTS; ++i)
		mBlend += vBones[vBlendIndex[i]] * vBoneWeight[i];

	float3x3	mAxis = float3x3(mBlend[0], mBlend[1], mBlend[2]);
	float3		vPos = mBlend[3];
	
	vPosition = mul(In.Position, mAxis) + vPos;
	vNormal = mul(vInNormal, mAxis);
	vTangent = mul(vInTangent, mAxis);
	
	vNormal = normalize(vNormal);
	vTangent = normalize(vTangent);
#else
	float3 vPosition = In.Position;
	float3 vNormal = vInNormal;
	float3 vTangent = vInTangent;
#endif

	float3 vPositionView = mul(float4(vPosition, 1.0f), mWorldView).xyz;
	
	//own code
	
	float3 objectNormal 	= mul(vNormal, mWorldViewRotate);
	//float3 camVector	= float3(0.0f,0.0f,-1.0f); 
	float3 camVector = -normalize(vPositionView);
	
	//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));

	
	//float4x4 rotMatrixZ = float4x4(1.0f,0.0f,0.0f,0.0f, 0.0f,1.0f,0.0f,0.0f, 0.0f,0.0f,1.0f,0.0f, 0.0f,0.0f,0.0f,1.0f);
	float4x4 rotMatrixZ = float4x4(0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 );
	rotMatrixZ[0][0] = 1.0f;
	rotMatrixZ[1][1] = 1.0f;
	rotMatrixZ[2][2] = 1.0f;
	rotMatrixZ[3][3] = 1.0f;

	rotMatrixZ[0][0] = -cosAngle;
	rotMatrixZ[1][0] = -sinAngle;
	rotMatrixZ[0][1] = sinAngle;
	rotMatrixZ[1][1] = -cosAngle;	
	
	//Out.Position      = mul(mWorldViewProj,  mul(rotMatrixZ,float4(In.Position, 1.0f)));
	Out.Position      = mul(mul(float4(In.Position, 1.0f),rotMatrixZ),mWorldViewProj);
	
	
	//end own code
	
	//Out.Position      = mul(float4(vPosition, 1.0f), mWorldViewProj);
	Out.Color0        = vColor;
	Out.Texcoord0     = In.Texcoord0;
#if (LIGHTING_QUALITY == 0 || FALLOFF_QUALITY == 0)
	Out.PositionView  = vPositionView;
#endif
#if (FALLOFF_QUALITY == 1 && (FOG_TYPE != 0 || SHADOWS == 1))
	Out.Last.z = length(vPositionView);
#endif
	
#if (LIGHTING_QUALITY == 0)
	Out.Normal        = mul(vNormal, mWorldViewRotate);
	Out.Tangent       = mul(vTangent, mWorldViewRotate);
	Out.Binormal      = cross(Out.Tangent, Out.Normal);
#elif (LIGHTING_QUALITY == 1)
	float3 vCamDirection = -normalize(vPositionView);
	float3 vLight = vSunPositionView.xyz;
	float3 vWVNormal = mul(vNormal, mWorldViewRotate);
	float3 vWVTangent = mul(vTangent, mWorldViewRotate);
	float3 vWVBinormal = cross(vWVTangent, vWVNormal);

	float3x3 mRotate = transpose(float3x3(vWVTangent, vWVBinormal, vWVNormal));
	
	Out.SunLight      = mul(vLight, mRotate);
	Out.HalfAngle     = mul(normalize(vLight + vCamDirection), mRotate);
#elif (LIGHTING_QUALITY == 2)
	float3 vCamDirection = -normalize(vPositionView);
	float3 vLight = vSunPositionView.xyz;		
	float3 vHalfAngle = normalize(vLight + vCamDirection);
	float3 vWVNormal = mul(vNormal, mWorldViewRotate);

	float fDiffuse = saturate(dot(vWVNormal, vLight));
	float fSpecular = saturate(step(0.0f, fDiffuse) * (pow(dot(vWVNormal, vHalfAngle), fGlossiness)));

	Out.DiffLight     = vSunColor * fDiffuse;
	Out.SpecLight     = vSunColorSpec * fSpecular;
#elif (LIGHTING_QUALITY == 3)
	float3 vLight = vSunPositionView.xyz;		
	float3 vWVNormal = mul(vNormal, mWorldViewRotate);

	float fDiffuse = saturate(dot(vWVNormal, vLight));

	Out.DiffLight     =  vSunColor * fDiffuse;
#endif

#if (SHADOWS == 1)
	#ifdef SHADOW_SPLIT_PROJECTION
		Out.TexcoordLight0 = mul(float4(vPosition, 1.0f), mLightWorldViewProjTexSplit[0]);
		Out.TexcoordLight1 = mul(float4(vPosition, 1.0f), mLightWorldViewProjTexSplit[1]);
		Out.TexcoordLight2 = mul(float4(vPosition, 1.0f), mLightWorldViewProjTexSplit[2]);
		Out.TexcoordLight3 = mul(float4(vPosition, 1.0f), mLightWorldViewProjTexSplit[3]);
	#else
		Out.TexcoordLight = mul(float4(vPosition, 1.0f), mLightWorldViewProjTex);
	#endif
#endif

#ifdef CLOUDS
	Out.TexcoordClouds = mul(float4(vPosition, 1.0f), mCloudProj);
#endif

#if (FOG_QUALITY == 1 && FOG_TYPE != 0)
	Out.Last.w = Fog(vPositionView);
#endif

#if (FOG_OF_WAR == 1)
	Out.Last.xy = mul(float4(vPosition, 1.0f), mFowProj).xy;
#endif

	return Out;
}


» no title
« no title