Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include "Macros.fxh"
float4x4 WorldViewProjection;
float3 CameraRight;
float3 CameraUp;
texture Texture;
sampler TextureSampler = sampler_state
{
Texture = (Texture);
MINFILTER = LINEAR;
MAGFILTER = LINEAR;
MIPFILTER = LINEAR;
ADDRESSU = CLAMP;
ADDRESSV = CLAMP;
};
struct VSInput
{
float4 Position : POSITION0;
float4 Color : COLOR0;
float2 TexCoord : TEXCOORD0;
float Rotation : COLOR1;
float2 Size : TEXCOORD1;
};
struct VSOutput
{
float4 Position : POSITION0;
float4 Color : COLOR0;
float2 TexCoord : TEXCOORD0;
};
float4 ComputeParticleRotation(float rotation)
{
float c = cos(rotation);
float s = sin(rotation);
float4 rotationMatrix = float4(c, -s, s, c);
rotationMatrix *= 0.5;
rotationMatrix += 0.5;
return rotationMatrix;
}
VSOutput VSDefault(VSInput input)
{
float3 position = input.Position.xyz;
position += input.Size.x * CameraRight;
position += input.Size.y * CameraUp;
float4 rotation = ComputeParticleRotation(input.Rotation) * 2 - 1;
float2 texCoord = input.TexCoord;
texCoord -= 0.5;
texCoord = mul(texCoord, float2x2(rotation));
texCoord += 0.5;
VSOutput output;
output.Position = mul(float4(position, 1), WorldViewProjection);
output.Color = input.Color;
output.TexCoord = texCoord;
return output;
}
float4 PSDefault(VSOutput input) : COLOR0
{
return tex2D(TextureSampler, input.TexCoord) * input.Color;
}
TECHNIQUE(Default, VSDefault, PSDefault);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment