aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/scenegraph/d3d12/shaders/sprite.hlsl
blob: d4e3b066ee25086f580cf67969abc92cee5ef629 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
struct VSInput
{
    float4 position : POSITION;
    float2 coord : TEXCOORD0;
};

cbuffer ConstantBuffer : register(b0)
{
    float4x4 mvp;
    float4 animPos;
    float3 animData;
    float opacity;
};

struct PSInput
{
    float4 position : SV_POSITION;
    float4 fTexS : TEXCOORD0;
    float progress : TEXCOORD1;
};

Texture2D tex : register(t0);
SamplerState samp : register(s0);

PSInput VS_Sprite(VSInput input)
{
    PSInput result;

    result.position = mul(mvp, input.position);
    result.progress = animData.z;

    // Calculate frame location in texture
    result.fTexS.xy = animPos.xy + input.coord.xy * animData.xy;
    // Next frame is also passed, for interpolation
    result.fTexS.zw = animPos.zw + input.coord.xy * animData.xy;

    return result;
}

float4 PS_Sprite(PSInput input) : SV_TARGET
{
    return lerp(tex.Sample(samp, input.fTexS.xy), tex.Sample(samp, input.fTexS.zw), input.progress) * opacity;
}