Graphics Reference
In-Depth Information
float Time;
float FrameTime;
uint RandomSeed;
uint ParticleCount; // consume buffer count
}
// Represents a single particle
struct Particle {
float3 Position;
float Radius;
float3 OldPosition;
float Energy;
};
// Pixel shader input
struct PS_Input {
float4 Position : SV_Position;
float2 UV : TEXCOORD0;
float Energy : ENERGY;
};
3.
Within ParticleVS.hlsl , we will create an instancing vertex shader that reads the
particle for the current instance ID and computes the position for a quad.
#include "Common.hlsl"
#include "Particle.hlsl"
// Access to the particle buffer
StructuredBuffer<Particle> particles : register(t0);
// Computes the vertex position
float4 ComputePosition(in float3 pos, in float size,
in float2 vPos)
{
// Create billboard (quad always facing the camera)
float3 toEye = normalize(CameraPosition.xyz - pos);
float3 up = float3(0.0f, 1.0f, 0.0f);
float3 right = cross(toEye, up);
up = cross(toEye, right);
pos += (right * size * vPos.x) + (up * size * vPos.y);
return mul(float4(pos, 1), WorldViewProjection);
}
PS_Input VSMain(in uint vertexID : SV_VertexID,
in uint instanceID : SV_InstanceID)
{
 
Search WWH ::




Custom Search