float4x4 gWorld : WORLD;
float4x4 gWorldViewProj : WORLDVIEWPROJECTION;
float3 gLightDirection = float3(-0.577f, -0.577f, 0.577f);
float gOpacityAmount = 1;
float gTotalSec = 1;
float gNrSprites = 16;
int gAnimSpeed = 32;
Texture2D gDiffuseMap;
struct VS_INPUT{
float3 pos : POSITION;
float3 normal : NORMAL;
float2 texCoord : TEXCOORD;
};
struct VS_OUTPUT{
float4 pos : SV_POSITION;
float3 normal : NORMAL;
float2 texCoord : TEXCOORD;
};
//STATES
//******
BlendState AlphaBlending
{
BlendEnable[0] = TRUE;
SrcBlend = SRC_ALPHA;
DestBlend = INV_SRC_ALPHA;
BlendOp = ADD;
SrcBlendAlpha = ONE;
DestBlendAlpha = ZERO;
BlendOpAlpha = ADD;
RenderTargetWriteMask[0] = 0x0f;
};
DepthStencilState DisableDepthWriting
{
//Enable Depth Rendering
DepthEnable = TRUE;
//Disable Depth Writing
DepthWriteMask = ZERO;
};
RasterizerState BackCulling
{
CullMode = NONE;
};
SamplerState samPoint
{
Filter = MIN_MAG_MIP_POINT;
AddressU = WRAP;
AddressV = WRAP;
};
//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
VS_OUTPUT VS(VS_INPUT input)
{
VS_OUTPUT output;
// Step 1: convert position into float4 and multiply with matWorldViewProj
output.pos = mul ( float4(input.pos,1.0f), gWorldViewProj );
// Step 2: rotate the normal: NO TRANSLATION
// this is achieved by clipping the 4x4 to a 3x3 matrix,
// thus removing the postion row of the matrix
output.normal = normalize(mul(input.normal, (float3x3)gWorld));
//offset uvs for animation
int spriteId = (int)(gTotalSec * gAnimSpeed) % gNrSprites;
float offsetAmount = 1.0f / gNrSprites;
output.texCoord = input.texCoord;
output.texCoord.x += offsetAmount * spriteId;
return output;
}
//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 PS(VS_OUTPUT input) : SV_TARGET{
//Simple Texture Sampling
float4 result = gDiffuseMap.Sample(samPoint, input.texCoord);
return result * float4(1, 1, 1, 0.75f * gOpacityAmount);
//return input.color * result;
}
//--------------------------------------------------------------------------------------
// Technique
//--------------------------------------------------------------------------------------
technique11 Default
{
pass P0
{
SetRasterizerState(BackCulling);
SetDepthStencilState(DisableDepthWriting, 0);
SetBlendState(AlphaBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
SetVertexShader( CompileShader( vs_4_0, VS() ) );
SetGeometryShader( NULL );
SetPixelShader( CompileShader( ps_4_0, PS() ) );
}
}