initial sprite batch implementation & testbed

This commit is contained in:
2024-09-13 18:59:14 +10:00
parent c0de651947
commit 79013c24c4
13 changed files with 732 additions and 29 deletions

View File

@ -0,0 +1,28 @@
#include "shadertypes.h"
#include <metal_stdlib>
struct FragmentInput {
float4 position [[position]];
float2 texCoord;
half4 color;
};
vertex FragmentInput vertex2DMain(uint vertexID [[vertex_id]],
device const Vertex2D* vtx [[buffer(VertexShaderInputIdxVertices)]],
constant Shader2DUniforms& u [[buffer(VertexShaderInputIdxUniforms)]]
) {
FragmentInput out;
out.position = u.projection * float4(vtx[vertexID].position, 0.0, 1.0);
out.texCoord = vtx[vertexID].texCoord;
out.color = half4(vtx[vertexID].color);
return out;
}
fragment half4 fragment2DMain(FragmentInput in [[stage_in]],
metal::texture2d<half, metal::access::sample> texture [[texture(0)]]
) {
constexpr metal::sampler sampler(metal::address::repeat, metal::filter::linear);
half4 texel = texture.sample(sampler, in.texCoord);
return texel * in.color;
}