-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpriteShader.cs
74 lines (66 loc) · 3.28 KB
/
SpriteShader.cs
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using System.Runtime.InteropServices;
using VeldridGen.Example.Engine;
using VeldridGen.Example.Engine.Visual.Sprites;
using VeldridGen.Interfaces;
namespace VeldridGen.Example.SpriteRenderer
{
#pragma warning disable CA1051 // Do not declare visible instance fields
#pragma warning disable 649 // CS0649 Field is never assigned to, and will always have its default value
[VertexShader(typeof(SpriteVertexShader))]
[FragmentShader(typeof(SpriteFragmentShader))]
internal partial class SpritePipeline : PipelineHolder { }
[Name("SpriteSV.vert")]
[Input(0, typeof(Vertex2DTextured))]
[Input(1, typeof(GpuSpriteInstanceData), InstanceStep = 1)]
[ResourceSet(0, typeof(CommonSet))]
[ResourceSet(1, typeof(SpriteArraySet))]
[Output(0, typeof(SpriteIntermediateData))]
[SuppressMessage("Microsoft.Naming", "CA1812:AvoidUninstantiatedInternalClasses", Justification = "Used for code generation")]
public partial class SpriteVertexShader : IVertexShader { }
[Name("SpriteSF.frag")]
[Input(0, typeof(SpriteIntermediateData))]
[ResourceSet(0, typeof(CommonSet))]
[ResourceSet(1, typeof(SpriteArraySet))]
[Output(0, typeof(ColorOnly))]
[SuppressMessage("Microsoft.Naming", "CA1812:AvoidUninstantiatedInternalClasses", Justification = "Used for code generation")]
public partial class SpriteFragmentShader : IFragmentShader { }
internal sealed partial class SpriteArraySet : ResourceSetHolder
{
[TextureArray("uSprite")] ITextureArrayHolder _texture;
[Sampler("uSpriteSampler")] ISamplerHolder _sampler;
[UniformBuffer("_Uniform")] IBufferHolder<SpriteUniform> _uniform;
}
[StructLayout(LayoutKind.Sequential)]
internal struct SpriteUniform : IUniformFormat // Length must be multiple of 16
{
[Uniform("uFlags", EnumPrefix = "SKF")] public SpriteKeyFlags Flags { get; set; } // 4 bytes
[Uniform("uTexSizeW")] public float TextureWidth { get; set; } // 4 bytes
[Uniform("uTexSizeH")] public float TextureHeight { get; set; } // 4 bytes
[Uniform("_pad1")] uint Padding { get; set; } // 4 bytes
}
internal partial struct SpriteIntermediateData : IVertexFormat
{
[Vertex("TexPosition")] public Vector2 TexturePosition;
[Vertex("Layer", Flat = true)] public float TextureLayer;
[Vertex("Flags", Flat = true, EnumPrefix = "SF")] public SpriteFlags Flags;
[Vertex("NormCoords")] public Vector2 NormalisedSpriteCoordinates;
[Vertex("WorldPosition")] public Vector3 WorldPosition;
}
internal partial struct ColorOnly : IVertexFormat
{
[Vertex("Color")] public Vector4 OutputColor;
}
internal partial struct GpuSpriteInstanceData : IVertexFormat
{
[Vertex("InstancePos")] public Vector4 Position;
[Vertex("Size")] public Vector2 Size;
[Vertex("TexOffset")] public Vector2 TexPosition; // Normalised texture coordinates
[Vertex("TexSize")] public Vector2 TexSize; // Normalised texture coordinates
[Vertex("TexLayer")] public uint TexLayer;
[Vertex("Flags", EnumPrefix = "SF")] public SpriteFlags Flags;
}
#pragma warning restore 649
#pragma warning restore CA1051 // Do not declare visible instance fields
}