/*=============================================================================
	DepthOnlyVertexShader.hlsl: Depth-only vertex shader.
	Copyright 1998-2010 Epic Games, Inc. All Rights Reserved.
=============================================================================*/

#include "Common.usf"
#include "Material.usf"
#include "VertexFactory.usf"

void Main(
	FVertexFactoryInput Input,
#if !MATERIALBLENDING_SOLID
	out FVertexFactoryInterpolants OutFactoryInterpolants,
	out float4 CameraVectorOrVertexColor : TEXCOORD4,
	out float4 PixelPosition : TEXCOORD5,
#endif
	out float4 OutPosition : POSITION
	)
{
	FVertexFactoryIntermediates VFIntermediates = GetVertexFactoryIntermediates(Input);
	float4 WorldPos = VertexFactoryGetWorldPosition(Input, VFIntermediates);

#if TERRAIN_VERTEX_FACTORY
	// Don't calculate TangentBasis here for terrain, as doing so causes self-z-fighting on xbox 360, regardless of any ISOLATE usage
	FMaterialVertexParameters VertexParameters = GetMaterialVertexParameters(Input, VFIntermediates, WorldPos.xyz, float3x3(float3(0,0,0),float3(0,0,0),float3(0,0,0)));
#else
	float3x3 TangentBasis = VertexFactoryGetTangentBasis(Input, VFIntermediates);
	FMaterialVertexParameters VertexParameters = GetMaterialVertexParameters(Input, VFIntermediates, WorldPos.xyz, TangentBasis);
#endif
	// Isolate instructions used for world position offset on xbox 360, 
	// As these cause the optimizer to generate different position calculating instructions in each pass, resulting in self-z-fighting.
	// This is only necessary for shaders used in passes that have depth testing enabled.
	ISOLATE
	{
		WorldPos.xyz += GetMaterialWorldPositionOffset(VertexParameters);
	}

	OutPosition = MulMatrix(ViewProjectionMatrix,WorldPos);

#if !MATERIALBLENDING_SOLID
	// Masked and transparent materials need texture coords to clip
	OutFactoryInterpolants = VertexFactoryGetInterpolants(Input, VFIntermediates);
	#if WORLD_POS
		PixelPosition = WorldPos;
	#else
		PixelPosition = OutPosition;
	#endif

#if TERRAIN_VERTEX_FACTORY
	float3x3 TangentBasis = VertexFactoryGetTangentBasis(Input, VFIntermediates);
#endif

	CameraVectorOrVertexColor = 1;
#if PER_PIXEL_CAMERA_VECTOR
	CameraVectorOrVertexColor = VertexFactoryGetVertexColor(Input, VFIntermediates);
#else
	// The mask may be dependent on the camera vector
	CameraVectorOrVertexColor.xyz = VertexFactoryWorldToTangentSpace(Input,VFIntermediates,TangentBasis,CameraPosition.xyz - WorldPos.xyz * CameraPosition.w);
#endif

#endif
}