Files
UnrealEngineUWP/Engine/Shaders/SlateVertexShader.usf
2014-04-23 19:34:49 -04:00

83 lines
2.9 KiB
Plaintext

// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
#include "Common.usf"
float4x4 ViewProjection;
float4 VertexShaderParams;
/**
* Rotates a point around another point
*
* @param InPoint The point to rotate
* @param AboutPoint The point to rotate about
* @param Radians The angle of rotation in radians
* @return The rotated point
*/
float2 RotatePoint( float2 InPoint, float2 AboutPoint, float Radians )
{
if( Radians != 0.0f )
{
float CosAngle = cos(Radians);
float SinAngle = sin(Radians);
InPoint.x -= AboutPoint.x;
InPoint.y -= AboutPoint.y;
float X = (InPoint.x * CosAngle) - (InPoint.y * SinAngle);
float Y = (InPoint.x * SinAngle) + (InPoint.y * CosAngle);
return float2( X + AboutPoint.x, Y + AboutPoint.y );
}
return InPoint;
}
struct VertexOut
{
float4 Position : SV_POSITION;
float4 Color : COLOR0;
float4 TextureCoordinates : TEXCOORD0;
float4 ClipCoords : TEXCOORD1;
float2 WorldPosition : TEXCOORD2;
};
VertexOut Main(
in float4 InTextureCoordinates : ATTRIBUTE0,
/* Don't change these int streams to float, otherwise it WILL fail since the vertex declaration is defined as int on D3D11:
D3D11: WARNING: ID3D11Device::CreateInputLayout: The provided input signature expects to read an element with SemanticName/Index: 'ATTRIBUTE'/1 and component(s) of the type 'float32'. However, the matching entry in the Input Layout declaration, element[1], specifies mismatched format: 'R16G16B16A16_SINT'. This is not an error, since behavior is well defined: The element format determines what data conversion algorithm gets applied before it shows up in a shader register. Independently, the shader input signature defines how the shader will interpret the data that has been placed in its input registers, with no change in the bits stored. It is valid for the application to reinterpret data as a different type once it is in the vertex shader, so this warning is issued just in case reinterpretation was not intended by the author. [ STATE_CREATION WARNING #391: CREATEINPUTLAYOUT_TYPE_MISMATCH ]
*/
#if ES2_PROFILE && COMPILER_GLSL_ES2
in float4 InClipCoords : ATTRIBUTE1,
in float2 InPosition : ATTRIBUTE2,
#else
in int4 InClipCoords : ATTRIBUTE1,
in int2 InPosition : ATTRIBUTE2,
#endif
in float4 InColor : ATTRIBUTE3
)
{
VertexOut VOut;
VOut.ClipCoords = InClipCoords;
float2 RotatedPoint = RotatePoint( InPosition.xy, VertexShaderParams.yz, VertexShaderParams.x );
// Position used for clipping, before transformation
VOut.WorldPosition = RotatedPoint.xy;
VOut.Position = mul(float4(RotatedPoint.xy,0,1), ViewProjection);
#if ES2_PROFILE && COMPILER_GLSL_ES2
// @todo-mobile: Fix this in the projection matrix
VOut.Position.y = -VOut.Position.y;
#endif
// TextureCoordinates contains both the first and second texture coordinates in xy and zw respectively.
VOut.TextureCoordinates = InTextureCoordinates;
VOut.Color = InColor FCOLOR_COMPONENT_SWIZZLE;
return VOut;
}