Skip to content

Instantly share code, notes, and snippets.

View nbhasin2's full-sized avatar

Nishant Bhasin nbhasin2

View GitHub Profile
@nbhasin2
nbhasin2 / metal15.metal
Created March 13, 2025 05:59
metal15.metal
#include <metal_stdlib>
using namespace metal;
struct VertexOut {
float4 position [[position]];
float2 texCoord;
};
vertex VertexOut blended_vertex(uint vertexID [[vertex_id]]) {
float2 positions[4] = {
@nbhasin2
nbhasin2 / metal14.swift
Last active March 13, 2025 06:06
metal14.swift
class BlendedCirclesRenderer: NSObject, MTKViewDelegate {
var device: MTLDevice!
var commandQueue: MTLCommandQueue!
var pipelineState: MTLRenderPipelineState!
var time: Float = 0.0
init(device: MTLDevice = MTLCreateSystemDefaultDevice()!) {
self.device = device
self.commandQueue = device.makeCommandQueue()
@nbhasin2
nbhasin2 / metal13.metal
Created March 13, 2025 05:41
metal13.metal
#include <metal_stdlib>
using namespace metal;
struct VertexOut {
float4 position [[position]];
float2 texCoord;
};
vertex VertexOut multi_vertex(uint vertexID [[vertex_id]]) {
float2 positions[4] = {
@nbhasin2
nbhasin2 / metal12.swift
Created March 13, 2025 05:40
metal12.swift
class MultiCircleRenderer: NSObject, MTKViewDelegate {
var device: MTLDevice!
var commandQueue: MTLCommandQueue!
var pipelineState: MTLRenderPipelineState!
var time: Float = 0.0
init(device: MTLDevice = MTLCreateSystemDefaultDevice()!) {
self.device = device
self.commandQueue = device.makeCommandQueue()
@nbhasin2
nbhasin2 / metal11.metal
Created March 13, 2025 05:37
metal11.metal
#include <metal_stdlib>
using namespace metal;
struct VertexOut {
float4 position [[position]];
float2 texCoord;
};
vertex VertexOut animated_vertex(uint vertexID [[vertex_id]]) {
float2 positions[4] = {
@nbhasin2
nbhasin2 / metal10.swift
Created March 13, 2025 05:36
metal10.swift
struct AnimatedCircleMetalView: UIViewRepresentable {
func makeUIView(context: Context) -> MTKView {
let metalView = MTKView()
metalView.device = MTLCreateSystemDefaultDevice()
metalView.framebufferOnly = false
metalView.colorPixelFormat = .bgra8Unorm
metalView.delegate = context.coordinator
return metalView
}
@nbhasin2
nbhasin2 / metal9.swift
Created March 13, 2025 05:35
metal9.swift
class AnimatedCircleRenderer: NSObject, MTKViewDelegate {
var device: MTLDevice!
var commandQueue: MTLCommandQueue!
var pipelineState: MTLRenderPipelineState!
var time: Float = 0.0 // New time variable for animation
init(device: MTLDevice = MTLCreateSystemDefaultDevice()!) {
self.device = device
self.commandQueue = device.makeCommandQueue()
@nbhasin2
nbhasin2 / metal8.metal
Created March 13, 2025 05:33
metal8.metal
#include <metal_stdlib>
using namespace metal;
struct VertexOut {
float4 position [[position]];
float2 texCoord;
};
vertex VertexOut smooth_vertex(uint vertexID [[vertex_id]]) {
float2 positions[4] = {
@nbhasin2
nbhasin2 / metal7.swift
Created March 13, 2025 05:32
metal7.swift
class SmoothCircleRenderer: NSObject, MTKViewDelegate {
var device: MTLDevice!
var commandQueue: MTLCommandQueue!
var pipelineState: MTLRenderPipelineState!
init(device: MTLDevice = MTLCreateSystemDefaultDevice()!) {
self.device = device
self.commandQueue = device.makeCommandQueue()
let library = device.makeDefaultLibrary()
@nbhasin2
nbhasin2 / metal6.metal
Created March 13, 2025 05:27
metal6.metal
#include <metal_stdlib>
using namespace metal;
struct VertexOut {
float4 position [[position]];
float2 texCoord;
};
vertex VertexOut circle_vertex(uint vertexID [[vertex_id]]) {
// Define vertices for a full-screen quad