Skip to content

Instantly share code, notes, and snippets.

View TheoBendixson's full-sized avatar
🎮
Experimenting with new game ideas

Theodore Bendixson TheoBendixson

🎮
Experimenting with new game ideas
View GitHub Profile
@TheoBendixson
TheoBendixson / 2DPixelArtFragmentShader.metal
Last active June 14, 2021 23:19
2D Scaling Pixel Art Fragment Shader (Metal)
fragment float4
pixelArtFragmentShader(RasterizerData in [[stage_in]],
texture2d_array<half> texture_atlas [[ texture(0) ]])
{
constexpr sampler textureSampler (mag_filter::linear,
min_filter::linear);
// This is the alpha value from the graph, or the size of the margin where you
// want to apply bilinear filtering around a texel
float2 alpha = float2(0.07);
@TheoBendixson
TheoBendixson / 2dpixelartshader.metal
Last active June 14, 2021 22:59
2D Scaling Pixel Art Vertex Shader (Metal)
typedef enum MacVertexInputIndex
{
MacVertexInputIndexVertices = 0,
MacVertexInputIndexViewportSize = 1,
MacVertexInputIndexTextureSize = 2
} MacVertexInputIndex;
vertex RasterizerData
vertexShader(uint vertexID [[ vertex_id ]],
constant MacTextureShaderVertex *vertexArray [[ buffer(MacVertexInputIndexVertices) ]],
@TheoBendixson
TheoBendixson / 2dpixelgamemacplatform.mm
Last active June 14, 2021 22:34
2D Scaling Pixel Art Shader (Metal) - Passing Texture Size Into The Vertex Shader
// A simple struct representing the size of the texture in terms of
// texels.
typedef struct
{
real32 Width;
real32 Height;
} MacTextureSize;
// PRETEND THIS IS INSIDE OF A RENDERING FUNCTION
@TheoBendixson
TheoBendixson / pixelartshaderrasterizerdata.metal
Last active June 14, 2021 22:02
2D Pixel Art Rasterizer Data Struct (Metal Shading Language)
typedef struct
{
// Rasterizer position output data, in terms of Apple's normalized device
// coordinates. The vertex shader maps on screen pixel coordinates to normalized
// device coordinates and stores the output in this value.
float4 position [[position]];
// The fragment texture coordinate, expressed in standard UV notation where 0.0f
// is the beginning and 1.0f is the end of a textured quad.
float2 textureCoordinate;
class RGBColor {
var red: float
var green: float
var blue: float
}
class FakeTextField{
var text:String?
}